Merge pull request #3584 from justinmk/gitdescribe

build: Use `git describe` for version strings.
This commit is contained in:
Justin M. Keyes 2015-11-03 09:28:54 -05:00
commit ea4b8f9c8f
4 changed files with 23 additions and 20 deletions

View File

@ -47,24 +47,26 @@ if(NOT CMAKE_BUILD_TYPE)
endif() endif()
# Version tokens # Version tokens
# - In a git repo, these tokens are _ignored_.
# - If the current HEAD is tagged, the tag name is used.
# - Otherwise the result of `git describe` is used.
# - If not in a git repo (e.g. a tarball) these tokens set the version string.
set(NVIM_VERSION_MAJOR 0) set(NVIM_VERSION_MAJOR 0)
set(NVIM_VERSION_MINOR 1) set(NVIM_VERSION_MINOR 1)
set(NVIM_VERSION_PATCH 0) set(NVIM_VERSION_PATCH 0)
set(NVIM_VERSION_PRERELEASE "-dev")
file(TO_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/.git FORCED_GIT_DIR) file(TO_CMAKE_PATH ${CMAKE_CURRENT_LIST_DIR}/.git FORCED_GIT_DIR)
include(GetGitRevisionDescription) include(GetGitRevisionDescription)
if(NVIM_VERSION_PRERELEASE) get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT)
get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT) if(NVIM_VERSION_COMMIT) # is a git repo
git_get_exact_tag(NVIM_VERSION_MEDIUM)
# TODO(justinmk): UTC time would be nice here #1071 if(NVIM_VERSION_MEDIUM) # is a tagged release
git_timestamp(GIT_TIMESTAMP) unset(NVIM_VERSION_COMMIT)
if(GIT_TIMESTAMP) else() # is a dev build
set(NVIM_VERSION_BUILD "+${GIT_TIMESTAMP}") git_describe(NVIM_VERSION_MEDIUM)
get_git_head_revision(GIT_REFSPEC NVIM_VERSION_COMMIT)
endif() endif()
else()
# If possible, get the Git tag for the current revision.
git_get_exact_tag(NVIM_VERSION_COMMIT)
set(NVIM_VERSION_BUILD "")
endif() endif()
set(NVIM_VERSION_BUILD_TYPE "${CMAKE_BUILD_TYPE}") set(NVIM_VERSION_BUILD_TYPE "${CMAKE_BUILD_TYPE}")

View File

@ -5,8 +5,9 @@
#define NVIM_VERSION_MINOR @NVIM_VERSION_MINOR@ #define NVIM_VERSION_MINOR @NVIM_VERSION_MINOR@
#define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@ #define NVIM_VERSION_PATCH @NVIM_VERSION_PATCH@
#define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@" #define NVIM_VERSION_PRERELEASE "@NVIM_VERSION_PRERELEASE@"
#define NVIM_VERSION_BUILD "@NVIM_VERSION_BUILD@"
#cmakedefine NVIM_VERSION_COMMIT "@NVIM_VERSION_COMMIT@" #cmakedefine NVIM_VERSION_COMMIT "@NVIM_VERSION_COMMIT@"
#cmakedefine NVIM_VERSION_MEDIUM "@NVIM_VERSION_MEDIUM@"
#define NVIM_VERSION_CFLAGS "@NVIM_VERSION_CFLAGS@" #define NVIM_VERSION_CFLAGS "@NVIM_VERSION_CFLAGS@"
#define NVIM_VERSION_BUILD_TYPE "@NVIM_VERSION_BUILD_TYPE@" #define NVIM_VERSION_BUILD_TYPE "@NVIM_VERSION_BUILD_TYPE@"

View File

@ -25,17 +25,18 @@
#define STR_(x) #x #define STR_(x) #x
#define STR(x) STR_(x) #define STR(x) STR_(x)
// for the startup-screen ( ":intro" command ) // for ":version", ":intro", and "nvim --version"
#define NVIM_VERSION_MEDIUM STR(NVIM_VERSION_MAJOR) "." STR(NVIM_VERSION_MINOR) #ifndef NVIM_VERSION_MEDIUM
#define NVIM_VERSION_MEDIUM STR(NVIM_VERSION_MAJOR) "." STR(NVIM_VERSION_MINOR)\
// for the ":version" command and "nvim --version" "." STR(NVIM_VERSION_PATCH) NVIM_VERSION_PRERELEASE
#define NVIM_VERSION_LONG "NVIM " NVIM_VERSION_MEDIUM "." STR(NVIM_VERSION_PATCH) NVIM_VERSION_PRERELEASE NVIM_VERSION_BUILD #endif
#define NVIM_VERSION_LONG "NVIM " NVIM_VERSION_MEDIUM
char *Version = VIM_VERSION_SHORT; char *Version = VIM_VERSION_SHORT;
char *longVersion = NVIM_VERSION_LONG; char *longVersion = NVIM_VERSION_LONG;
char *longVersionWithDate = NVIM_VERSION_LONG " (compiled " __DATE__ " " __TIME__ ")"; char *longVersionWithDate = NVIM_VERSION_LONG \
char *mediumVersion = NVIM_VERSION_MEDIUM; " (compiled " __DATE__ " " __TIME__ ")";
#ifdef NVIM_VERSION_COMMIT #ifdef NVIM_VERSION_COMMIT
char *version_commit = "Commit: " NVIM_VERSION_COMMIT; char *version_commit = "Commit: " NVIM_VERSION_COMMIT;
#endif #endif

View File

@ -3,7 +3,6 @@
// defined in version.c // defined in version.c
extern char* Version; extern char* Version;
extern char* mediumVersion;
extern char* longVersion; extern char* longVersion;
// //