Skip to content

Commit

Permalink
Fix version file generation in external git repo
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mhx committed Apr 11, 2021
1 parent eb1fd9e commit 35cac17
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,33 @@
set(VERSION_SRC_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/dwarfs/version.cpp)
set(VERSION_HDR_FILE ${CMAKE_CURRENT_SOURCE_DIR}/include/dwarfs/version.h)

execute_process(
COMMAND git rev-parse --show-toplevel
OUTPUT_VARIABLE GIT_TOPLEVEL
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)

execute_process(
COMMAND git log --pretty=format:%h -n 1
OUTPUT_VARIABLE PRJ_GIT_REV
ERROR_QUIET)
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)

if("${PRJ_GIT_REV}" STREQUAL "")
if((NOT "${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${GIT_TOPLEVEL}")
OR ("${PRJ_GIT_REV}" STREQUAL ""))
if(NOT EXISTS ${VERSION_SRC_FILE} OR NOT EXISTS ${VERSION_HDR_FILE})
message(FATAL_ERROR "missing version files")
message("CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR}")
message("GIT_TOPLEVEL: ${GIT_TOPLEVEL}")
message("PRJ_GIT_REV: ${PRJ_GIT_REV}")
endif()
else()
execute_process(COMMAND git describe --tags --match "v*" --dirty
OUTPUT_VARIABLE PRJ_GIT_DESC)
execute_process(COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_VARIABLE PRJ_GIT_BRANCH)
execute_process(
COMMAND git describe --tags --match "v*" --dirty
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PRJ_GIT_DESC)
execute_process(
COMMAND git rev-parse --abbrev-ref HEAD
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE PRJ_GIT_BRANCH)

string(STRIP "${PRJ_GIT_REV}" PRJ_GIT_REV)
string(STRIP "${PRJ_GIT_DESC}" PRJ_GIT_DESC)
Expand Down

0 comments on commit 35cac17

Please sign in to comment.