Fix/revisit git-describe enhancement (#11124)

* Fix/keep massaging git-describe result

Ref: https://github.com/neovim/neovim/pull/11117#issuecomment-536416223

* build: revisit generation of version from Git

Fixes "make clean && make", where "auto/versiondef.h" would be missing
since b18b84d - because BYPRODUCTS are apparently removed when cleaning.

This includes the following improvements/changes:

- do not run git-describe during CMake's configure phase just for
  reporting
- do not print with changed Git version (too noisy, simplifies code)

* Move to src/nvim (included before config) for easier flow

* fallback to describe always, write empty include file

* update_version_stamp.lua: use prefix always
This commit is contained in:
Daniel Hahler
2019-10-02 03:45:59 +02:00
committed by GitHub
parent ac32426b94
commit 30ae60e7ca
4 changed files with 67 additions and 55 deletions

View File

@@ -217,6 +217,34 @@ function(get_preproc_output varname iname)
endif()
endfunction()
# Handle generating version from Git.
set(use_git_version 0)
if(NVIM_VERSION_MEDIUM)
message(STATUS "NVIM_VERSION_MEDIUM: ${NVIM_VERSION_MEDIUM}")
elseif(${CMAKE_VERSION} VERSION_LESS "3.2.0")
message(STATUS "Skipping version-string generation (requires CMake 3.2.0+)")
elseif(EXISTS ${PROJECT_SOURCE_DIR}/.git)
find_program(GIT_EXECUTABLE git)
if(GIT_EXECUTABLE)
message(STATUS "Using NVIM_VERSION_MEDIUM from Git")
set(use_git_version 1)
else()
message(STATUS "Skipping version-string generation (cannot find git)")
endif()
endif()
if(use_git_version)
# Create a update_version_stamp target to update the version during build.
file(RELATIVE_PATH relbuild "${PROJECT_SOURCE_DIR}" "${CMAKE_BINARY_DIR}")
add_custom_target(update_version_stamp ALL
COMMAND ${LUA_PRG} scripts/update_version_stamp.lua
${relbuild}/config/auto/versiondef_git.h
"v${NVIM_VERSION_MAJOR}.${NVIM_VERSION_MINOR}.${NVIM_VERSION_PATCH}"
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
BYPRODUCTS ${CMAKE_BINARY_DIR}/config/auto/versiondef_git.h)
else()
file(WRITE ${CMAKE_BINARY_DIR}/config/auto/versiondef_git.h "")
endif()
# NVIM_GENERATED_FOR_HEADERS: generated headers to be included in headers
# NVIM_GENERATED_FOR_SOURCES: generated headers to be included in sources
# NVIM_GENERATED_SOURCES: generated source files
@@ -245,12 +273,16 @@ foreach(sfile ${NVIM_SOURCES}
get_preproc_output(PREPROC_OUTPUT ${gf_i})
set(depends "${HEADER_GENERATOR}" "${sfile}")
if(use_git_version AND "${f}" STREQUAL "version.c")
# Ensure auto/versiondef_git.h exists after "make clean".
list(APPEND depends update_version_stamp)
endif()
add_custom_command(
OUTPUT "${gf_c_h}" "${gf_h_h}"
COMMAND ${CMAKE_C_COMPILER} ${sfile} ${PREPROC_OUTPUT} ${gen_cflags} ${C_FLAGS_ARRAY}
COMMAND "${LUA_PRG}" "${HEADER_GENERATOR}" "${sfile}" "${gf_c_h}" "${gf_h_h}" "${gf_i}"
DEPENDS "${HEADER_GENERATOR}" "${sfile}"
)
DEPENDS ${depends})
list(APPEND NVIM_GENERATED_FOR_SOURCES "${gf_c_h}")
list(APPEND NVIM_GENERATED_FOR_HEADERS "${gf_h_h}")
if(${d} MATCHES "^api$" AND NOT ${f} MATCHES "^api/helpers.c$")