2019-09-29 15:10:29 -07:00
|
|
|
#!/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.
|
|
|
|
--
|
2019-10-01 18:45:59 -07:00
|
|
|
-- arg[1]: file in which to update the version string
|
|
|
|
-- arg[2]: prefix to use always ("vX.Y.Z")
|
2019-09-29 15:10:29 -07:00
|
|
|
|
|
|
|
local function die(msg)
|
2019-10-01 18:45:59 -07:00
|
|
|
io.stderr:write(string.format('%s: %s\n', arg[0], msg))
|
2019-09-29 15:10:29 -07:00
|
|
|
-- 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
|
|
|
|
|
2019-10-01 18:45:59 -07:00
|
|
|
local versiondeffile = arg[1]
|
|
|
|
local prefix = arg[2]
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
-- `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
|
2019-09-29 15:10:29 -07:00
|
|
|
end
|
|
|
|
|
2019-10-01 18:45:59 -07:00
|
|
|
-- Read existing include file.
|
|
|
|
local current = io.open(versiondeffile, 'r')
|
|
|
|
if current then
|
|
|
|
current = current:read('*l')
|
2019-09-29 15:10:29 -07:00
|
|
|
end
|
|
|
|
|
2019-10-01 18:45:59 -07:00
|
|
|
-- 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')
|
2019-09-29 15:10:29 -07:00
|
|
|
end
|