Skip to content

Commit

Permalink
build: add git dirty var
Browse files Browse the repository at this point in the history
  • Loading branch information
Zxilly committed Sep 20, 2024
1 parent 202759c commit e1d6231
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,26 @@ if (GIT_FOUND)
if ((NOT GIT_COMMIT_RESULT EQUAL 0) OR (GIT_COMMIT STREQUAL ""))
set(GIT_COMMIT "unknown")
endif ()

execute_process(
COMMAND ${GIT_EXECUTABLE} status --porcelain
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DIRTY_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE GIT_DIRTY_RESULT
)
if ((NOT GIT_DIRTY_RESULT EQUAL 0))
set(GIT_DIRTY "unknown")
elseif (GIT_DIRTY_OUTPUT STREQUAL "")
set(GIT_DIRTY "clean")
else ()
set(GIT_DIRTY "dirty")
endif ()
else ()
set(GIT_COMMIT "unknown")
set(GIT_BRANCH "unknown")
set(GIT_TAG "unknown")
set(GIT_DIRTY "unknown")
endif ()

if (UA2F_VERSION_STR)
Expand All @@ -56,6 +72,7 @@ endif ()
add_compile_definitions(UA2F_GIT_COMMIT="${GIT_COMMIT}")
add_compile_definitions(UA2F_GIT_BRANCH="${GIT_BRANCH}")
add_compile_definitions(UA2F_GIT_TAG="${GIT_TAG}")
add_compile_definitions(UA2F_GIT_DIRTY="${GIT_DIRTY}")
add_compile_definitions(UA2F_VERSION="${UA2F_VERSION_STR}")

if (DEFINED ENV{UA2F_ENABLE_ASAN})
Expand Down
1 change: 1 addition & 0 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ void try_print_info(const int argc, char *argv[]) {
printf("Git commit: %s\n", UA2F_GIT_COMMIT);
printf("Git branch: %s\n", UA2F_GIT_BRANCH);
printf("Git tag: %s\n", UA2F_GIT_TAG);
printf("Git dirty: %s\n", UA2F_GIT_DIRTY);
#ifdef UA2F_CUSTOM_UA
printf("Embed UA: %s\n", UA2F_CUSTOM_UA);
#else
Expand Down

0 comments on commit e1d6231

Please sign in to comment.