diff --git a/AMBuildScript b/AMBuildScript index 054895ce1..00fde2ae8 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -3,16 +3,12 @@ import os, sys class SDK(object): def __init__(self, sdk, ext, aDef, name, platform, dir): - if dir == 'ep1': - folder = 'hl2sdk' - else: - folder = 'hl2sdk-' + dir + self.folder = 'hl2sdk-' + dir self.envvar = sdk self.ext = ext self.code = aDef self.define = name self.platform = platform - self.folder = folder # Default folder name. self.name = dir self.path = None # Actual path @@ -21,14 +17,14 @@ WinLinux = ['windows', 'linux'] WinLinuxMac = ['windows', 'linux', 'mac'] PossibleSDKs = { - 'ep1': SDK('HL2SDK', '1.ep1', '1', 'EPISODEONE', WinLinux, 'ep1'), - 'ep2': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'ob'), + 'episode1': SDK('HL2SDK', '1.ep1', '1', 'EPISODEONE', WinLinux, 'episode1'), + 'ep2': SDK('HL2SDKOB', '2.ep2', '3', 'ORANGEBOX', WinLinux, 'orangebox'), 'css': SDK('HL2SDKCSS', '2.css', '6', 'CSS', WinLinuxMac, 'css'), 'hl2dm': SDK('HL2SDKHL2DM', '2.hl2dm', '7', 'HL2DM', WinLinuxMac, 'hl2dm'), 'dods': SDK('HL2SDKDODS', '2.dods', '8', 'DODS', WinLinuxMac, 'dods'), 'tf2': SDK('HL2SDKTF2', '2.tf2', '10', 'TF2', WinLinuxMac, 'tf2'), 'l4d': SDK('HL2SDKL4D', '2.l4d', '11', 'LEFT4DEAD', WinLinuxMac, 'l4d'), - 'nd': SDK('HL2SDKND', '2.nd', '12', 'NUCLEARDAWN', WinLinuxMac, 'nd'), + 'nucleardawn': SDK('HL2SDKND', '2.nd', '12', 'NUCLEARDAWN', WinLinuxMac, 'nucleardawn'), 'l4d2': SDK('HL2SDKL4D2', '2.l4d2', '13', 'LEFT4DEAD2', WinLinuxMac, 'l4d2'), 'darkm': SDK('HL2SDK-DARKM', '2.darkm', '2', 'DARKMESSIAH', WinOnly, 'darkm'), 'swarm': SDK('HL2SDK-SWARM', '2.swarm', '14', 'ALIENSWARM', WinOnly, 'swarm'), @@ -314,7 +310,7 @@ class SMConfig(object): def HL2Compiler(self, context, sdk): compiler = self.ExtCompiler(context) - if sdk.name == 'ep1': + if sdk.name == 'episode1': mms_path = os.path.join(self.mms_root, 'core-legacy') else: mms_path = os.path.join(self.mms_root, 'core') @@ -334,7 +330,7 @@ class SMConfig(object): ['public', 'tier0'], ['public', 'tier1'] ] - if sdk.name == 'ep1' or sdk.name == 'darkm': + if sdk.name == 'episode1' or sdk.name == 'darkm': paths.append(['public', 'dlls']) paths.append(['game_shared']) else: @@ -345,7 +341,7 @@ class SMConfig(object): compiler.defines += ['SOURCE_ENGINE=' + sdk.code] - if sdk.name == '2013' and compiler.cxx.behavior == 'gcc': + if sdk.name == 'sdk2013' and compiler.cxx.behavior == 'gcc': # The 2013 SDK already has these in public/tier0/basetypes.h compiler.defines.remove('stricmp=strcasecmp') compiler.defines.remove('_stricmp=strcasecmp') @@ -362,7 +358,7 @@ class SMConfig(object): if sdk.name in ['blade', 'insurgency', 'csgo', 'dota']: compiler.defines += ['NETWORK_VARS_ENABLED'] - if sdk.name in ['css', 'hl2dm', 'dods', '2013', 'tf2', 'l4d', 'nd', 'l4d2']: + if sdk.name in ['css', 'hl2dm', 'dods', 'sdk2013', 'tf2', 'l4d', 'nucleardawn', 'l4d2', 'dota']: if builder.target_platform in ['linux', 'mac']: compiler.defines += ['NO_HOOK_MALLOC', 'NO_MALLOC_OVERRIDE'] @@ -379,20 +375,20 @@ class SMConfig(object): compiler = self.HL2Compiler(context, sdk) if builder.target_platform == 'linux': - if sdk.name == 'ep1': + if sdk.name == 'episode1': lib_folder = os.path.join(sdk.path, 'linux_sdk') - elif sdk.name == '2013': + elif sdk.name == 'sdk2013': lib_folder = os.path.join(sdk.path, 'lib', 'public', 'linux32') else: lib_folder = os.path.join(sdk.path, 'lib', 'linux') elif builder.target_platform == 'mac': - if sdk.name == '2013': + if sdk.name == 'sdk2013': lib_folder = os.path.join(sdk.path, 'lib', 'public', 'osx32') else: lib_folder = os.path.join(sdk.path, 'lib', 'mac') if builder.target_platform in ['linux', 'mac']: - if sdk.name == '2013': + if sdk.name == 'sdk2013': compiler.postlink += [ compiler.Dep(os.path.join(lib_folder, 'tier1.a')), compiler.Dep(os.path.join(lib_folder, 'mathlib.a')) @@ -411,7 +407,7 @@ class SMConfig(object): dynamic_libs = [] if builder.target_platform == 'linux': compiler.linkflags[0:0] = ['-lm'] - if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', '2013', 'nd', 'l4d2']: + if sdk.name in ['css', 'hl2dm', 'dods', 'tf2', 'sdk2013', 'nucleardawn', 'l4d2']: dynamic_libs = ['libtier0_srv.so', 'libvstdlib_srv.so'] elif sdk.name in ['l4d', 'blade', 'insurgency', 'csgo']: dynamic_libs = ['libtier0.so', 'libvstdlib.so'] diff --git a/core/sm_srvcmds.cpp b/core/sm_srvcmds.cpp index 7fc93666c..1661b9c51 100644 --- a/core/sm_srvcmds.cpp +++ b/core/sm_srvcmds.cpp @@ -343,7 +343,10 @@ void RootConsoleMenu::OnRootConsoleCommand(const char *cmdname, const CCommand & ConsolePrint(" SourcePawn Engine: %s (build %s)", g_pSourcePawn2->GetEngineName(), g_pSourcePawn2->GetVersionString()); ConsolePrint(" SourcePawn API: v1 = %d, v2 = %d", g_pSourcePawn->GetEngineAPIVersion(), g_pSourcePawn2->GetAPIVersion()); ConsolePrint(" Compiled on: %s %s", __DATE__, __TIME__); - ConsolePrint(" Build ID: %s", SOURCEMOD_BUILD_ID); +#if defined(SM_GENERATED_BUILD) + ConsolePrint(" Built from: https://github.com/alliedmodders/sourcemod/commit/%s", SOURCEMOD_SHA); +#endif + ConsolePrint(" Build ID: %s:%s", SOURCEMOD_LOCAL_REV, SOURCEMOD_SHA); ConsolePrint(" http://www.sourcemod.net/"); } } diff --git a/extensions/sdktools/AMBuilder b/extensions/sdktools/AMBuilder index 432919918..e4d9ff10b 100644 --- a/extensions/sdktools/AMBuilder +++ b/extensions/sdktools/AMBuilder @@ -11,7 +11,7 @@ for sdk_name in SM.sdks: os.path.join(builder.sourcePath, 'public', 'jit', 'x86'), ] - if sdk.name != 'ep1': + if sdk.name != 'episode1': binary.compiler.defines += ['HOOKING_ENABLED'] if binary.compiler.cxx.behavior == 'gcc': diff --git a/public/sourcemod_version.h b/public/sourcemod_version.h index c9ef3b0d8..095b993b7 100644 --- a/public/sourcemod_version.h +++ b/public/sourcemod_version.h @@ -49,13 +49,13 @@ # endif #else #define SM_BUILD_TAG "manual" -#define SM_BUILD_REV "0" +#define SM_BUILD_LOCAL_REV "0" #define SM_BUILD_CSET "0" #define SM_BUILD_MAJOR "1" #define SM_BUILD_MINOR "6" #define SM_BUILD_RELEASE "0" -#define SM_BUILD_UNIQUEID SM_BUILD_REV ":" SM_BUILD_CSET +#define SM_BUILD_UNIQUEID SM_BUILD_LOCAL_REV ":" SM_BUILD_CSET #define SM_VERSION_STRING SM_BUILD_MAJOR "." SM_BUILD_MINOR "." SM_BUILD_RELEASE "-" SM_BUILD_TAG #define SM_VERSION_FILE 1,6,0,0 diff --git a/tools/buildbot/Versioning b/tools/buildbot/Versioning index 68aab6de0..23557fcf6 100644 --- a/tools/buildbot/Versioning +++ b/tools/buildbot/Versioning @@ -16,11 +16,18 @@ outputs = [ os.path.join(builder.buildFolder, 'includes', 'version_auto.inc'), ] +with open(os.path.join(builder.sourcePath, '.git', 'HEAD')) as fp: + git_state = fp.read().strip().split(':')[1].strip() + +git_head_path = os.path.join(builder.sourcePath, '.git', git_state) +if not os.path.exists(git_head_path): + git_head_path = os.path.join(builder.sourcePath, '.git', 'HEAD') + sources = [ os.path.join(builder.sourcePath, 'product.version'), - # This is a hack, but we need some way to only run this script when HG changes. - os.path.join(builder.sourcePath, '.hg', 'dirstate'), + # This is a hack, but we need some way to only run this script when Git changes. + git_head_path, # The script source is a dependency, of course... argv[1] diff --git a/tools/buildbot/generate_headers.py b/tools/buildbot/generate_headers.py index 97b5b9150..08a1862cd 100644 --- a/tools/buildbot/generate_headers.py +++ b/tools/buildbot/generate_headers.py @@ -11,9 +11,19 @@ if len(argv) < 2: SourceFolder = os.path.abspath(os.path.normpath(argv[0])) OutputFolder = os.path.normpath(argv[1]) -def get_hg_version(): - argv = ['hg', 'parent', '-R', SourceFolder] +class FolderChanger: + def __init__(self, folder): + self.old = os.getcwd() + self.new = folder + def __enter__(self): + if self.new: + os.chdir(self.new) + + def __exit__(self, type, value, traceback): + os.chdir(self.old) + +def run_and_return(argv): # Python 2.6 doesn't have check_output. if hasattr(subprocess, 'check_output'): text = subprocess.check_output(argv) @@ -26,14 +36,18 @@ def get_hg_version(): if rval: raise subprocess.CalledProcessError(rval, argv) text = output.decode('utf8') + return text.strip() - m = re.match('changeset:\s+(\d+):(.+)', text) - if m == None: - raise Exception('Could not determine repository version') - return m.groups() +def get_git_version(): + revision_count = run_and_return(['git', 'rev-list', '--count', 'HEAD']) + revision_hash = run_and_return(['git', 'log', '--pretty=format:%h:%H', '-n', '1']) + shorthash, longhash = revision_hash.split(':') + + return revision_count, shorthash, longhash def output_version_headers(): - rev, cset = get_hg_version() + with FolderChanger(SourceFolder): + count, shorthash, longhash = get_git_version() with open(os.path.join(SourceFolder, 'product.version')) as fp: contents = fp.read() @@ -41,11 +55,12 @@ def output_version_headers(): if m == None: raise Exception('Could not detremine product version') major, minor, release, tag = m.groups() - fullstring = "{0}.{1}.{2}".format(major, minor, release) + product = "{0}.{1}.{2}".format(major, minor, release) + fullstring = product if tag != "": fullstring += "-{0}".format(tag) if tag == "dev": - fullstring += "+{0}".format(rev) + fullstring += "+{0}".format(shorthash) with open(os.path.join(OutputFolder, 'sourcemod_version_auto.h'), 'w') as fp: fp.write(""" @@ -53,19 +68,19 @@ def output_version_headers(): #define _SOURCEMOD_AUTO_VERSION_INFORMATION_H_ #define SM_BUILD_TAG \"{0}\" -#define SM_BUILD_REV \"{1}\" -#define SM_BUILD_CSET \"{2}\" -#define SM_BUILD_MAJOR \"{3}\" -#define SM_BUILD_MINOR \"{4}\" -#define SM_BUILD_RELEASE \"{5}\" +#define SM_BUILD_CSET \"{1}\" +#define SM_BUILD_MAJOR \"{2}\" +#define SM_BUILD_MINOR \"{3}\" +#define SM_BUILD_RELEASE \"{4}\" +#define SM_BUILD_LOCAL_REV \"{6}\" -#define SM_BUILD_UNIQUEID SM_BUILD_REV \":\" SM_BUILD_CSET +#define SM_BUILD_UNIQUEID "{6}:" SM_BUILD_CSET -#define SM_VERSION_STRING \"{6}\" -#define SM_VERSION_FILE {7},{8},{9},0 +#define SM_VERSION_STRING \"{5}\" +#define SM_VERSION_FILE {2},{3},{4},0 #endif /* _SOURCEMOD_AUTO_VERSION_INFORMATION_H_ */ - """.format(tag, rev, cset, major, minor, release, fullstring, major, minor, release)) + """.format(tag, shorthash, major, minor, release, fullstring, count)) with open(os.path.join(OutputFolder, 'version_auto.inc'), 'w') as fp: fp.write(""" @@ -75,13 +90,13 @@ def output_version_headers(): #define _auto_version_included #define SOURCEMOD_V_TAG \"{0}\" -#define SOURCEMOD_V_REV {1} -#define SOURCEMOD_V_CSET \"{2}\" -#define SOURCEMOD_V_MAJOR {3} -#define SOURCEMOD_V_MINOR {4} -#define SOURCEMOD_V_RELEASE {5} +#define SOURCEMOD_V_CSET \"{1}\" +#define SOURCEMOD_V_MAJOR {2} +#define SOURCEMOD_V_MINOR {3} +#define SOURCEMOD_V_RELEASE {4} +#define SOURCEMOD_V_REV {6} -#define SOURCEMOD_VERSION \"{6}\" - """.format(tag, rev, cset, major, minor, release, fullstring)) +#define SOURCEMOD_VERSION \"{5}\" + """.format(tag, shorthash, major, minor, release, fullstring, count)) output_version_headers() diff --git a/tools/buildbot/helpers.pm b/tools/buildbot/helpers.pm index c30bbd5cb..1e3e13ea6 100644 --- a/tools/buildbot/helpers.pm +++ b/tools/buildbot/helpers.pm @@ -9,6 +9,24 @@ our $SVN = "/usr/bin/svn"; our $SVN_USER = 'dvander'; our $SVN_ARGS = ''; +sub GitRevNum +{ + my ($path) = (@_); + my ($cd, $text, $rev); + + $cd = Cwd::cwd(); + chdir($path); + $text = `git rev-list --count HEAD`; + chdir($cd); + + chomp $text; + if ($text =~ /^(\d+)/) { + return $1; + } + + return 0; +} + sub HgRevNum { my ($path) = (@_); diff --git a/tools/buildbot/package.pl b/tools/buildbot/package.pl index 8f3d08f0f..e3e79e81f 100755 --- a/tools/buildbot/package.pl +++ b/tools/buildbot/package.pl @@ -34,7 +34,7 @@ my ($version); $version = Build::ProductVersion(Build::PathFormat('../../build/product.version')); $version =~ s/-dev//g; -$version .= '-hg' . Build::HgRevNum('../../build'); +$version .= '-git' . Build::GitRevNum('../../build'); # Append OS to package version if ($^O eq "darwin") diff --git a/tools/buildbot/symstore.pl b/tools/buildbot/symstore.pl index 264b4d308..128b14532 100755 --- a/tools/buildbot/symstore.pl +++ b/tools/buildbot/symstore.pl @@ -16,7 +16,7 @@ open(PDBLOG, '../OUTPUT/pdblog.txt') or die "Could not open pdblog.txt: $!\n"; my ($version); $version = Build::ProductVersion(Build::PathFormat('product.version')); $version =~ s/-dev//g; -$version .= '-hg' . Build::HgRevNum('.'); +$version .= '-git' . Build::GitRevNum('.'); my ($build_type); $build_type = Build::GetBuildType(Build::PathFormat('tools/buildbot/build_type')); diff --git a/versionlib/versionlib.cpp b/versionlib/versionlib.cpp index 571d33b5e..d4ee52305 100644 --- a/versionlib/versionlib.cpp +++ b/versionlib/versionlib.cpp @@ -29,6 +29,7 @@ #include #include -const char *SOURCEMOD_BUILD_ID = SM_BUILD_UNIQUEID; +const char *SOURCEMOD_LOCAL_REV = SM_BUILD_LOCAL_REV; +const char *SOURCEMOD_SHA = SM_BUILD_CSET; const char *SOURCEMOD_VERSION = SM_VERSION_STRING; const char *SOURCEMOD_BUILD_TIME = __DATE__ " " __TIME__; diff --git a/versionlib/versionlib.h b/versionlib/versionlib.h index bd2e0844b..065f3ff01 100644 --- a/versionlib/versionlib.h +++ b/versionlib/versionlib.h @@ -32,7 +32,8 @@ #if !defined(SM_USE_VERSIONLIB) // These get defined in sourcemod_version.h since // versionlib does not use versionlib. -# undef SOURCEMOD_BUILD_ID +# undef SOURCEMOD_LOCAL_REV +# undef SOURCEMOD_CSET # undef SOURCEMOD_VERSION # undef SOURCEMOD_BUILD_TIME #endif @@ -42,7 +43,8 @@ #else # define EXTERN_C extern #endif -EXTERN_C const char *SOURCEMOD_BUILD_ID; +EXTERN_C const char *SOURCEMOD_LOCAL_REV; +EXTERN_C const char *SOURCEMOD_SHA; EXTERN_C const char *SOURCEMOD_VERSION; EXTERN_C const char *SOURCEMOD_BUILD_TIME;