From a56c8d6017c81faaff25f20c836400d62b9be340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Halkenh=C3=A4user?= <15107583+mhalk@users.noreply.github.com> Date: Wed, 27 May 2026 17:18:40 +0000 Subject: [PATCH] [rocm-libraries] ROCm/rocm-libraries#6900 (commit 28608c2) [CK] Fix and expand CK's commit records in version.h ## Motivation In `version.h` of a CK installation `CK_COMMIT_ID` would be empty for out-of-source builds. Additionally, if it worked, it would show the parent repo's (`rocm-libraries`) commit. ## Technical Details Dropped "required" constraint so "unknown" string becomes a graceful option. Changed process of determining the CK commit, now uses `WORKING_DIRECTORY`. Thus, `CK_COMMIT_ID` holds only the last CK-relevant commit. Added `CK_PARENT_COMMIT_ID` which holds the parent's, e.g. `rocm-libraries`, commit. This can be the same as `CK_COMMIT_ID`, or not even applicable, depending on the scenario. ## Test Plan Ran CMake configuration and installation of CK to verify happy path. ## Test Result Commit SHA's showed the expected values depending on the repo state. ## Submission Checklist - [ x ] Look over the contributing guidelines at https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests. --- CMakeLists.txt | 44 +++++++++++++++++++++++++++++++++++++++-- include/ck/version.h.in | 1 + 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a4019188e..e5ea239aa2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -172,8 +172,48 @@ endif() include(getopt) # CK version file to record release version as well as git commit hash -find_package(Git REQUIRED) -execute_process(COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD OUTPUT_VARIABLE COMMIT_ID OUTPUT_STRIP_TRAILING_WHITESPACE) +# identifying the CK source tree. +# +# NOTE: execute_process() runs in the build directory by default, so we must +# pin WORKING_DIRECTORY to the source tree -- otherwise out-of-source builds +# (where the build dir is not inside a git checkout) would silently produce +# an empty CK_COMMIT_ID. We use `git log -1 -- .` (the last commit touching +# CK's sources) rather than `git rev-parse HEAD` so unrelated changes +# elsewhere in a containing monorepo (e.g. rocm-libraries) do not bump the +# CK identity. RESULT_VARIABLE/ERROR_QUIET also let us degrade gracefully +# when building from a release tarball without a .git directory. +find_package(Git) +set(COMMIT_ID "unknown") +set(CK_PARENT_COMMIT_ID "unknown") +if(GIT_FOUND) + execute_process( + COMMAND "${GIT_EXECUTABLE}" log -1 --format=%H -- . + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_COMMIT_ID + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE GIT_LOG_RESULT + ERROR_QUIET + ) + if(GIT_LOG_RESULT EQUAL 0 AND GIT_COMMIT_ID) + set(COMMIT_ID "${GIT_COMMIT_ID}") + endif() + + # Containing-repo HEAD. Captures the surrounding repository's exact + # snapshot, including shared infrastructure that lives outside CK + # (e.g. rocm-libraries top-level CMake/codegen helpers). When CK is + # built standalone, this is just CK's own HEAD. + execute_process( + COMMAND "${GIT_EXECUTABLE}" rev-parse HEAD + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_REPO_HEAD + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE GIT_REV_PARSE_RESULT + ERROR_QUIET + ) + if(GIT_REV_PARSE_RESULT EQUAL 0 AND GIT_REPO_HEAD) + set(CK_PARENT_COMMIT_ID "${GIT_REPO_HEAD}") + endif() +endif() configure_file(include/ck/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/ck/version.h) set(ROCM_SYMLINK_LIBS OFF) diff --git a/include/ck/version.h.in b/include/ck/version.h.in index 0d6a6512fb..5e3fb4305c 100644 --- a/include/ck/version.h.in +++ b/include/ck/version.h.in @@ -35,6 +35,7 @@ #define CK_VERSION_MINOR @CMAKE_PROJECT_VERSION_MINOR@ #define CK_VERSION_PATCH @CMAKE_PROJECT_VERSION_PATCH@ #define CK_COMMIT_ID @COMMIT_ID@ +#define CK_PARENT_COMMIT_ID @CK_PARENT_COMMIT_ID@ // clang-format on #endif