Skip to content

Commit

Permalink
Extract version info into a static library to speed up builds (bug 59…
Browse files Browse the repository at this point in the history
…90, r=ds).
  • Loading branch information
dvander committed Nov 24, 2013
1 parent 776a990 commit e936018
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 18 deletions.
7 changes: 7 additions & 0 deletions AMBuildScript
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -354,6 +357,10 @@ MMS.generated_headers = builder.RunScript(
'support/buildbot/Versioning',
{ 'MMS': MMS }
)
MMS.versionlib = builder.RunScript(
'versionlib/AMBuildScript',
{ 'MMS': MMS }
)

builder.RunBuildScripts(
[
Expand Down
9 changes: 5 additions & 4 deletions core-legacy/concommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "sh_string.h"
#include "sh_list.h"
#include "util.h"
#include <versionlib.h>

/**
* @brief Console Command Implementations
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion core-legacy/sourcemm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 0 additions & 1 deletion core-legacy/sourcemm.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "ISmmAPI.h"
#include "CPlugin.h"
#include "oslink.h"
#include <metamod_version.h>
#include "loader_bridge.h"

/**
Expand Down
12 changes: 9 additions & 3 deletions core-legacy/vsp_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
#include "concommands.h"
#include "util.h"
#include <loader_bridge.h>
#include <sh_string.h>
#include <versionlib.h>

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()
{
Expand All @@ -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;

Expand All @@ -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();
Expand Down Expand Up @@ -119,7 +125,7 @@ class VspBridge : public IVspBridge

virtual const char *GetDescription()
{
return vsp_desc;
return vsp_desc.c_str();
}
};

Expand Down
5 changes: 3 additions & 2 deletions core/metamod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "metamod.h"
#include <interface.h>
#include <eiface.h>
#include <versionlib.h>
#include "metamod_provider.h"
#include "metamod_plugins.h"
#include "metamod_util.h"
Expand Down Expand Up @@ -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);

Expand Down
1 change: 0 additions & 1 deletion core/metamod.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include <sourcehook/sourcehook.h>
#include <ISmmPlugin.h>
#include "metamod_provider.h"
#include <metamod_version.h>

using namespace SourceMM;

Expand Down
7 changes: 4 additions & 3 deletions core/metamod_console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <stdio.h>
#include "metamod_oslink.h"
#include <ctype.h>
#include <versionlib.h>
#include "metamod.h"
#include "metamod_util.h"
#include "metamod_console.h"
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -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());
Expand Down
13 changes: 10 additions & 3 deletions core/vsp_bridge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <iplayerinfo.h>
#include <assert.h>
#include <loader_bridge.h>
#include <versionlib.h>
#include <sh_string.h>
#include "provider/provider_ep2.h"

#if SOURCE_ENGINE == SE_DOTA
Expand All @@ -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)
Expand Down Expand Up @@ -73,6 +75,9 @@ class VspBridge : public IVspBridge
{
if (!g_Metamod.IsLoadedAsGameDLL())
{
vsp_desc.append(" ");
vsp_desc.append(METAMOD_VERSION);

CGlobalVars *pGlobals;
IPlayerInfoManager *playerInfoManager;

Expand Down Expand Up @@ -126,7 +131,9 @@ class VspBridge : public IVspBridge
}
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);
}

Expand Down Expand Up @@ -175,7 +182,7 @@ class VspBridge : public IVspBridge

virtual const char *GetDescription()
{
return vsp_desc;
return vsp_desc.c_str();
}
};

Expand Down
11 changes: 11 additions & 0 deletions versionlib/AMBuildScript
Original file line number Diff line number Diff line change
@@ -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

31 changes: 31 additions & 0 deletions versionlib/versionlib.cpp
Original file line number Diff line number Diff line change
@@ -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 <metamod_version.h>
#include <versionlib.h>

const char *METAMOD_BUILD_ID = MMS_BUILD_UNIQUEID;
const char *METAMOD_VERSION = MMS_FULL_VERSION;

31 changes: 31 additions & 0 deletions versionlib/versionlib.h
Original file line number Diff line number Diff line change
@@ -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_

0 comments on commit e936018

Please sign in to comment.