File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import SCons
1111# Local
1212from build .option_handler import OptionsClass
1313from 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
1515from build .license_info import license_builder
1616from build .cache import show_progress
1717
@@ -276,6 +276,7 @@ env.FinalizeOptions = FinalizeOptions
276276env .GlobRecursive = GlobRecursive
277277env .get_git_info = get_git_info
278278env .license_builder = license_builder
279+ env .git_builder = git_builder
279280
280281def to_raw_cstring (value : Union [str , List [str ]]) -> str :
281282 MAX_LITERAL = 35 * 1024
Original file line number Diff line number Diff line change 11import os
22import subprocess
3- from pathlib import Path
4-
5- base_folder = Path (__file__ ).resolve ().parent
63
74
85def get_git_tag ():
@@ -94,3 +91,28 @@ def get_git_hash():
9491
9592def 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+ )
You can’t perform that action at this time.
0 commit comments