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: 2 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
28 changes: 25 additions & 3 deletions build/git_info.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import os
import subprocess
from pathlib import Path

base_folder = Path(__file__).resolve().parent


def get_git_tag():
Expand Down Expand Up @@ -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 <cstdint>
#include <string_view>

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;
}}
"""
)