tools/buildbot/PackageScript
author David Anderson <dvander@alliedmods.net>
Thu Aug 08 22:02:42 2013 -0700 (2013-08-08)
changeset 3980 dc7dfcd855dc
parent 3961 0dc477c29792
child 4186 c6a694ae8566
permissions -rw-r--r--
More Windows build 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', 'sdkhooks.games'],
    75            ['addons', 'sourcemod', 'gamedata', 'sdktools.games'],
    76 		   ['addons', 'sourcemod', 'gamedata', 'sm-cstrike.games'],
    77            ['addons', 'sourcemod', 'configs', 'geoip'],
    78            ['addons', 'sourcemod', 'translations'],
    79            ['addons', 'sourcemod', 'logs'],
    80            ['addons', 'sourcemod', 'extensions'],
    81            ['addons', 'sourcemod', 'data'],
    82            ['addons', 'sourcemod', 'scripting', 'include'],
    83            ['addons', 'sourcemod', 'scripting', 'admin-flatfile'],
    84            ['addons', 'sourcemod', 'scripting', 'adminmenu'],
    85            ['addons', 'sourcemod', 'scripting', 'testsuite'],
    86            ['cfg', 'sourcemod'],
    87            ['addons', 'sourcemod', 'configs', 'sql-init-scripts'],
    88            ['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'mysql'],
    89            ['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'sqlite'],
    90            ['addons', 'sourcemod', 'scripting', 'basecommands'],
    91            ['addons', 'sourcemod', 'scripting', 'basecomm'],
    92            ['addons', 'sourcemod', 'scripting', 'funvotes'],
    93            ['addons', 'sourcemod', 'scripting', 'basevotes'],
    94            ['addons', 'sourcemod', 'scripting', 'basebans'],
    95            ['addons', 'sourcemod', 'scripting', 'funcommands'],
    96            ['addons', 'sourcemod', 'scripting', 'playercommands'],
    97            ['addons', 'metamod'],
    98           ]
    99 
   100 #Setup
   101 job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
   102 job.AddCommand(CreateFolders(folders))
   103 
   104 #Copy Folders
   105 job.AddCommand(CopyFolder(['configs'], ['addons', 'sourcemod', 'configs']))
   106 job.AddCommand(CopyFolder(['configs', 'geoip'], ['addons', 'sourcemod', 'configs', 'geoip']))
   107 job.AddCommand(CopyFolder(['configs', 'cfg'], ['cfg', 'sourcemod']))
   108 job.AddCommand(CopyFolder(['configs', 'metamod'], ['addons', 'metamod']))
   109 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts'],
   110 	['addons', 'sourcemod', 'configs', 'sql-init-scripts']))
   111 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts', 'mysql'],
   112 	['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'mysql']))
   113 job.AddCommand(CopyFolder(['configs', 'sql-init-scripts', 'sqlite'],
   114 	['addons', 'sourcemod', 'configs', 'sql-init-scripts', 'sqlite']))
   115 job.AddCommand(CopyFolder(['gamedata'], ['addons', 'sourcemod', 'gamedata']))
   116 job.AddCommand(CopyFolder(['gamedata', 'sdkhooks.games'],
   117 	['addons', 'sourcemod', 'gamedata', 'sdkhooks.games']))
   118 job.AddCommand(CopyFolder(['gamedata', 'sdktools.games'],
   119 	['addons', 'sourcemod', 'gamedata', 'sdktools.games']))
   120 job.AddCommand(CopyFolder(['gamedata', 'core.games'],
   121 	['addons', 'sourcemod', 'gamedata', 'core.games']))
   122 job.AddCommand(CopyFolder(['gamedata', 'sm-cstrike.games'],
   123 	['addons', 'sourcemod', 'gamedata', 'sm-cstrike.games']))
   124 job.AddCommand(CopyFolder(['plugins'], ['addons', 'sourcemod', 'scripting'], ['AMBuilder']))
   125 job.AddCommand(CopyFolder(['plugins', 'include'],
   126 	['addons', 'sourcemod', 'scripting', 'include']))
   127 job.AddCommand(CopyFolder(['translations'], ['addons', 'sourcemod', 'translations']))
   128 job.AddCommand(CopyFolder(['public', 'licenses'], ['addons', 'sourcemod']))
   129 job.AddCommand(CopyFolder(['plugins', 'admin-flatfile'],
   130 	['addons', 'sourcemod', 'scripting', 'admin-flatfile']))
   131 job.AddCommand(CopyFolder(['plugins', 'adminmenu'],
   132 	['addons', 'sourcemod', 'scripting', 'adminmenu']))
   133 job.AddCommand(CopyFolder(['plugins', 'testsuite'],
   134 	['addons', 'sourcemod', 'scripting', 'testsuite']))
   135 job.AddCommand(CopyFolder(['plugins', 'basecommands'],
   136 	['addons', 'sourcemod', 'scripting', 'basecommands']))
   137 job.AddCommand(CopyFolder(['plugins', 'basecomm'],
   138 	['addons', 'sourcemod', 'scripting', 'basecomm']))
   139 job.AddCommand(CopyFolder(['plugins', 'funvotes'],
   140 	['addons', 'sourcemod', 'scripting', 'funvotes']))
   141 job.AddCommand(CopyFolder(['plugins', 'basevotes'],
   142 	['addons', 'sourcemod', 'scripting', 'basevotes']))
   143 job.AddCommand(CopyFolder(['plugins', 'basebans'],
   144 	['addons', 'sourcemod', 'scripting', 'basebans']))
   145 job.AddCommand(CopyFolder(['plugins', 'funcommands'],
   146 	['addons', 'sourcemod', 'scripting', 'funcommands']))
   147 job.AddCommand(CopyFolder(['plugins', 'playercommands'],
   148 	['addons', 'sourcemod', 'scripting', 'playercommands']))
   149 
   150 defPlugins = [
   151 	'admin-flatfile',
   152 	'adminhelp',
   153 	'antiflood',
   154 	'basecommands',
   155 	'reservedslots',
   156 	'basetriggers',
   157 	'nextmap',
   158 	'basechat',
   159 	'funcommands',
   160 	'basevotes',
   161 	'funvotes',
   162 	'basebans',
   163 	'basecomm',
   164 	'adminmenu',
   165 	'playercommands',
   166 	'clientprefs',
   167 	'sounds'
   168 ]
   169 
   170 disPlugins = [
   171 	'admin-sql-prefetch',
   172 	'admin-sql-threaded',
   173 	'sql-admin-manager',
   174 	'mapchooser',
   175 	'randomcycle',
   176 	'rockthevote',
   177 	'nominations'
   178 ]
   179 
   180 commands = []
   181 for plugin in defPlugins:
   182 	commands.append(CopyFile(os.path.join('..', 'plugins', plugin + '.smx'),
   183 	                         os.path.join('addons', 'sourcemod', 'plugins')))
   184 
   185 for plugin in disPlugins:
   186 	commands.append(CopyFile(os.path.join('..', 'plugins', plugin + '.smx'),
   187 	                         os.path.join('addons', 'sourcemod', 'plugins', 'disabled')))
   188 job.AddCommandGroup(commands)
   189 
   190 job.AddCommand(CopyFile(os.path.join('..', 'includes', 'version_auto.inc'),
   191 	os.path.join('addons', 'sourcemod', 'scripting', 'include')))
   192 
   193 bincopies = []
   194 
   195 def AddNormalLibrary(name, dest):
   196 	dest = os.path.join('addons', 'sourcemod', dest)
   197 	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
   198 	
   199 	# Each platform's version of dump_syms needs the path in a different format.
   200 	if AMBuild.target['platform'] == 'linux':
   201 		debug_info.append(name + '/' + name + '.so')
   202 	elif AMBuild.target['platform'] == 'darwin':
   203 		debug_info.append(name + '/' + name + '.dylib.dSYM')
   204 	elif AMBuild.target['platform'] == 'windows':
   205 		debug_info.append(name + '\\' + name + '.pdb')
   206 
   207 def AddHL2Library(name, dest):
   208 	for i in SM.sdkInfo:
   209 		sdk = SM.sdkInfo[i]
   210 		if AMBuild.target['platform'] not in sdk['platform']:
   211 			continue
   212 		AddNormalLibrary(name + '.' + sdk['ext'], dest)
   213 
   214 debug_info = []
   215 
   216 if AMBuild.target['platform'] == 'linux':
   217 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm_i486.so'),
   218 	                 os.path.join('addons', 'sourcemod', 'bin')))
   219 	debug_info.append('loader/sourcemod_mm_i486.so')
   220 elif AMBuild.target['platform'] == 'darwin':
   221 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dylib'),
   222 	                 os.path.join('addons', 'sourcemod', 'bin')))
   223 	debug_info.append('loader/sourcemod_mm.dylib.dSYM')
   224 elif AMBuild.target['platform'] == 'windows':
   225 	bincopies.append(CopyFile(os.path.join('..', 'loader', 'sourcemod_mm.dll'),
   226 	                 os.path.join('addons', 'sourcemod', 'bin')))
   227 	debug_info.append('loader\\sourcemod_mm.pdb')
   228 
   229 AddHL2Library('sourcemod', 'bin')
   230 AddNormalLibrary('sourcemod.logic', 'bin')
   231 AddNormalLibrary('sourcepawn.jit.x86', 'bin')
   232 AddNormalLibrary('geoip.ext', 'extensions')
   233 if SM.hasMySql:
   234 	AddNormalLibrary('dbi.mysql.ext', 'extensions')
   235 AddNormalLibrary('dbi.sqlite.ext', 'extensions')
   236 
   237 if 'css' in SM.sdkInfo:
   238 	AddNormalLibrary('game.cstrike.ext.2.css', 'extensions')
   239 
   240 if 'csgo' in SM.sdkInfo:
   241 	AddNormalLibrary('game.cstrike.ext.2.csgo', 'extensions')
   242 
   243 if 'tf2' in SM.sdkInfo:
   244 	AddNormalLibrary('game.tf2.ext.2.tf2', 'extensions')
   245 
   246 AddNormalLibrary('topmenus.ext', 'extensions')
   247 AddNormalLibrary('regex.ext', 'extensions')
   248 AddNormalLibrary('webternet.ext', 'extensions')
   249 AddNormalLibrary('clientprefs.ext', 'extensions')
   250 AddNormalLibrary('updater.ext', 'extensions')
   251 AddNormalLibrary('bintools.ext', 'extensions')
   252 AddHL2Library('sdkhooks.ext', 'extensions')
   253 AddHL2Library('sdktools.ext', 'extensions')
   254 
   255 bincopies.append(CopyFile(os.path.join('..', 'spcomp', 'spcomp' + osutil.ExecutableSuffix()),
   256                           os.path.join('addons', 'sourcemod', 'scripting')))
   257 
   258 # Each platform's version of dump_syms needs the path in a different format.
   259 if AMBuild.target['platform'] == 'linux':
   260 	debug_info.append('spcomp' + '/' + 'spcomp')
   261 elif AMBuild.target['platform'] == 'darwin':
   262 	debug_info.append('spcomp' + '/' + 'spcomp' + '.dSYM')
   263 elif AMBuild.target['platform'] == 'windows':
   264 	debug_info.append('spcomp' + '\\' + 'spcomp' + '.pdb')
   265 
   266 job.AddCommandGroup(bincopies)
   267 
   268 if AMBuild.target['platform'] == 'windows':
   269 	job.AddCommand(CopyFile(
   270 		os.path.join(AMBuild.sourceFolder, 'sourcepawn', 'batchtool', 'compile.exe'),
   271 		os.path.join('addons', 'sourcemod', 'scripting')))
   272 	
   273 pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
   274 for pdb in debug_info:
   275 	pdblog.write(pdb + '\n')
   276 pdblog.close()
   277