Skip to content

Commit 91c33aa

Browse files
authored
Merge pull request #424 from OpenVicProject/add/git-info
Add commit info to GameManager
2 parents 76fdbc4 + 24913b0 commit 91c33aa

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,6 @@ src/openvic-simulation/testing/test_results/results.txt
8787

8888
# ccls
8989
.ccls-cache
90+
91+
# Generated source files
92+
src/openvic-simulation/gen/*

SConstruct

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,27 @@ SConscript("deps/SCsub", "env")
2929

3030
env.openvic_simulation = {}
3131

32+
def version_git_info_builder(target, source, env):
33+
with open(str(target[0]), "wt", encoding="utf-8", newline="\n") as file:
34+
file.write("/* THIS FILE IS GENERATED. EDITS WILL BE LOST. */\n\n")
35+
file.write(
36+
"""\
37+
#pragma once
38+
39+
#include <cstdint>
40+
#include <string_view>
41+
42+
namespace OpenVic {{
43+
static constexpr std::string_view SIM_COMMIT_HASH = "{git_hash}";
44+
static constexpr const uint64_t SIM_COMMIT_TIMESTAMP = {git_timestamp}ull;
45+
}}
46+
""".format(**source[0].read())
47+
)
48+
49+
result = env.Command("src/openvic-simulation/gen/commit_info.gen.hpp", env.Value(env.get_git_info()), env.Action(version_git_info_builder, "$GENCOMSTR"))
50+
env.NoCache(result)
51+
Default(result)
52+
3253
# For future reference:
3354
# - CCFLAGS are compilation flags shared between C and C++
3455
# - CFLAGS are for C-specific compilation flags

src/headless/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ static bool run_headless(Dataloader::path_vector_t const& roots, bool run_tests)
116116
Logger::info("State updated");
117117
} };
118118

119+
Logger::info("Commit hash: ", GameManager::get_commit_hash());
120+
119121
Logger::info("===== Loading definitions... =====");
120122
ret &= game_manager.set_roots(roots);
121123
ret &= game_manager.load_definitions(

src/openvic-simulation/GameManager.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "openvic-simulation/InstanceManager.hpp"
77
#include "openvic-simulation/dataloader/Dataloader.hpp"
88
#include "openvic-simulation/misc/GameRulesManager.hpp"
9+
#include "openvic-simulation/gen/commit_info.gen.hpp"
910

1011
namespace OpenVic {
1112
struct GameManager {
@@ -40,5 +41,13 @@ namespace OpenVic {
4041
bool start_game_session();
4142

4243
bool update_clock();
44+
45+
static constexpr std::string_view get_commit_hash() {
46+
return SIM_COMMIT_HASH;
47+
}
48+
49+
static constexpr uint64_t get_commit_timestamp() {
50+
return SIM_COMMIT_TIMESTAMP;
51+
}
4352
};
4453
}

0 commit comments

Comments
 (0)