Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
    npro  
 Modern all-safe Rust Network Protocol library supporting h1, h2, h3, ws, wt sans-IO and with socket IO + tls
git clone https://npro.rs/repo/npro
 
root / assets / freertos-espidf.svg
Author[]Andy Green <andy@warmcat.com> 2026-09-12 15:10 UTC
Committer[]Andy Green <andy@warmcat.com> 2026-09-12 15:10 UTC
Treec419b0c2398cf45f149d7e94e100ccba3c79e30b   Raw Patch
 
get-git-hash
get-git-hash
diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fc0a84..1e2a70d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,7 +134,7 @@ endif() include_directories(${CMAKE_BINARY_DIR}) add_custom_target(sai_git_hash ALL COMMAND ${CMAKE_COMMAND} - -DCMAKE_SOURCE_DIR=${CMAKE_SOURCE_DIR} + -DSAI_SOURCE_DIR=${CMAKE_SOURCE_DIR} -DCPACK_PACKAGE_VERSION=${CPACK_PACKAGE_VERSION} -DOUTPUT_FILE=${CMAKE_BINARY_DIR}/sai-git-hash.h -P ${CMAKE_SOURCE_DIR}/cmake/GetGitHash.cmake diff --git a/cmake/GetGitHash.cmake b/cmake/GetGitHash.cmake index 7882120..c15cc5b 100644 --- a/cmake/GetGitHash.cmake +++ b/cmake/GetGitHash.cmake @@ -1,19 +1,29 @@ +# Run in cmake script mode (-P) by the sai_git_hash target. +# +# Note: in script mode CMAKE_SOURCE_DIR is forced to the current working +# directory, so the caller must pass the checkout under SAI_SOURCE_DIR. + +set(GIT_HASH "unknown") + +if(NOT SAI_SOURCE_DIR) + set(SAI_SOURCE_DIR "${CMAKE_SOURCE_DIR}") +endif() + find_package(Git) if(GIT_EXECUTABLE) execute_process( COMMAND "${GIT_EXECUTABLE}" describe --tags --always - WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + WORKING_DIRECTORY "${SAI_SOURCE_DIR}" RESULT_VARIABLE GIT_RESULT - OUTPUT_VARIABLE GIT_HASH + OUTPUT_VARIABLE GIT_OUT OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET ) - if(NOT GIT_RESULT EQUAL 0) - # Git failed (e.g. running as root in a user directory) - return() + # Git can fail (e.g. running as root in a user directory, or not a + # checkout); fall through with "unknown" so the header always exists. + if(GIT_RESULT EQUAL 0 AND NOT "${GIT_OUT}" STREQUAL "") + set(GIT_HASH "${GIT_OUT}") endif() -else() - set(GIT_HASH "unknown") endif() set(NEW_HASH_FILE_CONTENT "#define SAI_BUILD_INFO \"${CPACK_PACKAGE_VERSION}-${GIT_HASH}\"\n")
Page fetched 0s ago, creation time: 1ms (vhost etag hits: 0%, cache hits: 0%)