mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-18 00:18:43 +01:00
Build: Make genrev more resilient to invalid source code checkouts
This commit is contained in:
@@ -24,13 +24,6 @@ if(WITHOUT_GIT)
|
||||
string(TIMESTAMP rev_date_fallback "%Y-%m-%d %H:%M:%S" UTC)
|
||||
else()
|
||||
if(GIT_EXECUTABLE)
|
||||
# Retrieve repository dirty status
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
RESULT_VARIABLE is_dirty
|
||||
)
|
||||
|
||||
# Create a revision-string that we can use
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" rev-parse --short=12 HEAD
|
||||
@@ -40,58 +33,68 @@ else()
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
# Append dirty marker to commit hash
|
||||
if(is_dirty)
|
||||
set(rev_hash "${rev_hash}+")
|
||||
endif()
|
||||
|
||||
# And grab the commits timestamp
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" show -s --format=%ci
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE rev_date
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
# Also retrieve branch name
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" symbolic-ref -q --short HEAD
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE rev_branch
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
# when ran on CI, repository is put in detached HEAD state, attempt to scan for known local branches
|
||||
if(NOT rev_branch)
|
||||
if(rev_hash)
|
||||
# Retrieve repository dirty status
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" for-each-ref --points-at=HEAD refs/heads "--format=%(refname:short)"
|
||||
COMMAND "${GIT_EXECUTABLE}" diff-index --quiet HEAD --
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
RESULT_VARIABLE is_dirty
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
# Append dirty marker to commit hash
|
||||
if(is_dirty)
|
||||
set(rev_hash "${rev_hash}+")
|
||||
endif()
|
||||
|
||||
# And grab the commits timestamp
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" show -s --format=%ci
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE rev_date
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
|
||||
# Also retrieve branch name
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" symbolic-ref -q --short HEAD
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE rev_branch
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
endif()
|
||||
|
||||
# if local branch scan didn't find anything, try remote branches
|
||||
if(NOT rev_branch)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" for-each-ref --points-at=HEAD refs/remotes "--format=%(refname:short)"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE rev_branch
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
endif()
|
||||
# when ran on CI, repository is put in detached HEAD state, attempt to scan for known local branches
|
||||
if(NOT rev_branch)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" for-each-ref --points-at=HEAD refs/heads "--format=%(refname:short)"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE rev_branch
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
endif()
|
||||
|
||||
# give up finding a name for branch, use commit hash
|
||||
if(NOT rev_branch)
|
||||
set(rev_branch ${rev_hash})
|
||||
endif()
|
||||
# if local branch scan didn't find anything, try remote branches
|
||||
if(NOT rev_branch)
|
||||
execute_process(
|
||||
COMMAND "${GIT_EXECUTABLE}" for-each-ref --points-at=HEAD refs/remotes "--format=%(refname:short)"
|
||||
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
|
||||
OUTPUT_VARIABLE rev_branch
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||
ERROR_QUIET
|
||||
)
|
||||
endif()
|
||||
|
||||
# normalize branch to single line (for-each-ref can output multiple lines if there are multiple branches on the same commit)
|
||||
string(REGEX MATCH "^[^ \t\r\n]+" rev_branch ${rev_branch})
|
||||
# give up finding a name for branch, use commit hash
|
||||
if(NOT rev_branch)
|
||||
set(rev_branch ${rev_hash})
|
||||
endif()
|
||||
|
||||
# normalize branch to single line (for-each-ref can output multiple lines if there are multiple branches on the same commit)
|
||||
string(REGEX MATCH "^[^ \t\r\n]+" rev_branch ${rev_branch})
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Last minute check - ensure that we have a proper revision
|
||||
|
||||
Reference in New Issue
Block a user