Skip to content

Commit ae419e3

Browse files
committed
Add git_builder SCons builder function
1 parent 049e7ea commit ae419e3

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

SConstruct

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import SCons
1111
# Local
1212
from build.option_handler import OptionsClass
1313
from build.glob_recursive import GlobRecursive
14-
from build.git_info import get_git_info
14+
from build.git_info import get_git_info, git_builder
1515
from build.license_info import license_builder
1616
from build.cache import show_progress
1717

@@ -276,6 +276,7 @@ env.FinalizeOptions = FinalizeOptions
276276
env.GlobRecursive = GlobRecursive
277277
env.get_git_info = get_git_info
278278
env.license_builder = license_builder
279+
env.git_builder = git_builder
279280

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

build/git_info.py

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import os
22
import subprocess
3-
from pathlib import Path
4-
5-
base_folder = Path(__file__).resolve().parent
63

74

85
def get_git_tag():
@@ -94,3 +91,28 @@ def get_git_hash():
9491

9592
def get_git_info():
9693
return {**get_git_hash(), "git_tag": get_git_tag(), "git_release": get_git_release()}
94+
95+
96+
def git_builder(target, source, env):
97+
name_prefix = env.get("name_prefix", "project")
98+
prefix_upper = name_prefix.upper()
99+
100+
git_info = source[0].read()
101+
102+
with open(str(target[0]), "wt", encoding="utf-8", newline="\n") as file:
103+
file.write("/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
104+
file.write(
105+
f"""\
106+
#pragma once
107+
108+
#include <cstdint>
109+
#include <string_view>
110+
111+
namespace OpenVic {{
112+
static constexpr std::string_view {prefix_upper}_TAG = "{git_info["git_tag"]}";
113+
static constexpr std::string_view {prefix_upper}_RELEASE = "{git_info["git_release"]}";
114+
static constexpr std::string_view {prefix_upper}_COMMIT_HASH = "{git_info["git_hash"]}";
115+
static constexpr const uint64_t {prefix_upper}_COMMIT_TIMESTAMP = {git_info["git_timestamp"]}ull;
116+
}}
117+
"""
118+
)

0 commit comments

Comments
 (0)