diff --git a/extra/git-ref.py b/extra/git-ref.py deleted file mode 100644 index 5eef8654..00000000 --- a/extra/git-ref.py +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/env python3 - -import filecmp -import subprocess -import sys -import os - -out = "GitRef.hpp" -tmp = f"{out}.tmp" - -if len(sys.argv) > 1: - rev = sys.argv[1] -else: - rev = "HEAD" - -try: - ref = subprocess.run(["git", "rev-parse", "--short", rev], 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) \ No newline at end of file diff --git a/profiler/CMakeLists.txt b/profiler/CMakeLists.txt index 3975592d..dd9d682c 100644 --- a/profiler/CMakeLists.txt +++ b/profiler/CMakeLists.txt @@ -189,12 +189,25 @@ if(NOT DEFINED GIT_REV) set(GIT_REV "HEAD") endif() -find_package(Python3 COMPONENTS Interpreter REQUIRED) -add_custom_target(git-ref - COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_LIST_DIR}/../extra/git-ref.py ${GIT_REV} - BYPRODUCTS GitRef.hpp -) -add_dependencies(${PROJECT_NAME} git-ref) +find_package(Git) +if(Git_FOUND) + add_custom_target(git-ref + COMMAND ${GIT_EXECUTABLE} log -1 "--format=#pragma once %nnamespace tracy { static inline const char* GitRef = %x22%h%x22; }" ${GIT_REV} > GitRef.hpp.tmp + COMMAND ${CMAKE_COMMAND} -E copy_if_different GitRef.hpp.tmp GitRef.hpp + BYPRODUCTS GitRef.hpp GitRef.hpp.tmp + VERBATIM + ) + add_dependencies(${PROJECT_NAME} git-ref) +else() + message(WARNING "git not found, using 'unknown' as git ref.") + add_custom_command( + OUTPUT GitRef.hpp + COMMAND ${CMAKE_COMMAND} -E echo "#pragma once" > GitRef.hpp + COMMAND ${CMAKE_COMMAND} -E echo "namespace tracy { static inline const char* GitRef = \"unknown\"; }" >> GitRef.hpp + VERBATIM + ) + target_sources(${PROJECT_NAME} PUBLIC GitRef.hpp) +endif() if(NOT EMSCRIPTEN) if(NOT NO_FILESELECTOR)