support/buildbot/PackageScript
author Asher Baker <asherkin@gmail.com>
Mon Apr 01 03:03:31 2013 +0100 (2013-04-01)
changeset 830 ca911754b95d
parent 704 6055e296b807
child 870 004b1437bd14
permissions -rw-r--r--
Added basic VDF file for easier installation (bug 5681, r=dvander).
ds@704
     1
# vim: set ts=2 sw=2 tw=99 noet ft=python: 
ds@704
     2
import os
ds@704
     3
import shutil
ds@704
     4
import ambuild.osutil as osutil
ds@704
     5
from ambuild.command import Command
ds@704
     6
ds@704
     7
job = AMBuild.AddJob('package')
ds@704
     8
ds@704
     9
class DestroyPath(Command):
ds@704
    10
	def __init__(self, folder):
ds@704
    11
		Command.__init__(self)
ds@704
    12
		self.folder = folder
ds@704
    13
ds@704
    14
	def destroy(self, path):
ds@704
    15
		entries = os.listdir(path)
ds@704
    16
		for entry in entries:
ds@704
    17
			newpath = os.path.join(path, entry)
ds@704
    18
			if os.path.isdir(newpath):
ds@704
    19
				self.destroy(newpath)
ds@704
    20
				os.rmdir(newpath)
ds@704
    21
			elif os.path.isfile(newpath):
ds@704
    22
				os.remove(newpath)
ds@704
    23
ds@704
    24
	def run(self, runner, job):
ds@704
    25
		runner.PrintOut('rm -rf {0}/*'.format(self.folder))
ds@704
    26
		self.destroy(self.folder)
ds@704
    27
ds@704
    28
class CreateFolders(Command):
ds@704
    29
	def __init__(self, folders):
ds@704
    30
		Command.__init__(self)
ds@704
    31
		self.folders = folders
ds@704
    32
	
ds@704
    33
	def run(self, runner, job):
ds@704
    34
		for folder in self.folders:
ds@704
    35
			path = os.path.join(*folder)
ds@704
    36
			runner.PrintOut('mkdir {0}'.format(path))
ds@704
    37
			os.makedirs(path)
ds@704
    38
ds@704
    39
#Shallow folder copy
ds@704
    40
class CopyFolder(Command):
ds@704
    41
	def __init__(self, fromList, toList, excludes = []):
ds@704
    42
		Command.__init__(self)
ds@704
    43
		self.fromPath = os.path.join(AMBuild.sourceFolder, *fromList)
ds@704
    44
		self.toPath = os.path.join(*toList) 
ds@704
    45
		self.excludes = excludes
ds@704
    46
	
ds@704
    47
	def run(self, runner, job):
ds@704
    48
		entries = os.listdir(self.fromPath)
ds@704
    49
		for entry in entries:
ds@704
    50
			if entry in self.excludes:
ds@704
    51
				continue
ds@704
    52
			path = os.path.join(self.fromPath, entry)
ds@704
    53
			if not os.path.isfile(path):
ds@704
    54
				continue
ds@704
    55
			runner.PrintOut('copy {0} to {1}'.format(path, self.toPath))
ds@704
    56
			shutil.copy(path, self.toPath)
ds@704
    57
ds@704
    58
#Single file copy
ds@704
    59
class CopyFile(Command):
ds@704
    60
	def __init__(self, fromFile, toPath):
ds@704
    61
		Command.__init__(self)
ds@704
    62
		self.fromFile = fromFile
ds@704
    63
		self.toPath = toPath
ds@704
    64
ds@704
    65
	def run(self, runner, job):
ds@704
    66
		runner.PrintOut('copy {0} to {1}'.format(self.fromFile, self.toPath))
ds@704
    67
		shutil.copy(self.fromFile, self.toPath)
ds@704
    68
ds@704
    69
ds@704
    70
folders = [['addons', 'metamod', 'bin']]
ds@704
    71
ds@704
    72
#Setup
ds@704
    73
job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
ds@704
    74
job.AddCommand(CreateFolders(folders))
ds@704
    75
asherkin@830
    76
#Copy Files
asherkin@830
    77
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'support', 'metamod.vdf'),
asherkin@830
    78
                        os.path.join('addons')))
ds@704
    79
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'support', 'metaplugins.ini'),
ds@704
    80
                        os.path.join('addons', 'metamod')))
ds@704
    81
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'support', 'README.txt'),
ds@704
    82
                        os.path.join('addons', 'metamod')))
ds@704
    83
ds@704
    84
bincopies = []
ds@704
    85
ds@704
    86
def AddNormalLibrary(name, dest):
ds@704
    87
	dest = os.path.join('addons', 'metamod', dest)
ds@704
    88
	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
ds@704
    89
	pdb_list.append(name + '\\' + name + '.pdb')
ds@704
    90
ds@704
    91
def AddHL2Library(name, dest):
ds@704
    92
	for i in MMS.sdkInfo:
ds@704
    93
		sdk = MMS.sdkInfo[i]
ds@704
    94
		if AMBuild.target['platform'] not in sdk['platform']:
ds@704
    95
			continue
ds@704
    96
		AddNormalLibrary(name + '.' + sdk['ext'], dest)
ds@704
    97
ds@704
    98
pdb_list = []
ds@704
    99
ds@704
   100
# Copy loader binaries
ds@704
   101
AddNormalLibrary('server', 'bin')
ds@704
   102
if AMBuild.target['platform'] == 'linux':
ds@704
   103
	AddNormalLibrary('server_i486', 'bin')
ds@704
   104
ds@704
   105
AddHL2Library('metamod', 'bin')
ds@704
   106
ds@704
   107
job.AddCommandGroup(bincopies)
ds@704
   108
ds@704
   109
if AMBuild.target['platform'] == 'windows':
ds@704
   110
	pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
ds@704
   111
	for pdb in pdb_list:
ds@704
   112
		pdblog.write(pdb + '\n')
ds@704
   113
	pdblog.close()
ds@704
   114