mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-22 06:34:36 +00:00
Generate git revision to a header file.
This commit is contained in:
parent
959f0de7e5
commit
5934f5da9a
24
extra/git-ref.py
Normal file
24
extra/git-ref.py
Normal 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)
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user