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 4d1265d
Show file tree
Hide file tree
Showing 3 changed files with 14 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 @@ -8,6 +8,9 @@ execute_process(
ERROR_QUIET
RESULT_VARIABLE RES)

# Extract build info: "145-g0f9113907" => "g0f9113907"
string(REGEX REPLACE ".*\\-" "" NVIM_VERSION_BUILD "${GIT_TAG}")

if(RES)
message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
file(WRITE "${OUTPUT}" "")
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
4 changes: 4 additions & 0 deletions test/functional/api/version_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ describe("api_info()['version']", function()
local version = call('api_info')['version']
local major = version['major']
local minor = version['minor']
local build = version['build']
local patch = version['patch']
local prerelease = version['prerelease']

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 4d1265d

Please sign in to comment.