Skip to content

Commit 35cac17

Browse files
committed
Fix version file generation in external git repo
If the source tarball is extracted within a git repository, the version file generation code would try to re-create the version files and would very likely fail doing so. This is an issue on Arch Linux, where packages are apparently built from within a repo that hold the package build information.
1 parent eb1fd9e commit 35cac17

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

cmake/version.cmake

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,33 @@
1919
set(VERSION_SRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/dwarfs/version.cpp)
2020
set(VERSION_HDR_FILE ${CMAKE_CURRENT_SOURCE_DIR}/include/dwarfs/version.h)
2121

22+
execute_process(
23+
COMMAND git rev-parse --show-toplevel
24+
OUTPUT_VARIABLE GIT_TOPLEVEL
25+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
26+
2227
execute_process(
2328
COMMAND git log --pretty=format:%h -n 1
2429
OUTPUT_VARIABLE PRJ_GIT_REV
25-
ERROR_QUIET)
30+
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
2631

27-
if("${PRJ_GIT_REV}" STREQUAL "")
32+
if((NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${GIT_TOPLEVEL}")
33+
OR ("${PRJ_GIT_REV}" STREQUAL ""))
2834
if(NOT EXISTS ${VERSION_SRC_FILE} OR NOT EXISTS ${VERSION_HDR_FILE})
2935
message(FATAL_ERROR "missing version files")
36+
message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
37+
message("GIT_TOPLEVEL: ${GIT_TOPLEVEL}")
38+
message("PRJ_GIT_REV: ${PRJ_GIT_REV}")
3039
endif()
3140
else()
32-
execute_process(COMMAND git describe --tags --match "v*" --dirty
33-
OUTPUT_VARIABLE PRJ_GIT_DESC)
34-
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
35-
OUTPUT_VARIABLE PRJ_GIT_BRANCH)
41+
execute_process(
42+
COMMAND git describe --tags --match "v*" --dirty
43+
OUTPUT_STRIP_TRAILING_WHITESPACE
44+
OUTPUT_VARIABLE PRJ_GIT_DESC)
45+
execute_process(
46+
COMMAND git rev-parse --abbrev-ref HEAD
47+
OUTPUT_STRIP_TRAILING_WHITESPACE
48+
OUTPUT_VARIABLE PRJ_GIT_BRANCH)
3649

3750
string(STRIP "${PRJ_GIT_REV}" PRJ_GIT_REV)
3851
string(STRIP "${PRJ_GIT_DESC}" PRJ_GIT_DESC)

0 commit comments

Comments
 (0)