Skip to content

Commit 4c39ad7

Browse files
committed
Add author_builder SCons builder function
1 parent 7cc783b commit 4c39ad7

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

SConstruct

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ from build.option_handler import OptionsClass
1313
from build.glob_recursive import GlobRecursive
1414
from build.git_info import get_git_info, git_builder
1515
from build.license_info import license_builder
16+
from build.author_info import author_builder
1617
from build.cache import show_progress
1718

1819
def normalize_path(val, env):
@@ -277,6 +278,8 @@ env.GlobRecursive = GlobRecursive
277278
env.get_git_info = get_git_info
278279
env.license_builder = license_builder
279280
env.git_builder = git_builder
281+
env.author_builder = author_builder
282+
280283

281284
def to_raw_cstring(value: Union[str, List[str]]) -> str:
282285
MAX_LITERAL = 35 * 1024

build/author_info.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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"\tstatic 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("}")

0 commit comments

Comments
 (0)