Fix git version fetching logic. (#1981)

Esse commit está contido em:
Arm Patinyasakdikul
2025-10-17 07:17:49 -07:00
commit de GitHub
commit 9806f5e9dd
2 arquivos alterados com 26 adições e 12 exclusões
+10 -6
Ver Arquivo
@@ -889,16 +889,19 @@ endforeach()
# Create an initial git_version.cpp file (that will be updated with latest git version)
#==================================================================================================
# Create initial empty file at configure time
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp "")
list(APPEND HIP_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp)
# Create a custom target that updates git_version.cpp and executes whenever rccl is built
add_custom_target(git_version_check
COMMENT "Updating git_version.cpp if necessary"
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/git_version.cmake
# Add a custom target that always runs at build time to update git version
add_custom_target(update_git_version
ALL
COMMAND ${CMAKE_COMMAND} -DRCCL_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR} -DRCCL_BINARY_DIR=${CMAKE_CURRENT_BINARY_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/scripts/git_version.cmake
BYPRODUCTS ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp
COMMENT "Updating git version information"
VERBATIM
)
list(APPEND HIP_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp)
# Set up RCCL library
#==================================================================================================
@@ -906,7 +909,8 @@ add_custom_target(git_version_check
add_library(rccl ${HIP_SOURCES})
## Set RCCL dependencies
add_dependencies(rccl git_version_check) # Execute git_version_check during build
## Ensure git version is updated before building rccl
add_dependencies(rccl update_git_version)
if (BUILD_TESTS AND ROCM_VERSION VERSION_GREATER_EQUAL "60400" AND CMAKE_BUILD_TYPE MATCHES "Debug")
## Set static replacement dependency for fixture unit tests
+16 -6
Ver Arquivo
@@ -19,8 +19,16 @@
# SOFTWARE.
# Attempt to collect the latest git hash
set(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
# Use RCCL_SOURCE_DIR if passed, otherwise fallback to CMAKE_CURRENT_SOURCE_DIR
if(NOT DEFINED RCCL_SOURCE_DIR)
set(RCCL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
endif()
if(NOT DEFINED RCCL_BINARY_DIR)
set(RCCL_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
execute_process(COMMAND git log --pretty=format:'%h' -n 1
WORKING_DIRECTORY ${RCCL_SOURCE_DIR}
OUTPUT_VARIABLE GIT_REV
ERROR_QUIET)
@@ -31,10 +39,12 @@ else()
# Check for changes (denote with a '+') after hash
execute_process(
COMMAND bash -c "git diff --quiet --exit-code || echo +"
WORKING_DIRECTORY ${RCCL_SOURCE_DIR}
OUTPUT_VARIABLE GIT_DIFF)
# Collect branch information
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
WORKING_DIRECTORY ${RCCL_SOURCE_DIR}
OUTPUT_VARIABLE GIT_BRANCH)
string(STRIP "${GIT_REV}" GIT_REV)
@@ -46,18 +56,18 @@ else()
endif()
# Compare file with older git version file (git_version.cpp)
if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp)
#MESSAGE(STATUS "Found ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp")
file(READ ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp PREV_GIT_VERSION)
if (EXISTS ${RCCL_BINARY_DIR}/git_version.cpp)
#MESSAGE(STATUS "Found ${RCCL_BINARY_DIR}/git_version.cpp")
file(READ ${RCCL_BINARY_DIR}/git_version.cpp PREV_GIT_VERSION)
#message(STATUS "CURR GIT version: ${CURR_GIT_VERSION}")
#message(STATUS "PREV GIT version: ${PREV_GIT_VERSION}")
if (NOT "${CURR_GIT_VERSION}" STREQUAL "${PREV_GIT_VERSION}")
message(STATUS "Updating git_version.cpp")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp "${CURR_GIT_VERSION}")
file(WRITE ${RCCL_BINARY_DIR}/git_version.cpp "${CURR_GIT_VERSION}")
else()
message(STATUS "No changes to git_version.cpp required")
endif()
else()
# Create git_version.cpp if it doesn't exist yet
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/git_version.cpp "${CURR_GIT_VERSION}")
file(WRITE ${RCCL_BINARY_DIR}/git_version.cpp "${CURR_GIT_VERSION}")
endif()