PackageScript
author David Anderson <danderson@mozilla.com>
Fri Apr 15 01:07:45 2011 -0700 (2011-04-15)
changeset 28 dc8f2d4b515d
child 32 4abb69efd473
permissions -rw-r--r--
AMBuild infrastructure.
     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', 'metamod'],
    71 				   ['addons', 'stripper'],
    72 					 ['addons', 'stripper', 'bin'],
    73 					 ['addons', 'stripper', 'dumps'],
    74 					 ['addons', 'stripper', 'maps']]
    75 
    76 #Setup
    77 job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
    78 job.AddCommand(CreateFolders(folders))
    79 
    80 #Copiy Files
    81 job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'de_dust.cfg'),
    82                         os.path.join('addons', 'stripper', 'maps')))
    83 job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'global_filters.cfg'),
    84                         os.path.join('addons', 'stripper')))
    85 
    86 bincopies = []
    87 
    88 def AddNormalLibrary(name, dest):
    89 	dest = os.path.join('addons', 'stripper', dest)
    90 	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
    91 	pdb_list.append(name + '\\' + name + '.pdb')
    92 
    93 def AddHL2Library(name, dest):
    94 	for i in Stripper.sdkInfo:
    95 		sdk = Stripper.sdkInfo[i]
    96 		if AMBuild.target['platform'] not in sdk['platform']:
    97 			continue
    98 		AddNormalLibrary(name + '.' + sdk['ext'], dest)
    99 
   100 pdb_list = []
   101 
   102 # Copy loader binaries
   103 AddNormalLibrary('stripper_mm', 'bin')
   104 AddNormalLibrary('stripper.core', 'bin')
   105 AddHL2Library('stripper', 'bin')
   106 
   107 job.AddCommandGroup(bincopies)
   108 
   109 if AMBuild.target['platform'] == 'windows':
   110 	pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
   111 	for pdb in pdb_list:
   112 		pdblog.write(pdb + '\n')
   113 	pdblog.close()
   114 
   115