aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortreatybreaker <price@orion-technologies.io>2023-06-11 16:57:23 -0500
committerGitHub <noreply@github.com>2023-06-11 14:57:23 -0700
commit199a990c9e4e36f72ddcd041af28185f2ee4b4d6 (patch)
treec00095f25468e053177c1419b7fc488bd05da039
parent385a1facf28b1f3ddc1c6a4dc4ca35729a852b2c (diff)
downloadrneovim-199a990c9e4e36f72ddcd041af28185f2ee4b4d6.tar.gz
rneovim-199a990c9e4e36f72ddcd041af28185f2ee4b4d6.tar.bz2
rneovim-199a990c9e4e36f72ddcd041af28185f2ee4b4d6.zip
feat: report "build" in vim.version() #23925
Problem: Nvim version string typically has a "build" component but vim.version() doesn't report it. Solution: Add the "build" field to vim.version(). Closes #23863
-rw-r--r--cmake/GenerateVersion.cmake5
-rw-r--r--src/nvim/version.c5
-rw-r--r--test/functional/api/version_spec.lua2
3 files changed, 11 insertions, 1 deletions
diff --git a/cmake/GenerateVersion.cmake b/cmake/GenerateVersion.cmake
index ab046e93ba..0758dad8ad 100644
--- a/cmake/GenerateVersion.cmake
+++ b/cmake/GenerateVersion.cmake
@@ -14,6 +14,9 @@ if(RES)
return()
endif()
+# Extract build info: "v0.9.0-145-g0f9113907" => "g0f9113907"
+string(REGEX REPLACE ".*\\-" "" NVIM_VERSION_BUILD "${GIT_TAG}")
+
# `git describe` annotates the most recent tagged release; for pre-release
# builds we append that to the dev version.
if(NVIM_VERSION_PRERELEASE)
@@ -24,7 +27,7 @@ if(NVIM_VERSION_PRERELEASE)
set(NVIM_VERSION "${NVIM_VERSION}-${NVIM_VERSION_GIT}")
endif()
-set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION}\"\n")
+set(NVIM_VERSION_STRING "#define NVIM_VERSION_MEDIUM \"${NVIM_VERSION}\"\n#define NVIM_VERSION_BUILD \"${NVIM_VERSION_BUILD}\"\n")
string(SHA1 CURRENT_VERSION_HASH "${NVIM_VERSION_STRING}")
if(EXISTS ${OUTPUT})
diff --git a/src/nvim/version.c b/src/nvim/version.c
index c0e0ceef55..b9fa7799a6 100644
--- a/src/nvim/version.c
+++ b/src/nvim/version.c
@@ -2560,6 +2560,11 @@ Dictionary version_dict(void)
PUT(d, "major", INTEGER_OBJ(NVIM_VERSION_MAJOR));
PUT(d, "minor", INTEGER_OBJ(NVIM_VERSION_MINOR));
PUT(d, "patch", INTEGER_OBJ(NVIM_VERSION_PATCH));
+#ifndef NVIM_VERSION_BUILD
+ PUT(d, "build", NIL);
+#else
+ PUT(d, "build", CSTR_AS_OBJ(NVIM_VERSION_BUILD));
+#endif
PUT(d, "prerelease", BOOLEAN_OBJ(NVIM_VERSION_PRERELEASE[0] != '\0'));
PUT(d, "api_level", INTEGER_OBJ(NVIM_API_LEVEL));
PUT(d, "api_compatible", INTEGER_OBJ(NVIM_API_LEVEL_COMPAT));
diff --git a/test/functional/api/version_spec.lua b/test/functional/api/version_spec.lua
index 771192e9ab..6d466b0cc1 100644
--- a/test/functional/api/version_spec.lua
+++ b/test/functional/api/version_spec.lua
@@ -34,6 +34,7 @@ describe("api_info()['version']", function()
local minor = version['minor']
local patch = version['patch']
local prerelease = version['prerelease']
+ local build = version['build']
eq("number", type(major))
eq("number", type(minor))
eq("number", type(patch))
@@ -42,6 +43,7 @@ describe("api_info()['version']", function()
eq(0, funcs.has("nvim-"..major.."."..minor.."."..(patch + 1)))
eq(0, funcs.has("nvim-"..major.."."..(minor + 1).."."..patch))
eq(0, funcs.has("nvim-"..(major + 1).."."..minor.."."..patch))
+ assert(build == nil or type(build) == 'string')
end)
end)