Skip to content

Commit

Permalink
cmake: handle scenario where a commit has multiple tags
Browse files Browse the repository at this point in the history
  • Loading branch information
xTVaser committed Jan 7, 2024
1 parent 71cee0a commit 93024e1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cmake/Pcsx2Utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,22 @@ function(get_git_version_info)
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)

EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} tag --points-at HEAD
OUTPUT_VARIABLE PCSX2_GIT_TAG
EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} tag --points-at HEAD --sort=version:refname
OUTPUT_VARIABLE PCSX2_GIT_TAG_LIST
RESULT_VARIABLE TAG_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET)

# CAUTION: There is a race here, this solves the problem of a commit being tagged multiple times (take the last tag)
# however, if simultaneous builds are pushing tags to the same commit you might get inconsistent results (it's a race)
#
# The easy solution is, don't do that, but just something to be aware of.
if(TAG_RESULT EQUAL 0)
string(REPLACE "\n" ";" PCSX2_GIT_TAG_LIST "${PCSX2_GIT_TAG_LIST}")
list(GET PCSX2_GIT_TAG_LIST -1 PCSX2_GIT_TAG)
message("Using tag: ${PCSX2_GIT_TAG}")
endif()

EXECUTE_PROCESS(WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
OUTPUT_VARIABLE PCSX2_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
Expand Down Expand Up @@ -109,7 +120,7 @@ function(write_svnrev_h)
)
endif()
else()
file(WRITE ${CMAKE_BINARY_DIR}/common/include/svnrev.h
file(WRITE ${CMAKE_BINARY_DIR}/common/include/svnrev.h
"#define SVN_REV ${PCSX2_WC_TIME}ll\n"
"#define GIT_TAG \"${PCSX2_GIT_TAG}\"\n"
"#define GIT_TAGGED_COMMIT 0\n"
Expand Down

0 comments on commit 93024e1

Please sign in to comment.