Skip to content

Commit

Permalink
Print Git Hash on --version
Browse files Browse the repository at this point in the history
  • Loading branch information
rexim authored and lerno committed Aug 27, 2024
1 parent 26acce2 commit 484a9ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,19 @@ if(C3_USE_TB AND GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
endif()
endif()

if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
# Get git hash
execute_process(COMMAND git rev-parse HEAD
OUTPUT_VARIABLE GIT_HASH
RESULT_VARIABLE GIT_REVPARSE_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(GIT_REVPARSE_RESULT EQUAL "0")
add_compile_definitions(GIT_HASH="${GIT_HASH}")
else()
message(WARNING "Cannot to get Git Hash: git rev-parse failed with ${GIT_REVPARSE_RESULT}")
endif()
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "MSVC")
if (C3_LLVM_VERSION STREQUAL "auto")
set(C3_LLVM_VERSION "18")
Expand Down
3 changes: 3 additions & 0 deletions src/build/build_options.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,9 @@ static void print_version(void)
PRINTF("C3 Compiler Version: %s", COMPILER_VERSION);
#endif
PRINTF("Installed directory: %s", find_executable_path());
#ifdef GIT_HASH
PRINTF("Git Hash: %s", GIT_HASH);
#endif
PRINTF("LLVM version: %s", llvm_version);
PRINTF("LLVM default target: %s", llvm_target);
}
Expand Down

0 comments on commit 484a9ac

Please sign in to comment.