tools/buildbot/PackageScript
author Asher Baker <asherkin@gmail.com>
Tue Dec 25 21:44:58 2012 +0000 (2012-12-25)
changeset 3725 27fdbcf87348
parent 3652 e0a6517dcd89
child 3767 7223d0a452a8
permissions -rw-r--r--
Fixed PackageScript to not try and include extra extensions.
     1 # vim: set ts=2 sw=2 tw=99 noet ft=python: 
     2 import os
     3 import shutil
     4 import ambuild.osutil as osutil
     5 from ambuild.command import Command
     6 
     7 job = AMBuild.AddJob('package')
     8 
     9 class DestroyPath(Command):
    10 	def __init__(self, folder):
    11 		Command.__init__(self)
    12 		self.folder = folder
    13 
    14 	def destroy(self, path):
    15 		entries = os.listdir(path)
    16 		for entry in entries:
    17 			newpath = os.path.join(path, entry)
    18 			if os.path.isdir(newpath):
    19 				self.destroy(newpath)
    20 				os.rmdir(newpath)
    21 			elif os.path.isfile(newpath):
    22 				os.remove(newpath)
    23 
    24 	def run(self, runner, job):
    25 		runner.PrintOut('rm -rf {0}/*'.format(self.folder))
    26 		self.destroy(self.folder)
    27 
    28 class CreateFolders(Command):
    29 	def __init__(self, folders):
    30 		Command.__init__(self)
    31 		self.folders = folders
    32 	
    33 	def run(self, runner, job):
    34 		for folder in self.folders:
    35 			path = os.path.join(*folder)
    36 			runner.PrintOut('mkdir {0}'.format(path))
    37 			os.makedirs(path)
    38 
    39 #Shallow folder copy
    40 class CopyFolder(Command):
    41 	def __init__(self, fromList, toList, excludes = []):
    42 		Command.__init__(self)
    43 		self.fromPath = os.path.join(AMBuild.sourceFolder, *fromList)
    44 		self.toPath = os.path.join(*toList) 
    45 		self.excludes = excludes
    46 	
    47 	def run(self, runner, job):
    48 		entries = os.listdir(self.fromPath)
    49 		for entry in entries:
    50 			if entry in self.excludes:
    51 				continue
    52 			path = os.path.join(self.fromPath, entry)
    53 			if not os.path.isfile(path):
    54 				continue
    55 			runner.PrintOut('copy {0} to {1}'.format(path, self.toPath))
    56 			shutil.copy(path, self.toPath)
    57 
    58 #Single file copy
    59 class CopyFile(Command):
    60 	def __init__(self, fromFile, toPath):
    61 		Command.__init__(self)
    62 		self.fromFile = fromFile
    63 		self.toPath = toPath
    64 
    65 	def run(self, runner, job):
    66 		runner.PrintOut('copy {0} to {1}'.format(self.fromFile, self.toPath))
    67 		shutil.copy(self.fromFile, self.toPath)
    68 
    69 
    70 folders = [['addons', 'sourcemod', 'bin'],
    71            ['addons', 'sourcemod', 'plugins', 'disabled'],
    72            ['addons', 'sourcemod', 'gamedata'],
    73            ['addons', 'sourcemod', 'gamedata', 'core.games'],
    74            ['addons', 'sourcemod', 'gamedata', 'sdktools.games'],
    75 		   ['addons', 'sourcemod', 'gamedata', 'sm-cstrike.games'],
    76            ['addons', 'sourcemod', 'configs', 'geoip'],
    77            ['addons', 'sourcemod', 'translations'],
    78            ['addons', 'sourcemod', 'logs'],
    79            ['addons', 'sourcemod', 'extensions'],
    80            ['addons', 'sourcemod', 'data'],
    81            ['addons', 'sourcemod', 'scripting', 'include'],
    82            ['addons', 'sourcemod', 'scripting', 'admin-flatfile'],
    83            ['addons', 'sourcemod', 'scripting', 'adminmenu'],
    84            ['addons', 'sourcemod', 'scripting', 'testsuite'],
    85            ['cfg', 'sourcemod'],
    86            ['addons', 'sourcemod', 'configs', 'sql-init-scripts'],
    87            ['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'mysql'],
    88            ['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'sqlite'],
    89            ['addons', 'sourcemod', 'scripting', 'basecommands'],
    90            ['addons', 'sourcemod', 'scripting', 'basecomm'],
    91            ['addons', 'sourcemod', 'scripting', 'funvotes'],
    92            ['addons', 'sourcemod', 'scripting', 'basevotes'],
    93            ['addons', 'sourcemod', 'scripting', 'basebans'],
    94            ['addons', 'sourcemod', 'scripting', 'funcommands'],
    95            ['addons', 'sourcemod', 'scripting', 'playercommands'],
    96            ['addons', 'metamod'],
    97           ]
    98 
    99 #Setup
   100 job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
   101 job.AddCommand(CreateFolders(folders))
   102 
   103 #Copy Folders
   104 job.AddCommand(CopyFolder(['configs'], ['addons', 'sourcemod', 'configs']))
   105 job.AddCommand(CopyFolder(['configs', 'geoip'], ['addons', 'sourcemod', 'configs', 'geoip']))
   106 job.AddCommand(CopyFolder(['configs', 'cfg'], ['cfg', 'sourcemod']))
   107 job.AddCommand(CopyFolder(['configs', 'metamod'], ['addons', 'metamod']))
   108 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts'],
   109 	['addons', 'sourcemod', 'configs', 'sql-init-scripts']))
   110 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts', 'mysql'],
   111 	['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'mysql']))
   112 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts', 'sqlite'],
   113 	['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'sqlite']))
   114 job.AddCommand(CopyFolder(['gamedata'], ['addons', 'sourcemod', 'gamedata']))
   115 job.AddCommand(CopyFolder(['gamedata', 'sdktools.games'],
   116 	['addons', 'sourcemod', 'gamedata', 'sdktools.games']))
   117 job.AddCommand(CopyFolder(['gamedata', 'core.games'],
   118 	['addons', 'sourcemod', 'gamedata', 'core.games']))
   119 job.AddCommand(CopyFolder(['gamedata', 'sm-cstrike.games'],
   120 	['addons', 'sourcemod', 'gamedata', 'sm-cstrike.games']))
   121 job.AddCommand(CopyFolder(['plugins'], ['addons', 'sourcemod', 'scripting'], ['AMBuilder']))
   122 job.AddCommand(CopyFolder(['plugins', 'include'],
   123 	['addons', 'sourcemod', 'scripting', 'include']))
   124 job.AddCommand(CopyFolder(['translations'], ['addons', 'sourcemod', 'translations']))
   125 job.AddCommand(CopyFolder(['public', 'licenses'], ['addons', 'sourcemod']))
   126 job.AddCommand(CopyFolder(['plugins', 'admin-flatfile'],
   127 	['addons', 'sourcemod', 'scripting', 'admin-flatfile']))
   128 job.AddCommand(CopyFolder(['plugins', 'adminmenu'],
   129 	['addons', 'sourcemod', 'scripting', 'adminmenu']))
   130 job.AddCommand(CopyFolder(['plugins', 'testsuite'],
   131 	['addons', 'sourcemod', 'scripting', 'testsuite']))
   132 job.AddCommand(CopyFolder(['plugins', 'basecommands'],
   133 	['addons', 'sourcemod', 'scripting', 'basecommands']))
   134 job.AddCommand(CopyFolder(['plugins', 'basecomm'],
   135 	['addons', 'sourcemod', 'scripting', 'basecomm']))
   136 job.AddCommand(CopyFolder(['plugins', 'funvotes'],
   137 	['addons', 'sourcemod', 'scripting', 'funvotes']))
   138 job.AddCommand(CopyFolder(['plugins', 'basevotes'],
   139 	['addons', 'sourcemod', 'scripting', 'basevotes']))
   140 job.AddCommand(CopyFolder(['plugins', 'basebans'],
   141 	['addons', 'sourcemod', 'scripting', 'basebans']))
   142 job.AddCommand(CopyFolder(['plugins', 'funcommands'],
   143 	['addons', 'sourcemod', 'scripting', 'funcommands']))
   144 job.AddCommand(CopyFolder(['plugins', 'playercommands'],
   145 	['addons', 'sourcemod', 'scripting', 'playercommands']))
   146 
   147 defPlugins = [
   148 	'admin-flatfile',
   149 	'adminhelp',
   150 	'antiflood',
   151 	'basecommands',
   152 	'reservedslots',
   153 	'basetriggers',
   154 	'nextmap',
   155 	'basechat',
   156 	'funcommands',
   157 	'basevotes',
   158 	'funvotes',
   159 	'basebans',
   160 	'basecomm',
   161 	'adminmenu',
   162 	'playercommands',
   163 	'clientprefs',
   164 	'sounds'
   165 ]
   166 
   167 disPlugins = [
   168 	'admin-sql-prefetch',
   169 	'admin-sql-threaded',
   170 	'sql-admin-manager',
   171 	'mapchooser',
   172 	'randomcycle',
   173 	'rockthevote',
   174 	'nominations'
   175 ]
   176 
   177 commands = []
   178 for plugin in defPlugins:
   179 	commands.append(CopyFile(os.path.join('..', 'plugins', plugin + '.smx'),
   180 	                         os.path.join('addons', 'sourcemod', 'plugins')))
   181 
   182 for plugin in disPlugins:
   183 	commands.append(CopyFile(os.path.join('..', 'plugins', plugin + '.smx'),
   184 	                         os.path.join('addons', 'sourcemod', 'plugins', 'disabled')))
   185 job.AddCommandGroup(commands)
   186 
   187 job.AddCommand(CopyFile(os.path.join('..', 'includes', 'version_auto.inc'),
   188 	os.path.join('addons', 'sourcemod', 'scripting', 'include')))
   189 
   190 bincopies = []
   191 
   192 def AddNormalLibrary(name, dest):
   193 	dest = os.path.join('addons', 'sourcemod', dest)
   194 	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
   195 	
   196 	# Each platform's version of dump_syms needs the path in a different format.
   197 	if AMBuild.target['platform'] == 'linux':
   198 		debug_info.append(name + '/' + name + '.so')
   199 	elif AMBuild.target['platform'] == 'darwin':
   200 		debug_info.append(name + '/' + name + '.dylib.dSYM')
   201 	elif AMBuild.target['platform'] == 'windows':
   202 		debug_info.append(name + '\\' + name + '.pdb')
   203 
   204 def AddHL2Library(name, dest):
   205 	for i in SM.sdkInfo:
   206 		sdk = SM.sdkInfo[i]
   207 		if AMBuild.target['platform'] not in sdk['platform']:
   208 			continue
   209 		AddNormalLibrary(name + '.' + sdk['ext'], dest)
   210 
   211 debug_info = []
   212 
   213 if AMBuild.target['platform'] == 'linux':
   214 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm_i486.so'),
   215 	                 os.path.join('addons', 'sourcemod', 'bin')))
   216 	debug_info.append('loader/sourcemod_mm_i486.so')
   217 elif AMBuild.target['platform'] == 'darwin':
   218 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dylib'),
   219 	                 os.path.join('addons', 'sourcemod', 'bin')))
   220 	debug_info.append('loader/sourcemod_mm.dylib.dSYM')
   221 elif AMBuild.target['platform'] == 'windows':
   222 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dll'),
   223 	                 os.path.join('addons', 'sourcemod', 'bin')))
   224 	debug_info.append('loader\\sourcemod_mm.pdb')
   225 
   226 AddHL2Library('sourcemod', 'bin')
   227 AddNormalLibrary('sourcemod.logic', 'bin')
   228 AddNormalLibrary('sourcepawn.jit.x86', 'bin')
   229 AddNormalLibrary('geoip.ext', 'extensions')
   230 AddNormalLibrary('dbi.mysql.ext', 'extensions')
   231 AddNormalLibrary('dbi.sqlite.ext', 'extensions')
   232 
   233 if 'css' in SM.sdkInfo:
   234 	AddNormalLibrary('game.cstrike.ext.2.css', 'extensions')
   235 
   236 if 'csgo' in SM.sdkInfo:
   237 	AddNormalLibrary('game.cstrike.ext.2.csgo', 'extensions')
   238 
   239 if 'ep2v' in SM.sdkInfo:
   240 	AddNormalLibrary('game.tf2.ext.2.ep2v', 'extensions')
   241 
   242 AddNormalLibrary('topmenus.ext', 'extensions')
   243 AddNormalLibrary('regex.ext', 'extensions')
   244 AddNormalLibrary('webternet.ext', 'extensions')
   245 AddNormalLibrary('clientprefs.ext', 'extensions')
   246 AddNormalLibrary('updater.ext', 'extensions')
   247 AddNormalLibrary('bintools.ext', 'extensions')
   248 AddHL2Library('sdktools.ext', 'extensions')
   249 
   250 bincopies.append(CopyFile(os.path.join('..', 'spcomp', 'spcomp' + osutil.ExecutableSuffix()),
   251                           os.path.join('addons', 'sourcemod', 'scripting')))
   252 
   253 job.AddCommandGroup(bincopies)
   254 
   255 if AMBuild.target['platform'] == 'windows':
   256 	job.AddCommand(CopyFile(
   257 		os.path.join(AMBuild.sourceFolder, 'sourcepawn', 'batchtool', 'compile.exe'),
   258 		os.path.join('addons', 'sourcemod', 'scripting')))
   259 	
   260 pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
   261 for pdb in debug_info:
   262 	pdblog.write(pdb + '\n')
   263 pdblog.close()
   264