From f3b77c1b5e1e3734a5779a2447a69b86ec4a0b65 Mon Sep 17 00:00:00 2001 From: Reuben Morais Date: Wed, 21 Mar 2012 06:55:46 -0500 Subject: [PATCH] Changed build system so that it no longer requires all SDKs to be available (bug 5101, r=ds). --- AMBuildScript | 66 ++++++++++++++++++++++++++++--------------- core-legacy/AMBuilder | 50 ++++++++++++++++---------------- 2 files changed, 70 insertions(+), 46 deletions(-) diff --git a/AMBuildScript b/AMBuildScript index 0f6546d..c828cf6 100644 --- a/AMBuildScript +++ b/AMBuildScript @@ -8,26 +8,28 @@ class MMS: self.compiler = Cpp.Compiler() #Build SDK info + self.possibleSdks = { } + self.possibleSdks['ep1'] = {'sdk': 'HL2SDK', 'ext': '1.ep1', 'def': '1', + 'name': 'EPISODEONE', 'platform': ['windows', 'linux']} + self.possibleSdks['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '2.ep2', 'def': '3', + 'name': 'ORANGEBOX', 'platform': ['windows', 'linux']} + self.possibleSdks['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '6', + 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']} + self.possibleSdks['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '7', + 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin']} + self.possibleSdks['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '8', + 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin']} + self.possibleSdks['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2', + 'name': 'DARKMESSIAH', 'platform': ['windows']} + self.possibleSdks['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '9', + 'name': 'ALIENSWARM', 'platform': ['windows']} + self.possibleSdks['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4', + 'name': 'BLOODYGOODTIME', 'platform': ['windows']} + self.possibleSdks['eye'] = {'sdk': 'HL2SDK-EYE', 'ext': '2.eye', 'def': '5', + 'name': 'EYE', 'platform': ['windows']} + self.sdkInfo = { } - self.sdkInfo['ep1'] = {'sdk': 'HL2SDK', 'ext': '1.ep1', 'def': '1', - 'name': 'EPISODEONE', 'platform': ['windows', 'linux']} - self.sdkInfo['ep2'] = {'sdk': 'HL2SDKOB', 'ext': '2.ep2', 'def': '3', - 'name': 'ORANGEBOX', 'platform': ['windows', 'linux']} - self.sdkInfo['ep2v'] = {'sdk': 'HL2SDKOBVALVE', 'ext': '2.ep2v', 'def': '6', - 'name': 'ORANGEBOXVALVE', 'platform': ['windows', 'linux', 'darwin']} - self.sdkInfo['l4d'] = {'sdk': 'HL2SDKL4D', 'ext': '2.l4d', 'def': '7', - 'name': 'LEFT4DEAD', 'platform': ['windows', 'linux', 'darwin']} - self.sdkInfo['l4d2'] = {'sdk': 'HL2SDKL4D2', 'ext': '2.l4d2', 'def': '8', - 'name': 'LEFT4DEAD2', 'platform': ['windows', 'linux', 'darwin']} - self.sdkInfo['darkm'] = {'sdk': 'HL2SDK-DARKM', 'ext': '2.darkm', 'def': '2', - 'name': 'DARKMESSIAH', 'platform': ['windows']} - self.sdkInfo['swarm'] = {'sdk': 'HL2SDK-SWARM', 'ext': '2.swarm', 'def': '9', - 'name': 'ALIENSWARM', 'platform': ['windows']} - self.sdkInfo['bgt'] = {'sdk': 'HL2SDK-BGT', 'ext': '2.bgt', 'def': '4', - 'name': 'BLOODYGOODTIME', 'platform': ['windows']} - self.sdkInfo['eye'] = {'sdk': 'HL2SDK-EYE', 'ext': '2.eye', 'def': '5', - 'name': 'EYE', 'platform': ['windows']} - + if AMBuild.mode == 'config': #Detect compilers self.compiler.DetectAll(AMBuild) @@ -49,12 +51,22 @@ class MMS: envvars['HL2SDK-BGT'] = 'hl2sdk-bgt' envvars['HL2SDK-EYE'] = 'hl2sdk-eye' - #Must have a path for each envvar (file a bug if you don't like this) + # Finds if a dict with `key` set to `value` is present on the dict of dicts `dictionary` + def findDictByKey(dictionary, key, value): + for index in dictionary: + elem = dictionary[index] + if elem[key] == value: + return (elem, index) + return None + for i in envvars: if i in os.environ: path = os.environ[i] if not os.path.isdir(path): raise Exception('Path for {0} was not found: {1}'.format(i, path)) + elif i.startswith('HL2SDK'): + (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i) + self.sdkInfo[sdk] = info else: head = os.getcwd() oldhead = None @@ -64,9 +76,18 @@ class MMS: break oldhead = head head, tail = os.path.split(head) - if head == None or head == oldhead: + if i.startswith('HL2SDK'): + if head != None and head != oldhead: + (info, sdk) = findDictByKey(self.possibleSdks, 'sdk', i) + self.sdkInfo[sdk] = info + elif head == None or head == oldhead: raise Exception('Could not find a valid path for {0}'.format(i)) AMBuild.cache.CacheVariable(i, path) + + if len(self.sdkInfo) < 1: + raise Exception('At least one SDK must be available.') + + AMBuild.cache.CacheVariable('sdkInfo', self.sdkInfo) #Set up defines cxx = self.compiler.cxx @@ -189,6 +210,7 @@ class MMS: self.targetMap = { } AMBuild.cache.CacheVariable('targetMap', self.targetMap) else: + self.sdkInfo = AMBuild.cache['sdkInfo'] self.compiler.FromConfig(AMBuild, 'compiler') self.targetMap = AMBuild.cache['targetMap'] @@ -277,7 +299,7 @@ class MMS: compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, path, 'sourcehook')) compiler['CXXINCLUDES'].append(os.path.join(AMBuild.sourceFolder, 'loader')) - info = self.sdkInfo + info = self.possibleSdks compiler['CDEFINES'].extend(['SE_' + info[i]['name'] + '=' + info[i]['def'] for i in info]) paths = [['public'], ['public', 'engine'], ['public', 'mathlib'], ['public', 'vstdlib'], diff --git a/core-legacy/AMBuilder b/core-legacy/AMBuilder index 46121f9..2e632a0 100644 --- a/core-legacy/AMBuilder +++ b/core-legacy/AMBuilder @@ -1,29 +1,31 @@ # vim: set ts=2 sw=2 tw=99 noet ft=python: import os -sdk = MMS.sdkInfo['ep1'] +try: + sdk = MMS.sdkInfo['ep1'] + + if AMBuild.target['platform'] in sdk['platform']: + compiler = MMS.DefaultHL2Compiler('core-legacy', 'ep1') -if AMBuild.target['platform'] in sdk['platform']: - compiler = MMS.DefaultHL2Compiler('core-legacy', 'ep1') - - name = 'metamod.' + sdk['ext'] - - extension = AMBuild.AddJob(name) - binary = Cpp.LibraryBuilder(name, AMBuild, extension, compiler) - MMS.PreSetupHL2Job(extension, binary, 'ep1') - files = [ - 'sourcemm.cpp', - 'concommands.cpp', - 'oslink.cpp', - 'util.cpp', - 'CSmmAPI.cpp', - 'CPlugin.cpp', - 'gamedll_bridge.cpp', - 'vsp_bridge.cpp', - 'sourcehook/sourcehook.cpp' - ] - binary.AddSourceFiles('core-legacy', files) - MMS.PostSetupHL2Job(extension, binary, 'ep1') - MMS.AutoVersion('core-legacy', binary) - binary.SendToJob() + name = 'metamod.' + sdk['ext'] + extension = AMBuild.AddJob(name) + binary = Cpp.LibraryBuilder(name, AMBuild, extension, compiler) + MMS.PreSetupHL2Job(extension, binary, 'ep1') + files = [ + 'sourcemm.cpp', + 'concommands.cpp', + 'oslink.cpp', + 'util.cpp', + 'CSmmAPI.cpp', + 'CPlugin.cpp', + 'gamedll_bridge.cpp', + 'vsp_bridge.cpp', + 'sourcehook/sourcehook.cpp' + ] + binary.AddSourceFiles('core-legacy', files) + MMS.PostSetupHL2Job(extension, binary, 'ep1') + MMS.AutoVersion('core-legacy', binary) + binary.SendToJob() +except KeyError: + pass