Bring build scripts to AMBuild 2.2
This commit is contained in:
+34
-102
@@ -4,112 +4,44 @@ import shutil
|
||||
import ambuild.osutil as osutil
|
||||
from ambuild.command import Command
|
||||
|
||||
job = AMBuild.AddJob('package')
|
||||
builder.SetBuildFolder('package')
|
||||
|
||||
class DestroyPath(Command):
|
||||
def __init__(self, folder):
|
||||
Command.__init__(self)
|
||||
self.folder = folder
|
||||
def CreateFolders(folders):
|
||||
dict = {}
|
||||
for folder in folders:
|
||||
path = os.path.normpath(folder)
|
||||
dict[folder] = builder.AddFolder(path)
|
||||
return dict
|
||||
|
||||
def destroy(self, path):
|
||||
entries = os.listdir(path)
|
||||
for entry in entries:
|
||||
newpath = os.path.join(path, entry)
|
||||
if os.path.isdir(newpath):
|
||||
self.destroy(newpath)
|
||||
os.rmdir(newpath)
|
||||
elif os.path.isfile(newpath):
|
||||
os.remove(newpath)
|
||||
|
||||
def run(self, runner, job):
|
||||
runner.PrintOut('rm -rf {0}/*'.format(self.folder))
|
||||
self.destroy(self.folder)
|
||||
|
||||
class CreateFolders(Command):
|
||||
def __init__(self, folders):
|
||||
Command.__init__(self)
|
||||
self.folders = folders
|
||||
|
||||
def run(self, runner, job):
|
||||
for folder in self.folders:
|
||||
path = os.path.join(*folder)
|
||||
runner.PrintOut('mkdir {0}'.format(path))
|
||||
os.makedirs(path)
|
||||
|
||||
#Shallow folder copy
|
||||
class CopyFolder(Command):
|
||||
def __init__(self, fromList, toList, excludes = []):
|
||||
Command.__init__(self)
|
||||
self.fromPath = os.path.join(AMBuild.sourceFolder, *fromList)
|
||||
self.toPath = os.path.join(*toList)
|
||||
self.excludes = excludes
|
||||
|
||||
def run(self, runner, job):
|
||||
entries = os.listdir(self.fromPath)
|
||||
for entry in entries:
|
||||
if entry in self.excludes:
|
||||
continue
|
||||
path = os.path.join(self.fromPath, entry)
|
||||
if not os.path.isfile(path):
|
||||
continue
|
||||
runner.PrintOut('copy {0} to {1}'.format(path, self.toPath))
|
||||
shutil.copy(path, self.toPath)
|
||||
|
||||
#Single file copy
|
||||
class CopyFile(Command):
|
||||
def __init__(self, fromFile, toPath):
|
||||
Command.__init__(self)
|
||||
self.fromFile = fromFile
|
||||
self.toPath = toPath
|
||||
|
||||
def run(self, runner, job):
|
||||
runner.PrintOut('copy {0} to {1}'.format(self.fromFile, self.toPath))
|
||||
shutil.copy(self.fromFile, self.toPath)
|
||||
def CopyFiles(src, dest, filter_ext=None):
|
||||
source_path = os.path.join(builder.sourcePath, src)
|
||||
if os.path.isfile(source_path):
|
||||
builder.AddCopy(source_path, dest)
|
||||
return
|
||||
for entry in os.listdir(source_path):
|
||||
entry_path = os.path.join(source_path, entry)
|
||||
if not os.path.isfile(entry_path):
|
||||
continue
|
||||
if filter_ext:
|
||||
_, ext = os.path.splitext(entry)
|
||||
if filter_ext != ext:
|
||||
continue
|
||||
builder.AddCopy(entry_path, dest)
|
||||
|
||||
|
||||
folders = [['addons', 'sourcemod', 'extensions'], ['addons', 'sourcemod', 'gamedata'], ['addons', 'sourcemod', 'scripting', 'include']]
|
||||
folders = CreateFolders(['addons/sourcemod/extensions', 'addons/sourcemod/gamedata', 'addons/sourcemod/scripting', 'addons/sourcemod/scripting/include'])
|
||||
|
||||
#Setup
|
||||
job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
|
||||
job.AddCommand(CreateFolders(folders))
|
||||
|
||||
#Copy Files
|
||||
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'connect.games.txt'),
|
||||
os.path.join('addons', 'sourcemod', 'gamedata')))
|
||||
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'connect.inc'),
|
||||
os.path.join('addons', 'sourcemod', 'scripting', 'include')))
|
||||
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'connect.sp'),
|
||||
os.path.join('addons', 'sourcemod', 'scripting')))
|
||||
|
||||
bincopies = []
|
||||
|
||||
def AddNormalLibrary(name, dest):
|
||||
dest = os.path.join('addons', 'sourcemod', dest)
|
||||
bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
|
||||
|
||||
# Each platform's version of dump_syms needs the path in a different format.
|
||||
if AMBuild.target['platform'] == 'linux':
|
||||
debug_info.append(name + '/' + name + '.so')
|
||||
elif AMBuild.target['platform'] == 'darwin':
|
||||
debug_info.append(name + '/' + name + '.dylib.dSYM')
|
||||
elif AMBuild.target['platform'] == 'windows':
|
||||
debug_info.append(name + '\\' + name + '.pdb')
|
||||
|
||||
def AddHL2Library(name, dest):
|
||||
for i in SM.sdkInfo:
|
||||
sdk = SM.sdkInfo[i]
|
||||
if AMBuild.target['platform'] not in sdk['platform']:
|
||||
continue
|
||||
AddNormalLibrary(name + '.ext.' + sdk['ext'], dest)
|
||||
|
||||
debug_info = []
|
||||
|
||||
AddHL2Library('connect', 'extensions')
|
||||
|
||||
job.AddCommandGroup(bincopies)
|
||||
|
||||
pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
|
||||
for pdb in debug_info:
|
||||
pdblog.write(pdb + '\n')
|
||||
pdblog = open(os.path.join(builder.buildPath, 'pdblog.txt'), 'wt')
|
||||
for cxx_task in Extension.extensions:
|
||||
if cxx_task.target.arch == 'x86_64':
|
||||
builder.AddCopy(cxx_task.binary, folders['addons/sourcemod/extensions/x64'])
|
||||
else:
|
||||
builder.AddCopy(cxx_task.binary, folders['addons/sourcemod/extensions'])
|
||||
pdblog.write(cxx_task.debug.path + '\n')
|
||||
pdblog.close()
|
||||
|
||||
CopyFiles('connect.games.txt', folders['addons/sourcemod/gamedata'])
|
||||
CopyFiles('connect.inc', folders['addons/sourcemod/scripting/include'])
|
||||
CopyFiles('connect.sp', folders['addons/sourcemod/scripting'])
|
||||
|
||||
debug_info = []
|
||||
Reference in New Issue
Block a user