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:
parent
ac32426b94
commit
30ae60e7ca
|
@ -121,35 +121,6 @@ configure_file (
|
||||||
)
|
)
|
||||||
|
|
||||||
# generate version definitions
|
# generate version definitions
|
||||||
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)
|
|
||||||
# Get current version.
|
|
||||||
execute_process(
|
|
||||||
COMMAND ${GIT_EXECUTABLE} describe --dirty
|
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
||||||
OUTPUT_VARIABLE NVIM_VERSION_MEDIUM
|
|
||||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
|
||||||
message(STATUS "NVIM_VERSION_MEDIUM (from git): ${NVIM_VERSION_MEDIUM}")
|
|
||||||
|
|
||||||
# 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}/.version_stamp
|
|
||||||
${relbuild}/config/auto/versiondef.h
|
|
||||||
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
|
|
||||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/config/auto/versiondef.h)
|
|
||||||
add_dependencies(nvim update_version_stamp)
|
|
||||||
else()
|
|
||||||
message(STATUS "Skipping version-string generation (cannot find git)")
|
|
||||||
endif()
|
|
||||||
endif()
|
|
||||||
|
|
||||||
configure_file (
|
configure_file (
|
||||||
"${PROJECT_SOURCE_DIR}/config/versiondef.h.in"
|
"${PROJECT_SOURCE_DIR}/config/versiondef.h.in"
|
||||||
"${PROJECT_BINARY_DIR}/config/auto/versiondef.h"
|
"${PROJECT_BINARY_DIR}/config/auto/versiondef.h"
|
||||||
|
|
|
@ -5,7 +5,11 @@
|
||||||
#define NVIM_VERSION_MINOR @NVIM_VERSION_MINOR@
|
#define NVIM_VERSION_MINOR @NVIM_VERSION_MINOR@
|
||||||
#define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@
|
#define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@
|
||||||
#define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@"
|
#define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@"
|
||||||
|
|
||||||
#cmakedefine NVIM_VERSION_MEDIUM "@NVIM_VERSION_MEDIUM@"
|
#cmakedefine NVIM_VERSION_MEDIUM "@NVIM_VERSION_MEDIUM@"
|
||||||
|
#ifndef NVIM_VERSION_MEDIUM
|
||||||
|
# include "auto/versiondef_git.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define NVIM_API_LEVEL @NVIM_API_LEVEL@
|
#define NVIM_API_LEVEL @NVIM_API_LEVEL@
|
||||||
#define NVIM_API_LEVEL_COMPAT @NVIM_API_LEVEL_COMPAT@
|
#define NVIM_API_LEVEL_COMPAT @NVIM_API_LEVEL_COMPAT@
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
-- This is called via the custom update_version_stamp target in
|
-- This is called via the custom update_version_stamp target in
|
||||||
-- src/nvim/CMakeLists.txt.
|
-- src/nvim/CMakeLists.txt.
|
||||||
--
|
--
|
||||||
-- arg[1]: file containing the last git-describe output
|
-- arg[1]: file in which to update the version string
|
||||||
-- arg[2]: file in which to update the version string
|
-- arg[2]: prefix to use always ("vX.Y.Z")
|
||||||
|
|
||||||
local function die(msg)
|
local function die(msg)
|
||||||
print(string.format('%s: %s', arg[0], msg))
|
io.stderr:write(string.format('%s: %s\n', arg[0], msg))
|
||||||
-- No error, fall back to using generated "-dev" version.
|
-- No error, fall back to using generated "-dev" version.
|
||||||
os.exit(0)
|
os.exit(0)
|
||||||
end
|
end
|
||||||
|
@ -17,29 +17,34 @@ if #arg ~= 2 then
|
||||||
die(string.format("Expected two args, got %d", #arg))
|
die(string.format("Expected two args, got %d", #arg))
|
||||||
end
|
end
|
||||||
|
|
||||||
local stampfile = arg[1]
|
local versiondeffile = arg[1]
|
||||||
local stamp = io.open(stampfile, 'r')
|
local prefix = arg[2]
|
||||||
if stamp then
|
|
||||||
stamp = stamp:read('*l')
|
local described = io.popen('git describe --dirty'):read('*l')
|
||||||
|
if not described then
|
||||||
|
described = io.popen('git describe --tags --always --dirty'):read('*l')
|
||||||
|
end
|
||||||
|
if not described then
|
||||||
|
io.open(versiondeffile, 'w'):write('\n')
|
||||||
|
die('git-describe failed, using empty include file.')
|
||||||
end
|
end
|
||||||
|
|
||||||
local current = io.popen('git describe --dirty'):read('*l')
|
-- `git describe` annotates the most recent tagged release; for pre-release
|
||||||
if not current then
|
-- builds we must replace that with the unreleased version.
|
||||||
die('git-describe failed')
|
local with_prefix = described:gsub("^v%d+%.%d+%.%d+", prefix)
|
||||||
|
if described == with_prefix then
|
||||||
|
-- Prepend the prefix always, e.g. with "nightly-12208-g4041b62b9".
|
||||||
|
with_prefix = prefix .. "-" .. described
|
||||||
end
|
end
|
||||||
|
|
||||||
if stamp ~= current then
|
-- Read existing include file.
|
||||||
if stamp then
|
local current = io.open(versiondeffile, 'r')
|
||||||
print(string.format('git version changed: %s -> %s', stamp, current))
|
if current then
|
||||||
end
|
current = current:read('*l')
|
||||||
local new_lines = {}
|
end
|
||||||
local versiondeffile = arg[2]
|
|
||||||
for line in io.lines(versiondeffile) do
|
-- Write new include file, if different.
|
||||||
if line:match("NVIM_VERSION_MEDIUM") then
|
local new = '#define NVIM_VERSION_MEDIUM "'..with_prefix..'"'
|
||||||
line = '#define NVIM_VERSION_MEDIUM "'..current..'"'
|
if current ~= new then
|
||||||
end
|
io.open(versiondeffile, 'w'):write(new .. '\n')
|
||||||
new_lines[#new_lines + 1] = line
|
|
||||||
end
|
|
||||||
io.open(versiondeffile, 'w'):write(table.concat(new_lines, '\n') .. '\n')
|
|
||||||
io.open(stampfile, 'w'):write(current)
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -217,6 +217,34 @@ function(get_preproc_output varname iname)
|
||||||
endif()
|
endif()
|
||||||
endfunction()
|
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_HEADERS: generated headers to be included in headers
|
||||||
# NVIM_GENERATED_FOR_SOURCES: generated headers to be included in sources
|
# NVIM_GENERATED_FOR_SOURCES: generated headers to be included in sources
|
||||||
# NVIM_GENERATED_SOURCES: generated source files
|
# NVIM_GENERATED_SOURCES: generated source files
|
||||||
|
@ -245,12 +273,16 @@ foreach(sfile ${NVIM_SOURCES}
|
||||||
|
|
||||||
get_preproc_output(PREPROC_OUTPUT ${gf_i})
|
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(
|
add_custom_command(
|
||||||
OUTPUT "${gf_c_h}" "${gf_h_h}"
|
OUTPUT "${gf_c_h}" "${gf_h_h}"
|
||||||
COMMAND ${CMAKE_C_COMPILER} ${sfile} ${PREPROC_OUTPUT} ${gen_cflags} ${C_FLAGS_ARRAY}
|
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}"
|
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_SOURCES "${gf_c_h}")
|
||||||
list(APPEND NVIM_GENERATED_FOR_HEADERS "${gf_h_h}")
|
list(APPEND NVIM_GENERATED_FOR_HEADERS "${gf_h_h}")
|
||||||
if(${d} MATCHES "^api$" AND NOT ${f} MATCHES "^api/helpers.c$")
|
if(${d} MATCHES "^api$" AND NOT ${f} MATCHES "^api/helpers.c$")
|
||||||
|
|
Loading…
Reference in New Issue