Skip to content

Commit

Permalink
feat(version): add build field to vim.version()
Browse files Browse the repository at this point in the history
This exposes the git hash of the build to the lua table, generated by CMake.

Closes #23863
  • Loading branch information
PriceHiller committed Jun 7, 2023
1 parent c1ee187 commit 37db463
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cmake/GenerateVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ if(RES)
return()
endif()

# Extract build info: "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)
Expand All @@ -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})
Expand Down
6 changes: 6 additions & 0 deletions src/nvim/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"." STR(NVIM_VERSION_MINOR) "." STR(NVIM_VERSION_PATCH) \
NVIM_VERSION_PRERELEASE
#endif

#define NVIM_VERSION_LONG "NVIM " NVIM_VERSION_MEDIUM // NOLINT(bugprone-suspicious-missing-comma)

char *Version = VIM_VERSION_SHORT;
Expand Down Expand Up @@ -2560,6 +2561,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));
Expand Down
2 changes: 2 additions & 0 deletions test/functional/api/version_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ describe("api_info()['version']", function()
local minor = version['minor']
local patch = version['patch']
local prerelease = version['prerelease']
local build = version['build']
assert(build == nil or type(build) == 'string')
eq("number", type(major))
eq("number", type(minor))
eq("number", type(patch))
Expand Down

0 comments on commit 37db463

Please sign in to comment.