File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Expand file tree Collapse file tree 2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ from build.option_handler import OptionsClass
1313from build .glob_recursive import GlobRecursive
1414from build .git_info import get_git_info
1515from build .license_info import license_builder
16+ from build .author_info import author_builder
1617from build .cache import show_progress
1718
1819def normalize_path (val , env ):
@@ -276,6 +277,8 @@ env.FinalizeOptions = FinalizeOptions
276277env .GlobRecursive = GlobRecursive
277278env .get_git_info = get_git_info
278279env .license_builder = license_builder
280+ env .author_builder = author_builder
281+
279282
280283def to_raw_cstring (value : Union [str , List [str ]]) -> str :
281284 MAX_LITERAL = 35 * 1024
Original file line number Diff line number Diff line change 1+ def author_builder (target , source , env ):
2+ name_prefix = env .get ("name_prefix" , "project" )
3+ prefix_upper = name_prefix .upper ()
4+ sections = env .get ("sections" , { "Developers" : "AUTHORS_DEVELOPERS" })
5+
6+ def get_buffer () -> bytes :
7+ with open (str (source [0 ]), "rb" ) as file :
8+ return file .read ()
9+ buffer = get_buffer ()
10+
11+ reading = False
12+
13+ with open (str (target [0 ]), "wt" , encoding = "utf-8" , newline = "\n " ) as file :
14+ file .write ("/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n \n " )
15+ file .write (
16+ f"""\
17+ #pragma once
18+
19+ #include <array>
20+ #include <string_view>
21+
22+ namespace OpenVic {{
23+ """
24+ )
25+
26+ def close_section ():
27+ file .write ("\t });\n " )
28+
29+ for line in buffer .decode ().splitlines ():
30+ if line .startswith (" " ) and reading :
31+ file .write (f'\t \t "{ env .to_escaped_cstring (line ).strip ()} ",\n ' )
32+ elif line .startswith ("## " ):
33+ if reading :
34+ close_section ()
35+ file .write ("\n " )
36+ reading = False
37+ section = sections .get (line [3 :].strip (), None )
38+ if section :
39+ file .write (f"\t static constexpr std::array { prefix_upper } _{ section } = std::to_array<std::string_view>({{\n " )
40+ reading = True
41+
42+ if reading :
43+ close_section ()
44+
45+ file .write ("}" )
You can’t perform that action at this time.
0 commit comments