From 08c99dcff0d9397a1d464eee159b1d56217fc5e0 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 4 Oct 2014 17:50:31 +0000 Subject: [PATCH 1/6] version: update user-facing version indicators - VIM_VERSION_LONG and VIM_VERSION_LONG_DATE do not affect plugins, they are only cosmetic. - Vim-related version identifiers will be preserved for plugin compatibility (has("patchXXX") and v:version). --- runtime/doc/uganda.txt | 4 --- src/nvim/hardcopy.c | 2 +- src/nvim/version.c | 65 ++++------------------------------------- src/nvim/version_defs.h | 31 +++++++------------- 4 files changed, 18 insertions(+), 84 deletions(-) diff --git a/runtime/doc/uganda.txt b/runtime/doc/uganda.txt index 113df4f64f..ee1c36d676 100644 --- a/runtime/doc/uganda.txt +++ b/runtime/doc/uganda.txt @@ -123,10 +123,6 @@ Note: - Once a change is included that goes under the GNU GPL, this forces all further changes to also be made under the GNU GPL or a compatible license. -- If you distribute a modified version of Vim, you can include your name and - contact information with the "--with-modified-by" configure argument or the - MODIFIED_BY define. - ============================================================================== Kibaale Children's Centre *kcc* *Kibaale* *charity* diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index b964aa7353..c6354d6c5f 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -2457,7 +2457,7 @@ int mch_print_begin(prt_settings_T *psettings) STRCPY(buffer, "Unknown"); } prt_dsc_textline("For", buffer); - prt_dsc_textline("Creator", VIM_VERSION_LONG); + prt_dsc_textline("Creator", NVIM_VERSION_LONG); /* Note: to ensure Clean8bit I don't think we can use LC_TIME */ now = time(NULL); p_time = ctime(&now); diff --git a/src/nvim/version.c b/src/nvim/version.c index 043b720743..bded91523b 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -1,14 +1,7 @@ /// @file version.c /// -/// Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred) -/// It has been changed beyond recognition since then. -/// -/// Differences between version 6.x and 7.x can be found with ":help version7". -/// Differences between version 5.x and 6.x can be found with ":help version6". -/// Differences between version 4.x and 5.x can be found with ":help version5". -/// Differences between version 3.0 and 4.x can be found with ":help version4". -/// All the remarks about older versions have been removed, they are not very -/// interesting. +/// Nvim was forked from Vim 7.4.160. +/// Vim originated from Stevie version 3.6 (Fish disk 217) by GRWalter (Fred). #include @@ -25,9 +18,8 @@ #include "nvim/version_defs.h" char *Version = VIM_VERSION_SHORT; -static char *mediumVersion = VIM_VERSION_MEDIUM; -char *longVersion = VIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")"; +char *longVersion = NVIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")"; #ifdef INCLUDE_GENERATED_DECLARATIONS @@ -800,12 +792,6 @@ void list_version(void) } } -#ifdef MODIFIED_BY - MSG_PUTS("\n"); - MSG_PUTS(_("Modified by ")); - MSG_PUTS(MODIFIED_BY); -#endif // ifdef MODIFIED_BY - #ifdef HAVE_PATHDEF if ((*compiled_user != NUL) || (*compiled_sys != NUL)) { @@ -929,13 +915,9 @@ void intro_message(int colon) int sponsor; char *p; static char *(lines[]) = { - N_("VIM - Vi IMproved"), + N_(NVIM_VERSION_LONG), "", - N_("version "), N_("by Bram Moolenaar et al."), -#ifdef MODIFIED_BY - " ", -#endif // ifdef MODIFIED_BY N_("Vim is open source and freely distributable"), "", N_("Help poor children in Uganda!"), @@ -943,7 +925,6 @@ void intro_message(int colon) "", N_("type :q to exit "), N_("type :help or for on-line help"), - N_("type :help version7 for version info"), NULL, "", N_("Running in Vi compatible mode"), @@ -1001,7 +982,7 @@ void intro_message(int colon) } if (*p != NUL) { - do_intro_line(row, (char_u *)_(p), i == 2, 0); + do_intro_line(row, (char_u *)_(p), 0); } row++; } @@ -1013,45 +994,16 @@ void intro_message(int colon) } } -static void do_intro_line(int row, char_u *mesg, int add_version, int attr) +static void do_intro_line(int row, char_u *mesg, int attr) { - char_u vers[20]; int col; char_u *p; int l; int clen; -#ifdef MODIFIED_BY -# define MODBY_LEN 150 - char_u modby[MODBY_LEN]; - - if (*mesg == ' ') { - l = STRLCPY(modby, _("Modified by "), MODBY_LEN); - if (l < MODBY_LEN - 1) { - STRLCPY(modby + l, MODIFIED_BY, MODBY_LEN - l); - } - mesg = modby; - } -#endif // ifdef MODIFIED_BY - // Center the message horizontally. col = vim_strsize(mesg); - if (add_version) { - STRCPY(vers, mediumVersion); - - if (highest_patch()) { - // Check for 9.9x or 9.9xx, alpha/beta version - if (isalpha((int)vers[3])) { - int len = (isalpha((int)vers[4])) ? 5 : 4; - sprintf((char *)vers + len, ".%d%s", highest_patch(), - mediumVersion + len); - } else { - sprintf((char *)vers + 3, ".%d", highest_patch()); - } - } - col += (int)STRLEN(vers); - } col = (Columns - col) / 2; if (col < 0) { @@ -1074,11 +1026,6 @@ static void do_intro_line(int row, char_u *mesg, int add_version, int attr) screen_puts_len(p, l, row, col, *p == '<' ? hl_attr(HLF_8) : attr); col += clen; } - - // Add the version number to the version line. - if (add_version) { - screen_puts(vers, row, col, 0); - } } /// ":intro": clear screen, display intro screen and wait for return. diff --git a/src/nvim/version_defs.h b/src/nvim/version_defs.h index 65dbfc8581..3a0eba37f6 100644 --- a/src/nvim/version_defs.h +++ b/src/nvim/version_defs.h @@ -1,19 +1,12 @@ #ifndef NVIM_VERSION_DEFS_H #define NVIM_VERSION_DEFS_H -/* - * VIM - Vi IMproved by Bram Moolenaar - * - * Do ":help uganda" in Vim to read copying and usage conditions. - * Do ":help credits" in Vim to see a list of people who contributed. - */ +// VIM - Vi IMproved by Bram Moolenaar +// +// Do ":help uganda" in Vim to read copying and usage conditions. +// Do ":help credits" in Vim to see a list of people who contributed. -/* - * Define the version number, name, etc. - * The patchlevel is in included_patches[], in version.c. - * - * This doesn't use string concatenation, some compilers don't support it. - */ +// Vim version number, name, etc. Patchlevel is defined in version.c. #define VIM_VERSION_MAJOR 7 #define VIM_VERSION_MAJOR_STR "7" @@ -29,17 +22,15 @@ /* Used by MacOS port should be one of: development, alpha, beta, final */ #define VIM_VERSION_RELEASE development -/* - * VIM_VERSION_NODOT is used for the runtime directory name. - * VIM_VERSION_SHORT is copied into the swap file (max. length is 6 chars). - * VIM_VERSION_MEDIUM is used for the startup-screen. - * VIM_VERSION_LONG is used for the ":version" command and "Vim -h". - */ +// used for the runtime directory name #define VIM_VERSION_NODOT "vim74" +// copied into the swap file (max. length is 6 chars) #define VIM_VERSION_SHORT "7.4" +// used for the startup-screen #define VIM_VERSION_MEDIUM "7.4" -#define VIM_VERSION_LONG "VIM - Vi IMproved 7.4 (2014)" -#define VIM_VERSION_LONG_DATE "VIM - Vi IMproved 7.4 (2014, compiled " +// used for the ":version" command and "Vim -h" +#define NVIM_VERSION_LONG "NVIM 0.0.0 pre-alpha" +#define NVIM_VERSION_LONG_DATE "NVIM 0.0.0 pre-alpha (compiled " /* Displayed on splash screen. */ #define MODIFIED_BY "the Neovim contributors." From b80d8039670ff3405a7f5ea9b6b4444f5c337d18 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 4 Oct 2014 18:08:11 +0000 Subject: [PATCH 2/6] version: remove "Included patches" message It is meaningless to Nvim. --- src/nvim/version.c | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/src/nvim/version.c b/src/nvim/version.c index bded91523b..0af28fcdca 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -744,48 +744,17 @@ static void list_features(void) void list_version(void) { - int i; - int first; - char *s = ""; - // When adding features here, don't forget to update the list of // internal variables in eval.c! MSG(longVersion); - // Print the list of patch numbers if there is at least one. - // Print a range when patches are consecutive: "1-10, 12, 15-40, 42-45" - if (included_patches[0] != 0) { - MSG_PUTS(_("\nIncluded patches: ")); - first = -1; - - // find last one - for (i = 0; included_patches[i] != 0; ++i) {} - - while (--i >= 0) { - if (first < 0) { - first = included_patches[i]; - } - - if ((i == 0) || (included_patches[i - 1] != included_patches[i] + 1)) { - MSG_PUTS(s); - s = ", "; - msg_outnum((long)first); - - if (first != included_patches[i]) { - MSG_PUTS("-"); - msg_outnum((long)included_patches[i]); - } - first = -1; - } - } - } - // Print the list of extra patch descriptions if there is at least one. + char *s = ""; if (extra_patches[0] != NULL) { MSG_PUTS(_("\nExtra patches: ")); s = ""; - for (i = 0; extra_patches[i] != NULL; ++i) { + for (int i = 0; extra_patches[i] != NULL; ++i) { MSG_PUTS(s); s = ", "; MSG_PUTS(extra_patches[i]); @@ -809,8 +778,6 @@ void list_version(void) } #endif // ifdef HAVE_PATHDEF - MSG_PUTS(_("\nHuge version ")); - MSG_PUTS(_("without GUI.")); version_msg(_(" Features included (+) or not (-):\n")); list_features(); From ff023a47e33cf2f652a7f0805f677d2afa7580cb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 4 Oct 2014 19:16:55 +0000 Subject: [PATCH 3/6] version: remove non-functional Vim version identifiers --- src/nvim/ex_cmds.c | 4 ++-- src/nvim/version_defs.h | 50 ++++++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index c3408cc4db..78c8b61c37 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -1724,8 +1724,8 @@ static void do_viminfo(FILE *fp_in, FILE *fp_out, int flags) } if (fp_out != NULL) { /* Write the info: */ - fprintf(fp_out, _("# This viminfo file was generated by Vim %s.\n"), - VIM_VERSION_MEDIUM); + fprintf(fp_out, _("# This viminfo file was generated by Nvim %s.\n"), + NVIM_VERSION_MEDIUM); fputs(_("# You may edit it if you're careful!\n\n"), fp_out); fputs(_("# Value of 'encoding' when this file was written\n"), fp_out); fprintf(fp_out, "*encoding=%s\n\n", p_enc); diff --git a/src/nvim/version_defs.h b/src/nvim/version_defs.h index 3a0eba37f6..9257580dac 100644 --- a/src/nvim/version_defs.h +++ b/src/nvim/version_defs.h @@ -6,33 +6,43 @@ // Do ":help uganda" in Vim to read copying and usage conditions. // Do ":help credits" in Vim to see a list of people who contributed. +#define STR_(x) #x +#define STR(x) STR_(x) + +// +// Nvim version identifiers +// +#ifndef NVIM_VERSION_MAJOR +#define NVIM_VERSION_MAJOR 0 +#endif +#ifndef NVIM_VERSION_MINOR +#define NVIM_VERSION_MINOR 0 +#endif +#ifndef NVIM_VERSION_PATCH +#define NVIM_VERSION_PATCH 0 +#endif +#ifndef NVIM_VERSION_PRERELEASE +#define NVIM_VERSION_PRERELEASE +#endif +#ifndef NVIM_VERSION_BUILD +#define NVIM_VERSION_BUILD +#endif +// for the startup-screen +#define NVIM_VERSION_MEDIUM STR(NVIM_VERSION_MAJOR) "." STR(NVIM_VERSION_MINOR) +// for the ":version" command and "nvim -h" +#define NVIM_VERSION_LONG "NVIM " NVIM_VERSION_MEDIUM "." STR(NVIM_VERSION_PATCH) NVIM_VERSION_PRERELEASE NVIM_VERSION_BUILD +#define NVIM_VERSION_LONG_DATE NVIM_VERSION_LONG " (compiled " + +// // Vim version number, name, etc. Patchlevel is defined in version.c. - +// #define VIM_VERSION_MAJOR 7 -#define VIM_VERSION_MAJOR_STR "7" #define VIM_VERSION_MINOR 4 -#define VIM_VERSION_MINOR_STR "4" #define VIM_VERSION_100 (VIM_VERSION_MAJOR * 100 + VIM_VERSION_MINOR) -#define VIM_VERSION_BUILD 280 -#define VIM_VERSION_BUILD_BCD 0x118 -#define VIM_VERSION_BUILD_STR "280" -#define VIM_VERSION_PATCHLEVEL 0 -#define VIM_VERSION_PATCHLEVEL_STR "0" -/* Used by MacOS port should be one of: development, alpha, beta, final */ -#define VIM_VERSION_RELEASE development - // used for the runtime directory name #define VIM_VERSION_NODOT "vim74" -// copied into the swap file (max. length is 6 chars) +// swap file compatibility (max. length is 6 chars) #define VIM_VERSION_SHORT "7.4" -// used for the startup-screen -#define VIM_VERSION_MEDIUM "7.4" -// used for the ":version" command and "Vim -h" -#define NVIM_VERSION_LONG "NVIM 0.0.0 pre-alpha" -#define NVIM_VERSION_LONG_DATE "NVIM 0.0.0 pre-alpha (compiled " - -/* Displayed on splash screen. */ -#define MODIFIED_BY "the Neovim contributors." #endif // NVIM_VERSION_DEFS_H From 2c2fee4d1f510791c4c0a7021f11c7be820c7adb Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 4 Oct 2014 22:32:47 +0000 Subject: [PATCH 4/6] version: report commit hash as "build number" in long version string --- CMakeLists.txt | 11 +- cmake/GetGitRevisionDescription.cmake | 132 +++++++++++++++++++++++ cmake/GetGitRevisionDescription.cmake.in | 38 +++++++ config/config.h.in | 8 +- 4 files changed, 183 insertions(+), 6 deletions(-) create mode 100644 cmake/GetGitRevisionDescription.cmake create mode 100644 cmake/GetGitRevisionDescription.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 435a215e51..fa79c9f91c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,9 +12,14 @@ set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin") list(APPEND CMAKE_PREFIX_PATH ${DEPS_INSTALL_DIR}) -set(NEOVIM_VERSION_MAJOR 0) -set(NEOVIM_VERSION_MINOR 0) -set(NEOVIM_VERSION_PATCH 0) +include(GetGitRevisionDescription) +get_git_head_revision(GIT_REFSPEC GIT_SHA1) +set(NVIM_VERSION_MAJOR 0) +set(NVIM_VERSION_MINOR 0) +set(NVIM_VERSION_PATCH 0) +set(NVIM_VERSION_PRERELEASE "-alpha") +# TODO(justinmk): do not set this for "release" builds #1071 +set(NVIM_VERSION_BUILD "+${GIT_SHA1}") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake new file mode 100644 index 0000000000..d77c89eda9 --- /dev/null +++ b/cmake/GetGitRevisionDescription.cmake @@ -0,0 +1,132 @@ +# https://github.com/rpavlik/cmake-modules +# +# - Returns a version string from Git +# +# These functions force a re-configure on each git commit so that you can +# trust the values of the variables in your build system. +# +# get_git_head_revision( [ ...]) +# +# Returns the refspec and sha hash of the current head revision +# +# git_describe( [ ...]) +# +# Returns the results of git describe on the source tree, and adjusting +# the output so that it tests false if an error occurs. +# +# git_get_exact_tag( [ ...]) +# +# Returns the results of git describe --exact-match on the source tree, +# and adjusting the output so that it tests false if there was no exact +# matching tag. +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(__get_git_revision_description) + return() +endif() +set(__get_git_revision_description YES) + +# We must run the following at "include" time, not at function call time, +# to find the path to this module rather than the path to a calling list file +get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) + +function(get_git_head_revision _refspecvar _hashvar) + set(GIT_PARENT_DIR "${CMAKE_CURRENT_SOURCE_DIR}") + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + while(NOT EXISTS "${GIT_DIR}") # .git dir not found, search parent directories + set(GIT_PREVIOUS_PARENT "${GIT_PARENT_DIR}") + get_filename_component(GIT_PARENT_DIR ${GIT_PARENT_DIR} PATH) + if(GIT_PARENT_DIR STREQUAL GIT_PREVIOUS_PARENT) + # We have reached the root directory, we are not in git + set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE) + return() + endif() + set(GIT_DIR "${GIT_PARENT_DIR}/.git") + endwhile() + # check if this is a submodule + if(NOT IS_DIRECTORY ${GIT_DIR}) + file(READ ${GIT_DIR} submodule) + string(REGEX REPLACE "gitdir: (.*)\n$" "\\1" GIT_DIR_RELATIVE ${submodule}) + get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH) + get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE) + endif() + set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data") + if(NOT EXISTS "${GIT_DATA}") + file(MAKE_DIRECTORY "${GIT_DATA}") + endif() + + if(NOT EXISTS "${GIT_DIR}/HEAD") + return() + endif() + set(HEAD_FILE "${GIT_DATA}/HEAD") + configure_file("${GIT_DIR}/HEAD" "${HEAD_FILE}" COPYONLY) + + configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" + "${GIT_DATA}/grabRef.cmake" + @ONLY) + include("${GIT_DATA}/grabRef.cmake") + + set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE) + set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE) +endfunction() + +function(git_describe _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() + + # TODO sanitize + #if((${ARGN}" MATCHES "&&") OR + # (ARGN MATCHES "||") OR + # (ARGN MATCHES "\\;")) + # message("Please report the following error to the project!") + # message(FATAL_ERROR "Looks like someone's doing something nefarious with git_describe! Passed arguments ${ARGN}") + #endif() + + #message(STATUS "Arguments to execute_process: ${ARGN}") + + execute_process(COMMAND + "${GIT_EXECUTABLE}" + describe + ${hash} + ${ARGN} + WORKING_DIRECTORY + "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE + res + OUTPUT_VARIABLE + out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() + + set(${_var} "${out}" PARENT_SCOPE) +endfunction() + +function(git_get_exact_tag _var) + git_describe(out --exact-match ${ARGN}) + set(${_var} "${out}" PARENT_SCOPE) +endfunction() diff --git a/cmake/GetGitRevisionDescription.cmake.in b/cmake/GetGitRevisionDescription.cmake.in new file mode 100644 index 0000000000..8a085b2671 --- /dev/null +++ b/cmake/GetGitRevisionDescription.cmake.in @@ -0,0 +1,38 @@ +# +# Internal file for GetGitRevisionDescription.cmake +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +set(HEAD_HASH) + +file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024) + +string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS) +if(HEAD_CONTENTS MATCHES "ref") + # named branch + string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}") + if(EXISTS "@GIT_DIR@/${HEAD_REF}") + configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + elseif(EXISTS "@GIT_DIR@/logs/${HEAD_REF}") + configure_file("@GIT_DIR@/logs/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY) + set(HEAD_HASH "${HEAD_REF}") + endif() +else() + # detached HEAD + configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY) +endif() + +if(NOT HEAD_HASH) + file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024) + string(STRIP "${HEAD_HASH}" HEAD_HASH) +endif() diff --git a/config/config.h.in b/config/config.h.in index ba0945cf56..95d5326ad6 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -1,6 +1,8 @@ -#define NEOVIM_VERSION_MAJOR @NEOVIM_VERSION_MAJOR@ -#define NEOVIM_VERSION_MINOR @NEOVIM_VERSION_MINOR@ -#define NEOVIM_VERSION_PATCH @NEOVIM_VERSION_PATCH@ +#define NVIM_VERSION_MAJOR @NVIM_VERSION_MAJOR@ +#define NVIM_VERSION_MINOR @NVIM_VERSION_MINOR@ +#define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@ +#define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@" +#define NVIM_VERSION_BUILD "@NVIM_VERSION_BUILD@" #cmakedefine DEBUG From a1901941f8de5de54e0da1fe314d92bf705bca38 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 7 Oct 2014 05:45:05 +0000 Subject: [PATCH 5/6] version: generate "build number" from commit timestamp - cmake: git_timestamp() returns last commit time formatted as `YYYYMMddHHmm`. - Always include commit hash in :version and --version output. `nvim --version` sample output: NVIM 0.0.0-alpha+201410070245 (compiled Oct 7 2014 05:30:45) Commit: f747b2b1ff7bfe7eb00cc2be82d7af87c98f1111 --- CMakeLists.txt | 7 +++++-- cmake/GetGitRevisionDescription.cmake | 29 +++++++++++++++++++++++++++ config/config.h.in | 1 + src/nvim/version.c | 6 +++--- src/nvim/version_defs.h | 4 +++- 5 files changed, 41 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fa79c9f91c..8fab8d52e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,14 +12,17 @@ set(DEPS_BIN_DIR "${DEPS_INSTALL_DIR}/bin") list(APPEND CMAKE_PREFIX_PATH ${DEPS_INSTALL_DIR}) +# Version tokens include(GetGitRevisionDescription) -get_git_head_revision(GIT_REFSPEC GIT_SHA1) +get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT) set(NVIM_VERSION_MAJOR 0) set(NVIM_VERSION_MINOR 0) set(NVIM_VERSION_PATCH 0) set(NVIM_VERSION_PRERELEASE "-alpha") +# TODO(justinmk): UTC time would be nice here #1071 +git_timestamp(GIT_TIMESTAMP) # TODO(justinmk): do not set this for "release" builds #1071 -set(NVIM_VERSION_BUILD "+${GIT_SHA1}") +set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") set(CMAKE_EXPORT_COMPILE_COMMANDS ON) diff --git a/cmake/GetGitRevisionDescription.cmake b/cmake/GetGitRevisionDescription.cmake index d77c89eda9..42775057f1 100644 --- a/cmake/GetGitRevisionDescription.cmake +++ b/cmake/GetGitRevisionDescription.cmake @@ -126,6 +126,35 @@ function(git_describe _var) set(${_var} "${out}" PARENT_SCOPE) endfunction() +function(git_timestamp _var) + if(NOT GIT_FOUND) + find_package(Git QUIET) + endif() + get_git_head_revision(refspec hash) + if(NOT GIT_FOUND) + set(${_var} "GIT-NOTFOUND" PARENT_SCOPE) + return() + endif() + if(NOT hash) + set(${_var} "HEAD-HASH-NOTFOUND" PARENT_SCOPE) + return() + endif() + + execute_process(COMMAND "${GIT_EXECUTABLE}" log -1 --format="%ci" ${hash} ${ARGN} + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + RESULT_VARIABLE res + OUTPUT_VARIABLE out + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(NOT res EQUAL 0) + set(out "${out}-${res}-NOTFOUND") + endif() + string(REGEX REPLACE "[-\" :]" "" out ${out}) + string(SUBSTRING ${out} 0 12 out) + + set(${_var} ${out} PARENT_SCOPE) +endfunction() + function(git_get_exact_tag _var) git_describe(out --exact-match ${ARGN}) set(${_var} "${out}" PARENT_SCOPE) diff --git a/config/config.h.in b/config/config.h.in index 95d5326ad6..7a04837c92 100644 --- a/config/config.h.in +++ b/config/config.h.in @@ -3,6 +3,7 @@ #define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@ #define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@" #define NVIM_VERSION_BUILD "@NVIM_VERSION_BUILD@" +#define NVIM_VERSION_COMMIT "@NVIM_VERSION_COMMIT@" #cmakedefine DEBUG diff --git a/src/nvim/version.c b/src/nvim/version.c index 0af28fcdca..a79ef47e7e 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -18,9 +18,8 @@ #include "nvim/version_defs.h" char *Version = VIM_VERSION_SHORT; - -char *longVersion = NVIM_VERSION_LONG_DATE __DATE__ " " __TIME__ ")"; - +char *longVersion = NVIM_VERSION_LONG " (compiled " __DATE__ " " __TIME__ ")"; +char *version_commit = "Commit: " NVIM_VERSION_COMMIT; #ifdef INCLUDE_GENERATED_DECLARATIONS # include "version.c.generated.h" @@ -747,6 +746,7 @@ void list_version(void) // When adding features here, don't forget to update the list of // internal variables in eval.c! MSG(longVersion); + MSG(version_commit); // Print the list of extra patch descriptions if there is at least one. char *s = ""; diff --git a/src/nvim/version_defs.h b/src/nvim/version_defs.h index 9257580dac..d8e1b4ea82 100644 --- a/src/nvim/version_defs.h +++ b/src/nvim/version_defs.h @@ -27,11 +27,13 @@ #ifndef NVIM_VERSION_BUILD #define NVIM_VERSION_BUILD #endif +#ifndef NVIM_VERSION_COMMIT +#define NVIM_VERSION_COMMIT +#endif // for the startup-screen #define NVIM_VERSION_MEDIUM STR(NVIM_VERSION_MAJOR) "." STR(NVIM_VERSION_MINOR) // for the ":version" command and "nvim -h" #define NVIM_VERSION_LONG "NVIM " NVIM_VERSION_MEDIUM "." STR(NVIM_VERSION_PATCH) NVIM_VERSION_PRERELEASE NVIM_VERSION_BUILD -#define NVIM_VERSION_LONG_DATE NVIM_VERSION_LONG " (compiled " // // Vim version number, name, etc. Patchlevel is defined in version.c. From ea357eb320f99d0218782a0c0c68c55514e4513c Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 7 Oct 2014 09:59:00 +0000 Subject: [PATCH 6/6] version: remove "Compilation" and "Linking" messages. Can't reliably get this information from cmake (#1267), so it's misleading to show these messages at all. We can always revert this commit if we find a way later. --- config/pathdef.c.in | 2 -- src/nvim/globals.h | 2 -- src/nvim/version.c | 5 ----- 3 files changed, 9 deletions(-) diff --git a/config/pathdef.c.in b/config/pathdef.c.in index 7977daa065..b30bcfd3f1 100644 --- a/config/pathdef.c.in +++ b/config/pathdef.c.in @@ -1,7 +1,5 @@ #include "${PROJECT_SOURCE_DIR}/src/nvim/vim.h" char_u *default_vim_dir = (char_u *)"${CMAKE_INSTALL_PREFIX}/share/nvim"; char_u *default_vimruntime_dir = (char_u *)""; -char_u *all_cflags = (char_u *)"${COMPILER_FLAGS}"; -char_u *all_lflags = (char_u *)"${LINKER_FLAGS}"; char_u *compiled_user = (char_u *)"${USERNAME}"; char_u *compiled_sys = (char_u *)"${HOSTNAME}"; diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 25c453fea8..3f968ff5a0 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -996,8 +996,6 @@ extern char *longVersion; #ifdef HAVE_PATHDEF extern char_u *default_vim_dir; extern char_u *default_vimruntime_dir; -extern char_u *all_cflags; -extern char_u *all_lflags; extern char_u *compiled_user; extern char_u *compiled_sys; #endif diff --git a/src/nvim/version.c b/src/nvim/version.c index a79ef47e7e..efefcc3c6f 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -825,11 +825,6 @@ void list_version(void) version_msg((char *)default_vimruntime_dir); version_msg("\"\n"); } - version_msg(_("Compilation: ")); - version_msg((char *)all_cflags); - version_msg("\n"); - version_msg(_("Linking: ")); - version_msg((char *)all_lflags); #endif // ifdef HAVE_PATHDEF #ifdef DEBUG version_msg("\n");