Skip to content

Commit

Permalink
detect non-release commits and modify the string
Browse files Browse the repository at this point in the history
  • Loading branch information
guicho271828 committed Jan 14, 2025
1 parent 0613123 commit 84b723a
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions src/search/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,55 @@ set_up_options()
project(downward LANGUAGES CXX)
add_executable(downward planner.cc)

# write git SHA1 hash into a header file
# obtain git SHA1 hash
execute_process(
COMMAND git log -1 "--format=format:%h%n" HEAD
OUTPUT_VARIABLE GIT_REVISION
RESULT_VARIABLE GIT_REVISION_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(GIT_REVISION_CODE EQUAL 0)

# obtain the nearest release tag in the commit log
execute_process(
COMMAND git describe --tags --abbrev=0 HEAD
OUTPUT_VARIABLE GIT_RELEASE
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# detect if the current commit is the release commit
execute_process(
COMMAND git tag --points-at HEAD
OUTPUT_VARIABLE GIT_HEAD_TAG # empty if the HEAD does not have any tag
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# detect uncommitted changes
execute_process(
COMMAND git diff-index --quiet HEAD
RESULT_VARIABLE GIT_DIFF_CODE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(NOT GIT_DIFF_CODE EQUAL 0)
message(WARNING "Building from a repository with uncommited changes.")
set(GIT_REVISION "${GIT_REVISION}-dirty")

if ("${GIT_HEAD_TAG}" STREQUAL "${GIT_RELEASE}")
message(NOTICE "Building from a release commit.")
if(NOT GIT_DIFF_CODE EQUAL 0)
message(WARNING "Building from a repository with uncommited changes.")
set(GIT_REVISION "${GIT_RELEASE}-dirty")
else()
set(GIT_REVISION "${GIT_RELEASE}")
endif()
else()
message(NOTICE "Building from a non-release commit.")
if(NOT GIT_DIFF_CODE EQUAL 0)
message(WARNING "Building from a repository with uncommited changes.")
set(GIT_REVISION "${GIT_REVISION}-dirty (based on ${GIT_RELEASE})")
else()
set(GIT_REVISION "${GIT_REVISION} (based on ${GIT_RELEASE})")
endif()
endif()
message(NOTICE "revision string: \"${GIT_REVISION}\"")

else()
message(WARNING "Building from tarball. Using the release version as the build version string.")
execute_process(
Expand Down

0 comments on commit 84b723a

Please sign in to comment.