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
This commit is contained in:
Justin M. Keyes 2014-10-07 05:45:05 +00:00
parent 2c2fee4d1f
commit a1901941f8
5 changed files with 41 additions and 6 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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 = "";

View File

@ -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.