From f9d3b05fdb5663baa043cb9e640248b190ef5e80 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Sat, 23 Nov 2013 19:10:27 -0800 Subject: [PATCH] Extract version info into a static library to speed up builds (bug 5990, r=ds). --- AMBuildScript | 7 +++++++ core-legacy/concommands.cpp | 9 +++++---- core-legacy/sourcemm.cpp | 2 +- core-legacy/sourcemm.h | 1 - core-legacy/vsp_bridge.cpp | 12 +++++++++--- core/metamod.cpp | 5 +++-- core/metamod.h | 1 - core/metamod_console.cpp | 7 ++++--- core/vsp_bridge.cpp | 13 ++++++++++--- versionlib/AMBuildScript | 11 +++++++++++ versionlib/versionlib.cpp | 31 +++++++++++++++++++++++++++++++ versionlib/versionlib.h | 31 +++++++++++++++++++++++++++++++ 12 files changed, 112 insertions(+), 18 deletions(-) create mode 100644 versionlib/AMBuildScript create mode 100644 versionlib/versionlib.cpp create mode 100644 versionlib/versionlib.h diff --git a/AMBuildScript b/AMBuildScript index 697356a..2603588 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -63,6 +63,7 @@ class MMSConfig(object): self.sdks = {} self.binaries = [] self.generated_headers = None + self.versionlib = None def detectProductVersion(self): builder.AddConfigureFile('product.version') @@ -214,6 +215,7 @@ class MMSConfig(object): # Finish up. cfg.defines += ['MMS_GENERATED_BUILD'] cfg.includes += [os.path.join(builder.buildPath, 'includes')] + cfg.includes += [os.path.join(builder.sourcePath, 'versionlib')] cfg.cxxincludes += [os.path.join(builder.sourcePath, 'public')] def HL2Compiler(self, context, sdk): @@ -276,6 +278,7 @@ class MMSConfig(object): '-compatibility_version', '1.0.0', '-current_version', self.productVersion ] + binary.compiler.linkflags += [self.versionlib] binary.compiler.sourcedeps += MMS.generated_headers return binary @@ -354,6 +357,10 @@ MMS.generated_headers = builder.RunScript( 'support/buildbot/Versioning', { 'MMS': MMS } ) +MMS.versionlib = builder.RunScript( + 'versionlib/AMBuildScript', + { 'MMS': MMS } +) builder.RunBuildScripts( [ diff --git a/core-legacy/concommands.cpp b/core-legacy/concommands.cpp index 6cd57fb..370610b 100644 --- a/core-legacy/concommands.cpp +++ b/core-legacy/concommands.cpp @@ -16,6 +16,7 @@ #include "sh_string.h" #include "sh_list.h" #include "util.h" +#include /** * @brief Console Command Implementations @@ -105,7 +106,7 @@ void SMConVarAccessor::Unregister(ConCommandBase *pCommand) } } -ConVar metamod_version("metamod_version", MMS_FULL_VERSION, FCVAR_SPONLY | FCVAR_NOTIFY, "Metamod:Source Version"); +ConVar metamod_version("metamod_version", METAMOD_VERSION, FCVAR_SPONLY | FCVAR_NOTIFY, "Metamod:Source Version"); #ifdef OS_WIN32 ConVar mm_pluginsfile("mm_pluginsfile", "addons\\metamod\\metaplugins.ini", FCVAR_SPONLY, "Metamod:Source Plugins File"); ConVar mm_basedir("mm_basedir", "addons\\metamod", FCVAR_SPONLY, "Metamod:Source base folder"); @@ -140,8 +141,8 @@ CON_COMMAND(meta, "Metamod:Source Menu") return; } else if (strcmp(command, "version") == 0) { - CONMSG("Metamod:Source version %s\n", MMS_FULL_VERSION); - CONMSG("Build ID: %s\n", MMS_BUILD_UNIQUEID); + CONMSG("Metamod:Source version %s\n", METAMOD_VERSION); + CONMSG("Build ID: %s\n", METAMOD_BUILD_ID); if (g_GameDll.loaded) { CONMSG("Loaded As: GameDLL (gameinfo.txt)\n"); @@ -644,7 +645,7 @@ void ClientCommand_handler(edict_t *client) RETURN_META(MRES_SUPERCEDE); } else if(strcmp(subcmd, "version") == 0) { - CLIENT_CONMSG(client, "Metamod:Source version %s\n", MMS_FULL_VERSION); + CLIENT_CONMSG(client, "Metamod:Source version %s\n", METAMOD_VERSION); CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE); CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", PLAPI_VERSION, PLAPI_MIN_VERSION); CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SourceHook.GetIfaceVersion(), g_SourceHook.GetImplVersion()); diff --git a/core-legacy/sourcemm.cpp b/core-legacy/sourcemm.cpp index 5e359ea..c3d4d7c 100644 --- a/core-legacy/sourcemm.cpp +++ b/core-legacy/sourcemm.cpp @@ -475,7 +475,7 @@ int LoadPluginsFromFile(const char *filepath, int &skipped) } char buffer[255], error[255], full_path[PATH_SIZE]; - const char *ptr, *ext, *file; + const char *file; size_t length; while (!feof(fp) && fgets(buffer, sizeof(buffer), fp) != NULL) { diff --git a/core-legacy/sourcemm.h b/core-legacy/sourcemm.h index 075cf22..3f587df 100644 --- a/core-legacy/sourcemm.h +++ b/core-legacy/sourcemm.h @@ -23,7 +23,6 @@ #include "ISmmAPI.h" #include "CPlugin.h" #include "oslink.h" -#include #include "loader_bridge.h" /** diff --git a/core-legacy/vsp_bridge.cpp b/core-legacy/vsp_bridge.cpp index 4b61b98..83973af 100644 --- a/core-legacy/vsp_bridge.cpp +++ b/core-legacy/vsp_bridge.cpp @@ -28,13 +28,15 @@ #include "concommands.h" #include "util.h" #include +#include +#include SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); ConCommand *g_plugin_unload = NULL; bool g_bIsTryingToUnload; bool g_bIsBridgedAsVsp; -const char *vsp_desc = "Metamod:Source " MMS_FULL_VERSION; +SourceHook::String vsp_desc("Metamod:Source"); void InterceptPluginUnloads() { @@ -54,6 +56,9 @@ class VspBridge : public IVspBridge if (!g_GameDll.loaded) { + vsp_desc.append(" "); + vsp_desc.append(METAMOD_VERSION); + CreateInterfaceFn engineFactory = (CreateInterfaceFn)info->engineFactory; CreateInterfaceFn gsFactory = (CreateInterfaceFn)info->gsFactory; @@ -68,7 +73,8 @@ class VspBridge : public IVspBridge } else { - vsp_desc = "Metamod:Source Interface " MMS_FULL_VERSION; + vsp_desc.append(" Interface "); + vsp_desc.append(METAMOD_VERSION); } ConCommandBase *pBase = g_Engine.icvar->GetCommands(); @@ -119,7 +125,7 @@ class VspBridge : public IVspBridge virtual const char *GetDescription() { - return vsp_desc; + return vsp_desc.c_str(); } }; diff --git a/core/metamod.cpp b/core/metamod.cpp index 171eb46..40c4e7c 100644 --- a/core/metamod.cpp +++ b/core/metamod.cpp @@ -28,6 +28,7 @@ #include "metamod.h" #include #include +#include #include "metamod_provider.h" #include "metamod_plugins.h" #include "metamod_util.h" @@ -430,11 +431,11 @@ mm_StartupMetamod(bool is_vsp_load) UTIL_Format(buffer, sizeof(buffer), "%s%s", - MMS_FULL_VERSION, + METAMOD_VERSION, is_vsp_load ? "V" : ""); metamod_version = provider->CreateConVar("metamod_version", - MMS_FULL_VERSION, + METAMOD_VERSION, "Metamod:Source Version", ConVarFlag_Notify|ConVarFlag_SpOnly); diff --git a/core/metamod.h b/core/metamod.h index f438008..07a2b38 100644 --- a/core/metamod.h +++ b/core/metamod.h @@ -38,7 +38,6 @@ #include #include #include "metamod_provider.h" -#include using namespace SourceMM; diff --git a/core/metamod_console.cpp b/core/metamod_console.cpp index 0717a50..b52b96b 100644 --- a/core/metamod_console.cpp +++ b/core/metamod_console.cpp @@ -26,6 +26,7 @@ #include #include "metamod_oslink.h" #include +#include #include "metamod.h" #include "metamod_util.h" #include "metamod_console.h" @@ -68,8 +69,8 @@ bool Command_Meta(IMetamodSourceCommandInfo *info) } else if (strcmp(command, "version") == 0) { - CONMSG("Metamod:Source version %s\n", MMS_FULL_VERSION); - CONMSG("Build ID: %s\n", MMS_BUILD_UNIQUEID); + CONMSG("Metamod:Source version %s\n", METAMOD_VERSION); + CONMSG("Build ID: %s\n", METAMOD_BUILD_ID); if (g_Metamod.IsLoadedAsGameDLL()) { @@ -699,7 +700,7 @@ bool Command_ClientMeta(edict_t *client, IMetamodSourceCommandInfo *info) } else if(strcmp(subcmd, "version") == 0) { - CLIENT_CONMSG(client, "Metamod:Source version %s\n", MMS_FULL_VERSION); + CLIENT_CONMSG(client, "Metamod:Source version %s\n", METAMOD_VERSION); CLIENT_CONMSG(client, "Compiled on: %s\n", SOURCEMM_DATE); CLIENT_CONMSG(client, "Plugin interface version: %d:%d\n", METAMOD_PLAPI_VERSION, PLAPI_MIN_VERSION); CLIENT_CONMSG(client, "SourceHook version: %d:%d\n", g_SHPtr->GetIfaceVersion(), g_SHPtr->GetImplVersion()); diff --git a/core/vsp_bridge.cpp b/core/vsp_bridge.cpp index 8f0b38b..11022db 100644 --- a/core/vsp_bridge.cpp +++ b/core/vsp_bridge.cpp @@ -30,6 +30,8 @@ #include #include #include +#include +#include #include "provider/provider_ep2.h" #if SOURCE_ENGINE == SE_DOTA @@ -42,7 +44,7 @@ SH_DECL_HOOK0_void(ConCommand, Dispatch, SH_NOATTRIB, false); ConCommand *g_plugin_unload = NULL; bool g_bIsTryingToUnload; -const char *vsp_desc = "Metamod:Source " MMS_FULL_VERSION; +SourceHook::String vsp_desc("Metamod:Source"); #if SOURCE_ENGINE == SE_DOTA void InterceptPluginUnloads(const CCommandContext &context, const CCommand &args) @@ -73,6 +75,9 @@ public: { if (!g_Metamod.IsLoadedAsGameDLL()) { + vsp_desc.append(" "); + vsp_desc.append(METAMOD_VERSION); + CGlobalVars *pGlobals; IPlayerInfoManager *playerInfoManager; @@ -126,7 +131,9 @@ public: } else { - vsp_desc = "Metamod:Source Interface " MMS_FULL_VERSION; + vsp_desc.append(" Interface "); + vsp_desc.append(METAMOD_VERSION); + g_Metamod.NotifyVSPListening(info->vsp_callbacks, info->vsp_version); } @@ -175,7 +182,7 @@ public: virtual const char *GetDescription() { - return vsp_desc; + return vsp_desc.c_str(); } }; diff --git a/versionlib/AMBuildScript b/versionlib/AMBuildScript new file mode 100644 index 0000000..ed728f6 --- /dev/null +++ b/versionlib/AMBuildScript @@ -0,0 +1,11 @@ +# vim: sts=2 ts=8 sw=2 tw=99 et ft=python: + +lib = builder.compiler.StaticLibrary("version") +lib.compiler.sourcedeps += MMS.generated_headers +lib.sources += [ + 'versionlib.cpp' +] +cmd = builder.Add(lib) + +rvalue = cmd.binary + diff --git a/versionlib/versionlib.cpp b/versionlib/versionlib.cpp new file mode 100644 index 0000000..e4f3b57 --- /dev/null +++ b/versionlib/versionlib.cpp @@ -0,0 +1,31 @@ +/** + * vim: set ts=4 sw=4 tw=99 noet : + * ====================================================== + * Metamod:Source + * Copyright (C) 2004-2010 AlliedModders LLC and authors. + * All rights reserved. + * ====================================================== + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in a + * product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ + +#include +#include + +const char *METAMOD_BUILD_ID = MMS_BUILD_UNIQUEID; +const char *METAMOD_VERSION = MMS_FULL_VERSION; + diff --git a/versionlib/versionlib.h b/versionlib/versionlib.h new file mode 100644 index 0000000..0044416 --- /dev/null +++ b/versionlib/versionlib.h @@ -0,0 +1,31 @@ +/** + * vim: set ts=4 sw=4 tw=99 noet : + * ====================================================== + * Metamod:Source + * Copyright (C) 2004-2010 AlliedModders LLC and authors. + * All rights reserved. + * ====================================================== + * + * This software is provided 'as-is', without any express or implied warranty. + * In no event will the authors be held liable for any damages arising from + * the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you must not + * claim that you wrote the original software. If you use this software in a + * product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions must be plainly marked as such, and must not be + * misrepresented as being the original software. + * 3. This notice may not be removed or altered from any source distribution. + */ +#ifndef _INCLUDE_METAMOD_VERSIONLIB_H_ +#define _INCLUDE_METAMOD_VERSIONLIB_H_ + +extern "C" const char *METAMOD_BUILD_ID; +extern "C" const char *METAMOD_VERSION; + +#endif // _INCLUDE_METAMOD_VERSIONLIB_H_