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 6, 2023
1 parent c1ee187 commit cb93908
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cmake/GenerateVersion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ execute_process(
ERROR_QUIET
RESULT_VARIABLE RES)

# Extract build info: "145+g0f9113907" => "g0f9113907"
# if on a "dirty" branch, this will also append `-dirty` to the end: "g0f9113907-dirty"
string(REGEX REPLACE "[0-9]+\\+" "" NVIM_VERSION_BUILD "${GIT_TAG}")
# Prefix with a `g`
set(NVIM_VERSION_BUILD "g${NVIM_VERSION_BUILD}")
file(WRITE "${OUTPUT}" "#define NVIM_VERSION_BUILD \"${NVIM_VERSION_BUILD}\"\n")


if(RES)
message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
file(WRITE "${OUTPUT}" "")
Expand All @@ -33,7 +41,7 @@ endif()

if(NOT "${NVIM_VERSION_HASH}" STREQUAL "${CURRENT_VERSION_HASH}")
message(STATUS "Using NVIM_VERSION: ${NVIM_VERSION}")
file(WRITE "${OUTPUT}" "${NVIM_VERSION_STRING}")
file(APPEND "${OUTPUT}" "${NVIM_VERSION_STRING}")
if(WIN32)
configure_file("${OUTPUT}" "${OUTPUT}" NEWLINE_STYLE UNIX)
endif()
Expand Down
1 change: 1 addition & 0 deletions src/nvim/version.c
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,7 @@ 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));
PUT(d, "build", CSTR_AS_OBJ(NVIM_VERSION_BUILD));
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

0 comments on commit cb93908

Please sign in to comment.