aboutsummaryrefslogtreecommitdiff
path: root/scripts/update_version_stamp.lua
diff options
context:
space:
mode:
authorDaniel Hahler <git@thequod.de>2019-10-02 03:45:59 +0200
committerGitHub <noreply@github.com>2019-10-02 03:45:59 +0200
commit30ae60e7cac7e77005aa429bc13f8ffa3ce64eb1 (patch)
tree8723d4c2441f61df7f2c590d1f50b8b3f2e44cef /scripts/update_version_stamp.lua
parentac32426b94deabb6843fab797957f0064a54c5a5 (diff)
downloadrneovim-30ae60e7cac7e77005aa429bc13f8ffa3ce64eb1.tar.gz
rneovim-30ae60e7cac7e77005aa429bc13f8ffa3ce64eb1.tar.bz2
rneovim-30ae60e7cac7e77005aa429bc13f8ffa3ce64eb1.zip
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
Diffstat (limited to 'scripts/update_version_stamp.lua')
-rwxr-xr-x[-rw-r--r--]scripts/update_version_stamp.lua53
1 files changed, 29 insertions, 24 deletions
diff --git a/scripts/update_version_stamp.lua b/scripts/update_version_stamp.lua
index f01642043a..509e1f6fad 100644..100755
--- a/scripts/update_version_stamp.lua
+++ b/scripts/update_version_stamp.lua
@@ -4,11 +4,11 @@
-- This is called via the custom update_version_stamp target in
-- src/nvim/CMakeLists.txt.
--
--- arg[1]: file containing the last git-describe output
--- arg[2]: file in which to update the version string
+-- arg[1]: file in which to update the version string
+-- arg[2]: prefix to use always ("vX.Y.Z")
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.
os.exit(0)
end
@@ -17,29 +17,34 @@ if #arg ~= 2 then
die(string.format("Expected two args, got %d", #arg))
end
-local stampfile = arg[1]
-local stamp = io.open(stampfile, 'r')
-if stamp then
- stamp = stamp:read('*l')
+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
end
-local current = io.popen('git describe --dirty'):read('*l')
-if not current then
- die('git-describe failed')
+-- Read existing include file.
+local current = io.open(versiondeffile, 'r')
+if current then
+ current = current:read('*l')
end
-if stamp ~= current then
- if stamp then
- print(string.format('git version changed: %s -> %s', stamp, current))
- end
- local new_lines = {}
- local versiondeffile = arg[2]
- for line in io.lines(versiondeffile) do
- if line:match("NVIM_VERSION_MEDIUM") then
- line = '#define NVIM_VERSION_MEDIUM "'..current..'"'
- end
- new_lines[#new_lines + 1] = line
- end
- io.open(versiondeffile, 'w'):write(table.concat(new_lines, '\n') .. '\n')
- io.open(stampfile, 'w'):write(current)
+-- 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