build: don't append git tag on release versions

This prevents duplicate version strings such as v0.8.0-v0.8.0.

Also change the format for git releases from v0.9.0-dev-67-g625ba79be
to v0.9.0-dev-67+g625ba79be. The neovim versions are now:

release: v0.9.0
prerelease without git info: v0.9.0-dev
prerelease with git info: v0.9.0-dev-67+g625ba79be
This commit is contained in:
dundargoc 2022-10-04 11:42:53 +02:00
parent 9cb2a69039
commit 90785aafe1
2 changed files with 14 additions and 15 deletions

View File

@ -1,26 +1,27 @@
if(NVIM_VERSION_MEDIUM)
message(STATUS "USING NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
return()
endif()
set(NVIM_VERSION_MEDIUM
set(NVIM_VERSION
"v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}${NVIM_VERSION_PRERELEASE}")
execute_process(
COMMAND git describe --first-parent --dirty --always
OUTPUT_VARIABLE GIT_TAG
OUTPUT_STRIP_TRAILING_WHITESPACE
RESULT_VARIABLE RES)
if(RES AND NOT RES EQUAL 0)
message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}")
message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
file(WRITE "${OUTPUT}" "")
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 "${NVIM_VERSION_MEDIUM}-${NVIM_VERSION_GIT}")
set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION_MEDIUM}\"\n")
# `git describe` annotates the most recent tagged release; for pre-release
# builds we append that to the dev version.
if(NVIM_VERSION_PRERELEASE)
string(REGEX REPLACE "^v[0-9]+.[0-9]+.[0-9]+-" "" NVIM_VERSION_GIT "${GIT_TAG}")
string(REGEX REPLACE "^([0-9]+)-([a-z0-9]+)" "\\1+\\2" NVIM_VERSION_GIT "${NVIM_VERSION_GIT}")
set(NVIM_VERSION "${NVIM_VERSION}-${NVIM_VERSION_GIT}")
endif()
set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION}\"\n")
string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}")
if(EXISTS ${OUTPUT})
@ -28,6 +29,6 @@ if(EXISTS ${OUTPUT})
endif()
if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}")
message(STATUS "Using NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}")
endif()

View File

@ -206,9 +206,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})
# NVIM_GENERATED_FOR_HEADERS: generated headers to be included in headers