mirror of
https://github.com/neovim/neovim.git
synced 2024-12-20 03:05:11 -07:00
6768c43e21
Avoid noise during builds: > fatal: No annotated tags can describe '417449f468c4ba186954f6295b3338fb55ee7b4a'. > However, there were unannotated tags: try --tags. This might be useful in general, but is expected to not happen - and falling back is OK then. The fallback command would still display errors then. It also uses `--first-parent`, which is important for when a release branch gets merged back.
51 lines
1.5 KiB
Lua
Executable File
51 lines
1.5 KiB
Lua
Executable File
#!/usr/bin/env lua
|
|
--
|
|
-- Script to update the Git version stamp during build.
|
|
-- This is called via the custom update_version_stamp target in
|
|
-- src/nvim/CMakeLists.txt.
|
|
--
|
|
-- arg[1]: file in which to update the version string
|
|
-- arg[2]: prefix to use always ("vX.Y.Z")
|
|
|
|
local function die(msg)
|
|
io.stderr:write(string.format('%s: %s\n', arg[0], msg))
|
|
-- No error, fall back to using generated "-dev" version.
|
|
os.exit(0)
|
|
end
|
|
|
|
if #arg ~= 2 then
|
|
die(string.format("Expected two args, got %d", #arg))
|
|
end
|
|
|
|
local versiondeffile = arg[1]
|
|
local prefix = arg[2]
|
|
|
|
local described = io.popen('git describe --first-parent --dirty 2>/dev/null'):read('*l')
|
|
if not described then
|
|
described = io.popen('git describe --first-parent --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
|
|
|
|
-- `git describe` annotates the most recent tagged release; for pre-release
|
|
-- builds we must replace that with the unreleased version.
|
|
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
|
|
|
|
-- Read existing include file.
|
|
local current = io.open(versiondeffile, 'r')
|
|
if current then
|
|
current = current:read('*l')
|
|
end
|
|
|
|
-- Write new include file, if different.
|
|
local new = '#define NVIM_VERSION_MEDIUM "'..with_prefix..'"'
|
|
if current ~= new then
|
|
io.open(versiondeffile, 'w'):write(new .. '\n')
|
|
end
|