tools/buildbot/PackageScript
author Nicholas Hastings <skamonkey@gmail.com>
Sun May 27 17:47:41 2012 -0400 (2012-05-27)
changeset 3527 ea5b93820d9b
parent 3526 52bf630769bc
child 3540 33b39cd05faf
permissions -rw-r--r--
ANOTHER typo fix.
     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 bincopies = []
   188 
   189 def AddNormalLibrary(name, dest):
   190 	dest = os.path.join('addons', 'sourcemod', dest)
   191 	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
   192 	
   193 	# Each platform's version of dump_syms needs the path in a different format.
   194 	if AMBuild.target['platform'] == 'linux':
   195 		debug_info.append(name + '/' + name + '.so')
   196 	elif AMBuild.target['platform'] == 'darwin':
   197 		debug_info.append(name + '/' + name + '.dylib.dSYM')
   198 	elif AMBuild.target['platform'] == 'windows':
   199 		debug_info.append(name + '\\' + name + '.pdb')
   200 
   201 def AddHL2Library(name, dest):
   202 	for i in SM.sdkInfo:
   203 		sdk = SM.sdkInfo[i]
   204 		if AMBuild.target['platform'] not in sdk['platform']:
   205 			continue
   206 		AddNormalLibrary(name + '.' + sdk['ext'], dest)
   207 
   208 debug_info = []
   209 
   210 if AMBuild.target['platform'] == 'linux':
   211 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm_i486.so'),
   212 	                 os.path.join('addons', 'sourcemod', 'bin')))
   213 	debug_info.append('loader/sourcemod_mm_i486.so')
   214 elif AMBuild.target['platform'] == 'darwin':
   215 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dylib'),
   216 	                 os.path.join('addons', 'sourcemod', 'bin')))
   217 	debug_info.append('loader/sourcemod_mm.dylib.dSYM')
   218 elif AMBuild.target['platform'] == 'windows':
   219 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dll'),
   220 	                 os.path.join('addons', 'sourcemod', 'bin')))
   221 	debug_info.append('loader\\sourcemod_mm.pdb')
   222 
   223 AddHL2Library('sourcemod', 'bin')
   224 AddNormalLibrary('sourcemod.logic', 'bin')
   225 AddNormalLibrary('sourcepawn.jit.x86', 'bin')
   226 AddNormalLibrary('geoip.ext', 'extensions')
   227 AddNormalLibrary('dbi.mysql.ext', 'extensions')
   228 AddNormalLibrary('dbi.sqlite.ext', 'extensions')
   229 
   230 AddNormalLibrary('game.cstrike.ext.2.ep2v', 'extensions')
   231 if AMBuild.target['platform'] != 'darwin':
   232 	AddNormalLibrary('game.cstrike.ext.2.csgo', 'extensions')
   233 	
   234 AddNormalLibrary('game.tf2.ext.2.ep2v', 'extensions')
   235 AddNormalLibrary('topmenus.ext', 'extensions')
   236 AddNormalLibrary('regex.ext', 'extensions')
   237 AddNormalLibrary('webternet.ext', 'extensions')
   238 AddNormalLibrary('clientprefs.ext', 'extensions')
   239 AddNormalLibrary('updater.ext', 'extensions')
   240 AddNormalLibrary('bintools.ext', 'extensions')
   241 AddHL2Library('sdktools.ext', 'extensions')
   242 
   243 bincopies.append(CopyFile(os.path.join('..', 'spcomp', 'spcomp' + osutil.ExecutableSuffix()),
   244                           os.path.join('addons', 'sourcemod', 'scripting')))
   245 
   246 job.AddCommandGroup(bincopies)
   247 
   248 if AMBuild.target['platform'] == 'windows':
   249 	job.AddCommand(CopyFile(
   250 		os.path.join(AMBuild.sourceFolder, 'sourcepawn', 'batchtool', 'compile.exe'),
   251 		os.path.join('addons', 'sourcemod', 'scripting')))
   252 	
   253 pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
   254 for pdb in debug_info:
   255 	pdblog.write(pdb + '\n')
   256 pdblog.close()
   257