tools/buildbot/PackageScript
author Nicholas Hastings <skamonkey@gmail.com>
Wed Jun 23 08:54:56 2010 -0400 (2010-06-23)
changeset 3046 378bb5f89ffe
parent 2993 76da4d93e0d6
child 3053 56afc7b83a4b
permissions -rw-r--r--
Ep2v cstrike ext now gets added to package.
     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', 'configs', 'geoip'],
    76            ['addons', 'sourcemod', 'translations'],
    77            ['addons', 'sourcemod', 'logs'],
    78            ['addons', 'sourcemod', 'extensions'],
    79            ['addons', 'sourcemod', 'data'],
    80            ['addons', 'sourcemod', 'scripting', 'include'],
    81            ['addons', 'sourcemod', 'scripting', 'admin-flatfile'],
    82            ['addons', 'sourcemod', 'scripting', 'adminmenu'],
    83            ['addons', 'sourcemod', 'scripting', 'testsuite'],
    84            ['cfg', 'sourcemod'],
    85            ['addons', 'sourcemod', 'configs', 'sql-init-scripts'],
    86            ['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'mysql'],
    87            ['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'sqlite'],
    88            ['addons', 'sourcemod', 'scripting', 'basecommands'],
    89            ['addons', 'sourcemod', 'scripting', 'basecomm'],
    90            ['addons', 'sourcemod', 'scripting', 'funvotes'],
    91            ['addons', 'sourcemod', 'scripting', 'basevotes'],
    92            ['addons', 'sourcemod', 'scripting', 'basebans'],
    93            ['addons', 'sourcemod', 'scripting', 'funcommands'],
    94            ['addons', 'sourcemod', 'scripting', 'playercommands'],
    95            ['addons', 'metamod'],
    96           ]
    97 
    98 #Setup
    99 job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
   100 job.AddCommand(CreateFolders(folders))
   101 
   102 #Copy Folders
   103 job.AddCommand(CopyFolder(['configs'], ['addons', 'sourcemod', 'configs']))
   104 job.AddCommand(CopyFolder(['configs', 'geoip'], ['addons', 'sourcemod', 'configs', 'geoip']))
   105 job.AddCommand(CopyFolder(['configs', 'cfg'], ['cfg', 'sourcemod']))
   106 job.AddCommand(CopyFolder(['configs', 'metamod'], ['addons', 'metamod']))
   107 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts'],
   108 	['addons', 'sourcemod', 'configs', 'sql-init-scripts']))
   109 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts', 'mysql'],
   110 	['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'mysql']))
   111 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts', 'sqlite'],
   112 	['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'sqlite']))
   113 job.AddCommand(CopyFolder(['gamedata'], ['addons', 'sourcemod', 'gamedata']))
   114 job.AddCommand(CopyFolder(['gamedata', 'sdktools.games'],
   115 	['addons', 'sourcemod', 'gamedata', 'sdktools.games']))
   116 job.AddCommand(CopyFolder(['gamedata', 'core.games'],
   117 	['addons', 'sourcemod', 'gamedata', 'core.games']))
   118 job.AddCommand(CopyFolder(['plugins'], ['addons', 'sourcemod', 'scripting'], ['AMBuilder']))
   119 job.AddCommand(CopyFolder(['plugins', 'include'],
   120 	['addons', 'sourcemod', 'scripting', 'include']))
   121 job.AddCommand(CopyFolder(['translations'], ['addons', 'sourcemod', 'translations']))
   122 job.AddCommand(CopyFolder(['public', 'licenses'], ['addons', 'sourcemod']))
   123 job.AddCommand(CopyFolder(['plugins', 'admin-flatfile'],
   124 	['addons', 'sourcemod', 'scripting', 'admin-flatfile']))
   125 job.AddCommand(CopyFolder(['plugins', 'adminmenu'],
   126 	['addons', 'sourcemod', 'scripting', 'adminmenu']))
   127 job.AddCommand(CopyFolder(['plugins', 'testsuite'],
   128 	['addons', 'sourcemod', 'scripting', 'testsuite']))
   129 job.AddCommand(CopyFolder(['plugins', 'basecommands'],
   130 	['addons', 'sourcemod', 'scripting', 'basecommands']))
   131 job.AddCommand(CopyFolder(['plugins', 'basecomm'],
   132 	['addons', 'sourcemod', 'scripting', 'basecomm']))
   133 job.AddCommand(CopyFolder(['plugins', 'funvotes'],
   134 	['addons', 'sourcemod', 'scripting', 'funvotes']))
   135 job.AddCommand(CopyFolder(['plugins', 'basevotes'],
   136 	['addons', 'sourcemod', 'scripting', 'basevotes']))
   137 job.AddCommand(CopyFolder(['plugins', 'basebans'],
   138 	['addons', 'sourcemod', 'scripting', 'basebans']))
   139 job.AddCommand(CopyFolder(['plugins', 'funcommands'],
   140 	['addons', 'sourcemod', 'scripting', 'funcommands']))
   141 job.AddCommand(CopyFolder(['plugins', 'playercommands'],
   142 	['addons', 'sourcemod', 'scripting', 'playercommands']))
   143 
   144 defPlugins = [
   145 	'admin-flatfile',
   146 	'adminhelp',
   147 	'antiflood',
   148 	'basecommands',
   149 	'reservedslots',
   150 	'basetriggers',
   151 	'nextmap',
   152 	'basechat',
   153 	'funcommands',
   154 	'basevotes',
   155 	'funvotes',
   156 	'basebans',
   157 	'basecomm',
   158 	'adminmenu',
   159 	'playercommands',
   160 	'clientprefs',
   161 	'sounds'
   162 ]
   163 
   164 disPlugins = [
   165 	'admin-sql-prefetch',
   166 	'admin-sql-threaded',
   167 	'sql-admin-manager',
   168 	'mapchooser',
   169 	'randomcycle',
   170 	'rockthevote',
   171 	'nominations'
   172 ]
   173 
   174 commands = []
   175 for plugin in defPlugins:
   176 	commands.append(CopyFile(os.path.join('..', 'plugins', plugin + '.smx'),
   177 	                         os.path.join('addons', 'sourcemod', 'plugins')))
   178 
   179 for plugin in disPlugins:
   180 	commands.append(CopyFile(os.path.join('..', 'plugins', plugin + '.smx'),
   181 	                         os.path.join('addons', 'sourcemod', 'plugins', 'disabled')))
   182 job.AddCommandGroup(commands)
   183 
   184 bincopies = []
   185 
   186 def AddNormalLibrary(name, dest):
   187 	dest = os.path.join('addons', 'sourcemod', dest)
   188 	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
   189 	pdb_list.append(name + '\\' + name + '.pdb')
   190 
   191 def AddHL2Library(name, dest):
   192 	for i in SM.sdkInfo:
   193 		sdk = SM.sdkInfo[i]
   194 		if AMBuild.target['platform'] not in sdk['platform']:
   195 			continue
   196 		AddNormalLibrary(name + '.' + sdk['ext'], dest)
   197 
   198 pdb_list = []
   199 
   200 if AMBuild.target['platform'] == 'linux':
   201 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm_i486.so'),
   202 	                 os.path.join('addons', 'sourcemod', 'bin')))
   203 elif AMBuild.target['platform'] == 'darwin':
   204 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dylib'),
   205 	                 os.path.join('addons', 'sourcemod', 'bin')))
   206 elif AMBuild.target['platform'] == 'windows':
   207 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dll'),
   208 	                 os.path.join('addons', 'sourcemod', 'bin')))
   209 	pdb_list.append('loader\\sourcemod_mm.pdb')
   210 
   211 AddHL2Library('sourcemod', 'bin')
   212 AddNormalLibrary('sourcemod.logic', 'bin')
   213 AddNormalLibrary('sourcepawn.jit.x86', 'bin')
   214 AddNormalLibrary('geoip.ext', 'extensions')
   215 AddNormalLibrary('dbi.mysql.ext', 'extensions')
   216 AddNormalLibrary('dbi.sqlite.ext', 'extensions')
   217 if AMBuild.target['platform'] != 'darwin':
   218 	AddNormalLibrary('game.cstrike.ext.1.ep1', 'extensions')
   219 AddNormalLibrary('game.cstrike.ext.2.ep2v', 'extensions')
   220 AddNormalLibrary('game.tf2.ext.2.ep2v', 'extensions')
   221 AddNormalLibrary('topmenus.ext', 'extensions')
   222 AddNormalLibrary('regex.ext', 'extensions')
   223 AddNormalLibrary('webternet.ext', 'extensions')
   224 AddNormalLibrary('clientprefs.ext', 'extensions')
   225 AddNormalLibrary('updater.ext', 'extensions')
   226 AddHL2Library('bintools.ext', 'extensions')
   227 AddHL2Library('sdktools.ext', 'extensions')
   228 
   229 bincopies.append(CopyFile(os.path.join('..', 'spcomp', 'spcomp' + osutil.ExecutableSuffix()),
   230                           os.path.join('addons', 'sourcemod', 'scripting')))
   231 
   232 job.AddCommandGroup(bincopies)
   233 
   234 if AMBuild.target['platform'] == 'windows':
   235 	job.AddCommand(CopyFile(
   236 		os.path.join(AMBuild.sourceFolder, 'sourcepawn', 'batchtool', 'compile.exe'),
   237 		os.path.join('addons', 'sourcemod', 'scripting')))
   238 	pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
   239 	for pdb in pdb_list:
   240 		pdblog.write(pdb + '\n')
   241 	pdblog.close()
   242