From 8ecb96c09a2c605ba0c18d0c3ad1030d5a8b77cd Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 10 Oct 2014 12:12:17 +0200 Subject: [PATCH] Add the git commit (if applicable) to LyX version This only works for autotools right now, but adding that to cmake is trivial --- config/lyxinclude.m4 | 13 ++++++++++++- configure.ac | 3 +++ src/LyX.cpp | 4 +++- src/frontends/qt4/GuiAbout.cpp | 10 +++++++++- src/version.cpp | 2 ++ src/version.h | 2 ++ 6 files changed, 31 insertions(+), 3 deletions(-) diff --git a/config/lyxinclude.m4 b/config/lyxinclude.m4 index ac0b6427f8..c781c1e574 100644 --- a/config/lyxinclude.m4 +++ b/config/lyxinclude.m4 @@ -8,9 +8,10 @@ dnl Usage LYX_CHECK_VERSION Displays version of LyX being built and dnl sets variable "build_type" AC_DEFUN([LYX_CHECK_VERSION],[ echo "configuring LyX version" AC_PACKAGE_VERSION + +AC_MSG_CHECKING([for build type]) lyx_devel_version=no lyx_prerelease=no -AC_MSG_CHECKING([for build type]) AC_ARG_ENABLE(build-type, AC_HELP_STRING([--enable-build-type=TYPE],[set build setting according to TYPE=rel(ease), pre(release), dev(elopment), prof(iling), gprof]), [case $enableval in @@ -38,6 +39,16 @@ esac AC_SUBST(lyx_devel_version) ]) +dnl If LyX is compiled from a git clone, find the HEAD commit hash +dnl +dnl +AC_DEFUN([LYX_CHECK_GIT_COMMIT], [ +AC_MSG_CHECKING([for git commit hash]) +lyxgitcommit=`cd "$srcdir" && git log -1 --pretty=format:%H 2>/dev/null || true` +test x$lyxgitcommit = x && lyxgitcommit="none" +AC_MSG_RESULT($lyxgitcommit) +]) + dnl Define the option to set a LyX version on installed executables and directories dnl diff --git a/configure.ac b/configure.ac index 7ba65bb193..8539c7cfdb 100644 --- a/configure.ac +++ b/configure.ac @@ -35,6 +35,8 @@ AM_INIT_AUTOMAKE([foreign dist-bzip2 no-define 1.8] LYX_OBJECTS_LAYOUT) m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])]) PACKAGE=$save_PACKAGE +LYX_CHECK_GIT_COMMIT + # Allow to build some parts of the code as one big chunk m4_define([ALLPARTS],[boost,client,insets,mathed,core,tex2lyx,frontend_qt]) AC_ARG_ENABLE(monolithic-build, @@ -322,6 +324,7 @@ AC_DEFINE_UNQUOTED([PROGRAM_SUFFIX], "${version_suffix}",[Program version suffix]) AC_DEFINE_UNQUOTED([LYX_DATE],"$LYX_DATE",[Date of release]) +AC_DEFINE_UNQUOTED([LYX_GIT_COMMIT_HASH], "$lyxgitcommit", [Git commit]) AC_DEFINE_UNQUOTED([VERSION_INFO],"$VERSION_INFO",[Full version info]) AC_DEFINE_UNQUOTED([LYX_DIR_VER],"$lyx_dir_ver",[Versioned env var for system dir]) AC_DEFINE_UNQUOTED([LYX_USERDIR_VER],"$lyx_userdir_ver",[Versioned env var for user dir]) diff --git a/src/LyX.cpp b/src/LyX.cpp index 050db52454..023f80dfc1 100644 --- a/src/LyX.cpp +++ b/src/LyX.cpp @@ -1089,9 +1089,11 @@ int parse_version(string const &, string const &, string &) { cout << "LyX " << lyx_version << " (" << lyx_release_date << ")" << endl; + if (string(lyx_git_commit_hash) != "none") + cout << to_utf8(_(" Git commit hash ")) + << string(lyx_git_commit_hash).substr(0,8) << endl; cout << to_utf8(bformat(_("Built on %1$s[[date]], %2$s[[time]]"), from_ascii(__DATE__), from_ascii(__TIME__))) << endl; - cout << lyx_version_info << endl; exit(0); return 0; diff --git a/src/frontends/qt4/GuiAbout.cpp b/src/frontends/qt4/GuiAbout.cpp index 09834d41f5..c75fec0180 100644 --- a/src/frontends/qt4/GuiAbout.cpp +++ b/src/frontends/qt4/GuiAbout.cpp @@ -115,7 +115,12 @@ static QString version() docstring version_date = bformat(_("LyX Version %1$s\n(%2$s)"), from_ascii(lyx_version), - qstring_to_ucs4(loc_release_date))+"\n\n"; + qstring_to_ucs4(loc_release_date))+"\n"; + if (std::string(lyx_git_commit_hash) != "none") + version_date += _("Built from git commit hash ") + + from_utf8(lyx_git_commit_hash).substr(0,8); + version_date += "\n"; + QString res; QTextStream out(&res); out << toqstr(version_date); @@ -138,6 +143,9 @@ static QString buildinfo() QTextStream out(&res); out << "LyX " << lyx_version << " (" << lyx_release_date << ")" << endl; + if (std::string(lyx_git_commit_hash) != "none") + out << qt_(" Git commit hash ") + << QString(lyx_git_commit_hash).left(8) << endl; out << toqstr(bformat(_("Built on %1$s[[date]], %2$s[[time]]"), from_ascii(__DATE__), from_ascii(__TIME__))) << endl; diff --git a/src/version.cpp b/src/version.cpp index 1e4aa32439..4d46e145e4 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -20,6 +20,8 @@ extern char const * const lyx_version = PACKAGE_VERSION; extern const int lyx_version_major = LYX_MAJOR_VERSION; extern const int lyx_version_minor = LYX_MINOR_VERSION; /// +extern char const * const lyx_git_commit_hash = LYX_GIT_COMMIT_HASH; +/// extern char const * const lyx_release_date = LYX_DATE; /// Package identifier (lyx[-]) diff --git a/src/version.h b/src/version.h index 9293e4f6b0..d952ab5204 100644 --- a/src/version.h +++ b/src/version.h @@ -20,6 +20,8 @@ extern char const * const lyx_version; extern const int lyx_version_major; extern const int lyx_version_minor; /// +extern char const * const lyx_git_commit_hash; +/// extern char const * const lyx_release_date; /// Package identifier (lyx[-])