Add AMBuild

This commit is contained in:
Dr!fter
2013-09-01 11:11:38 -04:00
parent c7a075fd8e
commit f331c3dfaf
12 changed files with 1012 additions and 18 deletions
+116
View File
@@ -0,0 +1,116 @@
# vim: set ts=2 sw=2 tw=99 noet ft=python:
import os
import shutil
import ambuild.osutil as osutil
from ambuild.command import Command
job = AMBuild.AddJob('package')
class DestroyPath(Command):
def __init__(self, folder):
Command.__init__(self)
self.folder = folder
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)
folders = [
['addons', 'sourcemod', 'extensions'],
['addons', 'sourcemod', 'scripting', 'include'],
['addons', 'sourcemod', 'gamedata'],
['addons', 'sourcemod', 'gamedata', 'dhooks.games']
]
#Setup
job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
job.AddCommand(CreateFolders(folders))
#Copy Files
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'sourcemod', 'scripting', 'include', 'dhooks.inc'),
os.path.join('addons', 'sourcemod', 'scripting', 'include')))
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'sourcemod', 'scripting', 'dhooks-test.sp'),
os.path.join('addons', 'sourcemod', 'scripting')))
job.AddCommand(CopyFolder([AMBuild.sourceFolder, 'sourcemod', 'gamedata', 'dhooks-test.games'],
['addons', 'sourcemod', 'gamedata', 'dhooks-test.games']))
bincopies = []
def AddNormalLibrary(name, dest):
dest = os.path.join('addons', 'sourcemod', dest)
bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
#pdb_list.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)
#pdb_list = []
AddHL2Library('dhooks', 'extensions')
job.AddCommandGroup(bincopies)
#if AMBuild.target['platform'] == 'windows':
# pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
# for pdb in pdb_list:
# pdblog.write(pdb + '\n')
# pdblog.close()
+78
View File
@@ -0,0 +1,78 @@
#!/usr/bin/perl
# vim: set ts=2 sw=2 tw=99 noet:
use strict;
use Cwd;
use File::Basename;
use File::Path;
my ($myself, $path) = fileparse($0);
chdir($path);
require 'helpers.pm';
#Go back above build dir
chdir(Build::PathFormat('../..'));
#Get the source path.
our ($root) = getcwd();
rmtree('OUTPUT');
mkdir('OUTPUT') or die("Failed to create output folder: $!\n");
chdir('OUTPUT');
my ($result);
print "Attempting to reconfigure...\n";
#update and configure shiz
if ($^O eq "linux") {
#my @sdks = ('sourcemod-1.3', 'mmsource-1.8', 'hl2sdk', 'hl2sdk-ob', 'hl2sdk-ob-valve', 'hl2sdk-l4d', 'hl2sdk-l4d2');
#my ($sdk);
#foreach $sdk (@sdks) {
# print "Updating checkout of ", $sdk, " on ", $^O, "\n";
# $result = `hg pull -u /home/builds/common/$sdk`;
# print $result;
#}
$ENV{'SOURCEMOD14'} = '/home/builds/common/sourcemod-1.4';
$ENV{'MMSOURCE19'} = '/home/builds/common/mmsource-1.9';
$ENV{'HL2SDK'} = '/home/builds/common/hl2sdk';
$ENV{'HL2SDKOB'} = '/home/builds/common/hl2sdk-ob';
$ENV{'HL2SDKOBVALVE'} = '/home/builds/common/hl2sdk-ob-valve';
$ENV{'HL2SDKL4D'} = '/home/builds/common/hl2sdk-l4d';
$ENV{'HL2SDKL4D2'} = '/home/builds/common/hl2sdk-l4d2';
$ENV{'HL2SDKCSGO'} = '/home/builds/common/hl2sdk-csgo';
} elsif ($^O eq "darwin") {
#my @sdks = ('sourcemod-1.3', 'mmsource-1.8', 'hl2sdk-ob-valve');
#my ($sdk);
#foreach $sdk (@sdks) {
# print "Updating checkout of ", $sdk, " on ", $^O, "\n";
# $result = `hg pull -u /Users/builds/slaves/common/$sdk`;
# print $result;
#}
$ENV{'SOURCEMOD14'} = '/Users/builds/slaves/common/sourcemod-1.4';
$ENV{'MMSOURCE18'} = '/Users/builds/slaves/common/mmsource-1.8';
$ENV{'MMSOURCE19'} = '/Users/builds/slaves/common/mmsource-central';
$ENV{'HL2SDKOBVALVE'} = '/Users/builds/slaves/common/hl2sdk-ob-valve';
$ENV{'HL2SDKCSS'} = '/Users/builds/slaves/common/hl2sdk-css';
} else {
#JUST IN CASE
#$ENV{'MMSOURCE19'} = "C:\\Scripts\\common\\mmsource-1.9";
#$ENV{'HL2SDKCSGO'} = "C:\\Scripts\\common\\hl2sdk-csgo";
}
# Windows vars should already be set.
#configure AMBuild
if ($^O eq "linux") {
$result = `CC=gcc CXX=gcc python3 ../build/configure.py --enable-optimize`;
} elsif ($^O eq "darwin") {
$result = `CC=clang CXX=clang python3 ../build/configure.py --enable-optimize`;
} else {
$result = `C:\\Python31\\Python.exe ..\\build\\configure.py --enable-optimize`;
}
print "$result\n";
if ($? != 0) {
die('Could not configure!');
}
+1
View File
@@ -0,0 +1 @@
dev
+94
View File
@@ -0,0 +1,94 @@
#!/usr/bin/perl
use strict;
use Cwd;
package Build;
sub HgRevNum
{
my ($path) = (@_);
my ($cd, $text, $rev);
$cd = Cwd::cwd();
chdir($path);
$text = `hg identify -n`;
chdir($cd);
chomp $text;
if ($text =~ /^(\d+)/)
{
return $1;
}
return 0;
}
sub ProductVersion
{
my ($file) = (@_);
my ($version);
open(FILE, $file) or die "Could not open $file: $!\n";
$version = <FILE>;
close(FILE);
chomp $version;
return $version;
}
sub Delete
{
my ($str)=(@_);
if ($^O =~ /MSWin/)
{
Command("del /S /F /Q \"$str\"");
Command("rmdir /S /Q \"$str\"");
} else {
Command("rm -rf $str");
}
return !(-e $str);
}
sub Copy
{
my ($src,$dest)=(@_);
if ($^O =~ /MSWin/)
{
Command("copy \"$src\" \"$dest\" /y");
} else {
Command("cp \"$src\" \"$dest\"");
}
return (-e $dest);
}
sub Move
{
my ($src,$dest)=(@_);
if ($^O =~ /MSWin/)
{
Command("move \"$src\" \"$dest\"");
} else {
Command("mv \"$src\" \"$dest\"");
}
return (-e $dest);
}
sub Command
{
my($cmd)=(@_);
print "$cmd\n";
return `$cmd`;
}
sub PathFormat
{
my ($str)=(@_);
if ($^O =~ /MSWin/)
{
$str =~ s#/#\\#g;
} else {
$str =~ s#\\#/#g;
}
return $str;
}
return 1;
+99
View File
@@ -0,0 +1,99 @@
#!/usr/bin/perl
use strict;
use Cwd;
use File::Basename;
use Net::FTP;
my ($ftp_file, $ftp_host, $ftp_user, $ftp_pass, $ftp_path, $tag);
$ftp_file = shift;
$tag = shift;
open(FTP, $ftp_file) or die "Unable to read FTP config file $ftp_file: $!\n";
$ftp_host = <FTP>;
$ftp_user = <FTP>;
$ftp_pass = <FTP>;
$ftp_path = <FTP>;
close(FTP);
chomp $ftp_host;
chomp $ftp_user;
chomp $ftp_pass;
chomp $ftp_path;
my ($myself, $path) = fileparse($0);
chdir($path);
require 'helpers.pm';
my ($version);
$version = Build::ProductVersion(Build::PathFormat('product.version'));
$version .= '-hg' . Build::HgRevNum('.');
# Append OS to package version
if ($^O eq "darwin")
{
$version .= '-mac';
}
elsif ($^O =~ /MSWin/)
{
$version .= '-windows';
}
else
{
$version .= '-' . $^O;
}
#Switch to the output folder.
chdir(Build::PathFormat('../../OUTPUT/package'));
my ($dirlist, $filename, $cmd);
$dirlist = "addons";
$filename = 'sdkhooks-' . $version;
if ($^O eq "linux")
{
$filename .= '.tar.gz';
$cmd = "tar zcvf $filename $dirlist";
}
else
{
$filename .= '.zip';
$cmd = "zip -r $filename $dirlist";
}
print "$cmd\n";
system($cmd);
$ftp_path .= "/sdkhooks";
my ($major,$minor) = ($version =~ /^(\d+)\.(\d+)/);
$ftp_path .= "/$major.$minor";
my ($ftp);
$ftp = Net::FTP->new($ftp_host, Debug => 0, Passive => 0)
or die "Cannot connect to host $ftp_host: $@";
$ftp->login($ftp_user, $ftp_pass)
or die "Cannot connect to host $ftp_host as $ftp_user: " . $ftp->message . "\n";
if ($ftp_path ne '')
{
# YOU LEAVE ME NO CHOICE
$ftp->mkdir($ftp_path, 1);
$ftp->cwd($ftp_path)
or die "Cannot change to folder $ftp_path: " . $ftp->message . "\n";
}
$ftp->binary();
$ftp->put($filename)
or die "Cannot drop file $filename ($ftp_path): " . $ftp->message . "\n";
$ftp->close();
print "File sent to drop site as $filename -- build succeeded.\n";
exit(0);
+1
View File
@@ -0,0 +1 @@
2.0.0
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/perl
# vim: set ts=2 sw=2 tw=99 noet:
use File::Basename;
my ($myself, $path) = fileparse($0);
chdir($path);
require 'helpers.pm';
chdir('../../OUTPUT');
if ($^O eq "linux" || $^O eq "darwin") {
system("python3 build.py 2>&1");
} else {
system("C:\\Python31\\python.exe build.py 2>&1");
}
if ($? != 0)
{
die "Build failed: $!\n";
}
else
{
exit(0);
}
+64
View File
@@ -0,0 +1,64 @@
#!/usr/bin/perl
use File::Basename;
my ($myself, $path) = fileparse($0);
chdir($path);
require 'helpers.pm';
chdir('..');
open(PDBLOG, '../OUTPUT/pdblog.txt') or die "Could not open pdblog.txt: $!\n";
#Get version info
my ($version);
$version = Build::ProductVersion(Build::PathFormat('product.version'));
$version =~ s/-dev//g;
$version .= '-hg' . Build::HgRevNum('.');
my ($build_type);
$build_type = Build::GetBuildType(Build::PathFormat('buildbot/build_type'));
if ($build_type eq "dev")
{
$build_type = "buildbot";
}
elsif ($build_type eq "rel")
{
$build_type = "release";
}
my ($line);
while (<PDBLOG>)
{
$line = $_;
$line =~ s/\.pdb/\*/;
chomp $line;
Build::Command("symstore add /r /f \"..\\OUTPUT\\$line\" /s \"S:\\cssdm\" /t \"Stripper\" /v \"$version\" /c \"$build_type\"");
}
close(PDBLOG);
#Lowercase DLLs. Sigh.
my (@files);
opendir(DIR, "S:\\cssdm");
@files = readdir(DIR);
closedir(DIR);
my ($i, $j, $file, @subdirs);
for ($i = 0; $i <= $#files; $i++)
{
$file = $files[$i];
next unless ($file =~ /\.dll$/);
next unless (-d "S:\\cssdm\\$file");
opendir(DIR, "S:\\cssdm\\$file");
@subdirs = readdir(DIR);
closedir(DIR);
for ($j = 0; $j <= $#subdirs; $j++)
{
next unless ($subdirs[$j] =~ /[A-Z]/);
Build::Command("rename S:\\cssdm\\$file\\" . $subdirs[$j] . " " . lc($subdirs[$j]));
}
}