File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Expand file tree Collapse file tree 2 files changed +51
-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 , git_builder
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 ):
@@ -277,6 +278,8 @@ env.GlobRecursive = GlobRecursive
277278env .get_git_info = get_git_info
278279env .license_builder = license_builder
279280env .git_builder = git_builder
281+ env .author_builder = author_builder
282+
280283
281284def to_raw_cstring (value : Union [str , List [str ]]) -> str :
282285 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+
10+ buffer = get_buffer ()
11+
12+ reading = False
13+
14+ with open (str (target [0 ]), "wt" , encoding = "utf-8" , newline = "\n " ) as file :
15+ file .write ("/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n \n " )
16+ file .write (
17+ """\
18+ #pragma once
19+
20+ #include <array>
21+ #include <string_view>
22+
23+ namespace OpenVic {
24+ """
25+ )
26+
27+ def close_section ():
28+ file .write ("\t });\n " )
29+
30+ for line in buffer .decode ().splitlines ():
31+ if line .startswith (" " ) and reading :
32+ file .write (f'\t \t "{ env .to_escaped_cstring (line ).strip ()} ",\n ' )
33+ elif line .startswith ("## " ):
34+ if reading :
35+ close_section ()
36+ file .write ("\n " )
37+ reading = False
38+ section = sections .get (line [3 :].strip (), None )
39+ if section :
40+ file .write (
41+ f"\t static constexpr std::array { prefix_upper } _{ section } = std::to_array<std::string_view>({{\n "
42+ )
43+ reading = True
44+
45+ if reading :
46+ close_section ()
47+
48+ file .write ("}" )
You can’t perform that action at this time.
0 commit comments