diff --git a/SConstruct b/SConstruct index af6e6b4..77f3e8d 100644 --- a/SConstruct +++ b/SConstruct @@ -11,7 +11,7 @@ import SCons # Local from build.option_handler import OptionsClass from build.glob_recursive import GlobRecursive -from build.git_info import get_git_info +from build.git_info import get_git_info, git_builder from build.license_info import license_builder from build.cache import show_progress @@ -276,6 +276,7 @@ env.FinalizeOptions = FinalizeOptions env.GlobRecursive = GlobRecursive env.get_git_info = get_git_info env.license_builder = license_builder +env.git_builder = git_builder def to_raw_cstring(value: Union[str, List[str]]) -> str: MAX_LITERAL = 35 * 1024 diff --git a/build/git_info.py b/build/git_info.py index 0f16e87..eb3401f 100644 --- a/build/git_info.py +++ b/build/git_info.py @@ -1,8 +1,5 @@ import os import subprocess -from pathlib import Path - -base_folder = Path(__file__).resolve().parent def get_git_tag(): @@ -94,3 +91,28 @@ def get_git_hash(): def get_git_info(): return {**get_git_hash(), "git_tag": get_git_tag(), "git_release": get_git_release()} + + +def git_builder(target, source, env): + name_prefix = env.get("name_prefix", "project") + prefix_upper = name_prefix.upper() + + git_info = source[0].read() + + 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( + f"""\ +#pragma once + +#include +#include + +namespace OpenVic {{ + static constexpr std::string_view {prefix_upper}_TAG = "{git_info["git_tag"]}"; + static constexpr std::string_view {prefix_upper}_RELEASE = "{git_info["git_release"]}"; + static constexpr std::string_view {prefix_upper}_COMMIT_HASH = "{git_info["git_hash"]}"; + static constexpr const uint64_t {prefix_upper}_COMMIT_TIMESTAMP = {git_info["git_timestamp"]}ull; +}} +""" + )