diff --git a/public/build.c b/public/build.c index 756fc71c..6c85bbaf 100644 --- a/public/build.c +++ b/public/build.c @@ -17,7 +17,7 @@ GNU General Public License for more details. #include "crtlib.h" #include "buildenums.h" -static const char *mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +static const char *const mon[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; static const char mond[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; int Q_buildnum_date( const char *date ) @@ -80,8 +80,13 @@ int Q_buildnum( void ) { static int b = 0; - if( !b ) - b = Q_buildnum_date( __DATE__ ); + if( b ) return b; + + if( COM_CheckString( g_buildcommit_date )) + b = Q_buildnum_iso( g_buildcommit_date ); + + if( b <= 0 ) + b = Q_buildnum_date( g_build_date ); return b; } diff --git a/public/build_vcs.c b/public/build_vcs.c index 89a55d8e..c81275e6 100644 --- a/public/build_vcs.c +++ b/public/build_vcs.c @@ -15,4 +15,5 @@ GNU General Public License for more details. const char *g_buildcommit = XASH_BUILD_COMMIT; const char *g_buildbranch = XASH_BUILD_BRANCH; - +const char *g_buildcommit_date = XASH_BUILD_COMMIT_DATE; +const char *g_build_date = __DATE__; diff --git a/public/crtlib.h b/public/crtlib.h index b19152bd..eb52ba14 100644 --- a/public/crtlib.h +++ b/public/crtlib.h @@ -65,6 +65,8 @@ const char *Q_ArchitectureStringByID( const int arch, const uint abi, const int const char *Q_buildarch( void ); extern const char *g_buildcommit; extern const char *g_buildbranch; +extern const char *g_build_date; +extern const char *g_buildcommit_date; // // crtlib.c diff --git a/public/wscript b/public/wscript index 3cfac7a9..e3cda663 100644 --- a/public/wscript +++ b/public/wscript @@ -3,6 +3,7 @@ # mittorn, 2018 from waflib import Logs, Configure +from waflib.extras import gitversion import os top = '.' @@ -60,6 +61,16 @@ def export_define(conf, define, value=1): def simple_check(conf, fragment, msg, mandatory=False, **kw): return conf.check_cc(fragment=fragment, msg='Checking for %s' % msg, mandatory=mandatory, **kw) +@Configure.conf +def get_git_commit_date(conf): + node = conf.srcnode.find_node('.git') + + if not node: + Logs.debug('can\'t find .git in conf.srcnode') + return None + + return gitversion.run_git(conf, ['log', '-1', '--format=%ci']) + def options(opt): opt.add_option('--validate-target', action='store', dest='VALIDATE_TARGET', default=None, help='development option, needs --enable-tests flag') @@ -67,6 +78,11 @@ def options(opt): def configure(conf): # private to libpublic conf.load('gitversion') + + conf.start_msg('Git commit date') + conf.env.GIT_COMMIT_DATE = conf.get_git_commit_date() + conf.end_msg(conf.env.GIT_COMMIT_DATE) + conf.env.VALIDATE_TARGET = conf.options.VALIDATE_TARGET # need to expose it for everyone using libpublic headers @@ -121,7 +137,7 @@ def build(bld): # build it separately to slightly improve rebuild times bld.stlib(source = 'build_vcs.c', target = 'build_vcs', - defines = ['XASH_BUILD_COMMIT=\"%s\"' % bld.env.GIT_VERSION, 'XASH_BUILD_BRANCH=\"%s\"' % bld.env.GIT_BRANCH]) + defines = ['XASH_BUILD_COMMIT=\"%s\"' % bld.env.GIT_VERSION, 'XASH_BUILD_BRANCH=\"%s\"' % bld.env.GIT_BRANCH, 'XASH_BUILD_COMMIT_DATE=\"%s\"' % bld.env.GIT_COMMIT_DATE]) bld.stlib(source = bld.path.ant_glob('*.c', excl='build_vcs.c'), target = 'public',