Generate git revision to a header file.

This commit is contained in:
Bartosz Taudul 2024-09-08 14:17:11 +02:00
parent 959f0de7e5
commit 5934f5da9a
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 30 additions and 0 deletions

24
extra/git-ref.py Normal file
View File

@ -0,0 +1,24 @@
#!/bin/env python3
import filecmp
import subprocess
import os
out = "GitRef.hpp"
tmp = f"{out}.tmp"
try:
ref = subprocess.run(["git", "rev-parse", "--short", "HEAD"], check=True, capture_output=True).stdout.decode().strip()
except subprocess.CalledProcessError:
ref = "unknown"
if not os.path.exists(out):
with open(out, "w") as f:
print(f"#pragma once\n\nnamespace tracy {{ static inline const char* GitRef = \"{ref}\"; }}", file=f)
else:
with open(tmp, "w") as f:
print(f"#pragma once\n\nnamespace tracy {{ static inline const char* GitRef = \"{ref}\"; }}", file=f)
if not filecmp.cmp(out, tmp, shallow=False):
os.replace(tmp, out)
else:
os.unlink(tmp)

View File

@ -174,6 +174,12 @@ endif()
target_link_libraries(${PROJECT_NAME} PRIVATE TracyServer TracyImGui)
add_custom_target(git-ref
COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/../extra/git-ref.py
BYPRODUCTS GitRef.hpp
)
add_dependencies(${PROJECT_NAME} git-ref)
if(NOT EMSCRIPTEN)
target_link_libraries(${PROJECT_NAME} PRIVATE TracyNfd)
if (NOT USE_WAYLAND)