mirror of
https://github.com/neovim/neovim.git
synced 2024-12-24 05:05:00 -07:00
fix(build): non-git ("tarball") build fails #19448
Problem: Build fails without git or .git/. ref #19289 Solution: Fix the version generation logic. Test cases: If `git` is missing: -- Using NVIM_VERSION_MEDIUM: v0.8.0-dev If `.git/` is missing: -- Git tag extraction failed: fatal: not a git repository (or any of the parent directories): .git -- Using NVIM_VERSION_MEDIUM: v0.8.0-dev If `git describe` fails -- Git tag extraction failed: fatal: ... -- Using NVIM_VERSION_MEDIUM: v0.8.0-dev Co-authored-by: Justin M. Keyes <justinkz@gmail.com>
This commit is contained in:
parent
3f2e1c1db9
commit
790f8b0e16
@ -1,16 +1,10 @@
|
||||
# Handle generating version from Git.
|
||||
set(use_git_version 0)
|
||||
if(NVIM_VERSION_MEDIUM)
|
||||
message(STATUS "USING NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
find_program(GIT_EXECUTABLE git)
|
||||
if(NOT GIT_EXECUTABLE)
|
||||
message(AUTHOR_WARNING "Skipping version-string generation (cannot find git)")
|
||||
file(WRITE "${OUTPUT}" "")
|
||||
return()
|
||||
endif()
|
||||
set(NVIM_VERSION_MEDIUM
|
||||
"v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}${NVIM_VERSION_PRERELEASE}")
|
||||
|
||||
execute_process(
|
||||
COMMAND git describe --first-parent --tags --always --dirty
|
||||
@ -19,30 +13,25 @@ execute_process(
|
||||
RESULT_VARIABLE RES
|
||||
)
|
||||
|
||||
if("${RES}" EQUAL 1)
|
||||
if(EXISTS ${OUTPUT})
|
||||
message(STATUS "Unable to extract version-string from git: keeping the last known version")
|
||||
else()
|
||||
# this will only be executed once since the file will get generated afterwards
|
||||
message(AUTHOR_WARNING "Git tag extraction failed with: " "${ERR}")
|
||||
file(WRITE "${OUTPUT}" "")
|
||||
endif()
|
||||
if(NOT RES EQUAL 0)
|
||||
message(STATUS "Git tag extraction failed:\n" " ${GIT_TAG}${ERR}" )
|
||||
# This will only be executed once since the file will get generated afterwards.
|
||||
message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
|
||||
file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}")
|
||||
return()
|
||||
endif()
|
||||
|
||||
string(STRIP "${GIT_TAG}" GIT_TAG)
|
||||
string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}")
|
||||
set(NVIM_VERSION_MEDIUM
|
||||
"v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}-dev-${NVIM_VERSION_GIT}"
|
||||
)
|
||||
set(NVIM_VERSION_MEDIUM "${NVIM_VERSION_MEDIUM}-${NVIM_VERSION_GIT}")
|
||||
set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION_MEDIUM}\"\n")
|
||||
string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}")
|
||||
|
||||
string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}")
|
||||
if(EXISTS ${OUTPUT})
|
||||
file(SHA1 "${OUTPUT}" NVIM_VERSION_HASH)
|
||||
endif()
|
||||
|
||||
if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}")
|
||||
message(STATUS "Updating NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
|
||||
message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
|
||||
file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}")
|
||||
endif()
|
||||
|
@ -229,6 +229,7 @@ add_custom_target(update_version_stamp
|
||||
-DNVIM_VERSION_PATCH=${NVIM_VERSION_PATCH}
|
||||
-DNVIM_VERSION_PRERELEASE=${NVIM_VERSION_PRERELEASE}
|
||||
-DOUTPUT=${NVIM_VERSION_GIT_H}
|
||||
-DCMAKE_MESSAGE_LOG_LEVEL=${CMAKE_MESSAGE_LOG_LEVEL}
|
||||
-P ${PROJECT_SOURCE_DIR}/cmake/GenerateVersion.cmake
|
||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
||||
BYPRODUCTS ${NVIM_VERSION_GIT_H})
|
||||
|
Loading…
Reference in New Issue
Block a user