Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ from build.option_handler import OptionsClass
from build.glob_recursive import GlobRecursive
from build.git_info import get_git_info, git_builder
from build.license_info import license_builder
from build.author_info import author_builder
from build.cache import show_progress

def normalize_path(val, env):
Expand Down Expand Up @@ -277,6 +278,8 @@ env.GlobRecursive = GlobRecursive
env.get_git_info = get_git_info
env.license_builder = license_builder
env.git_builder = git_builder
env.author_builder = author_builder


def to_raw_cstring(value: Union[str, List[str]]) -> str:
MAX_LITERAL = 35 * 1024
Expand Down
48 changes: 48 additions & 0 deletions build/author_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
def author_builder(target, source, env):
name_prefix = env.get("name_prefix", "project")
prefix_upper = name_prefix.upper()
sections = env.get("sections", {"Developers": "AUTHORS_DEVELOPERS"})

def get_buffer() -> bytes:
with open(str(source[0]), "rb") as file:
return file.read()

buffer = get_buffer()

reading = False

with open(str(target[0]), "wt", encoding="utf-8", newline="\n") as file:
file.write("/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
file.write(
"""\
#pragma once

#include <array>
#include <string_view>

namespace OpenVic {
"""
)

def close_section():
file.write("\t});\n")

for line in buffer.decode().splitlines():
if line.startswith(" ") and reading:
file.write(f'\t\t"{env.to_escaped_cstring(line).strip()}",\n')
elif line.startswith("## "):
if reading:
close_section()
file.write("\n")
reading = False
section = sections.get(line[3:].strip(), None)
if section:
file.write(
f"\tstatic constexpr std::array {prefix_upper}_{section} = std::to_array<std::string_view>({{\n"
)
reading = True

if reading:
close_section()

file.write("}")