Skip to content

Commit d9cf4eb

Browse files
committed
add unity build scripts & perl helper modules
1 parent 1e8ecb8 commit d9cf4eb

File tree

10 files changed

+1761
-0
lines changed

10 files changed

+1761
-0
lines changed

build_all_osx.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
perl build_runtime_osx.pl --debug=1 \
3+
&& perl build_classlibs_osx.pl cleanbuild=0

build_classlibs_osx.pl

Lines changed: 357 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,357 @@
1+
use lib ('.', "perl_lib");
2+
use Cwd;
3+
use File::Path;
4+
use File::Copy::Recursive qw(dircopy);
5+
use Getopt::Long;
6+
use File::Basename;
7+
8+
system("source","~/.profile");
9+
print "My Path: $ENV{PATH}\n";
10+
11+
my $root = getcwd();
12+
13+
my $monodistro = "$root/builds/monodistribution";
14+
my $lib = "$monodistro/lib";
15+
my $libmono = "$lib/mono";
16+
my $monoprefix = "$root/tmp/monoprefix";
17+
18+
if ($ENV{UNITY_THISISABUILDMACHINE}) {
19+
print "rmtree-ing $root/builds because we're on a buildserver, and want to make sure we don't include old artifacts\n";
20+
rmtree("$root/builds");
21+
} else {
22+
print "not rmtree-ing $root/builds, as we're not on a buildmachine\n";
23+
}
24+
25+
my $unity=1;
26+
my $monotouch=1;
27+
my $injectSecurityAttributes=0;
28+
29+
my $skipbuild=0;
30+
my $cleanbuild=1;
31+
GetOptions(
32+
"skipbuild=i"=>\$skipbuild,
33+
"cleanbuild=i"=>\$cleanbuild,
34+
"unity=i"=>\$unity,
35+
"injectsecurityattributes=i"=>\$injectSecurityAttributes,
36+
"monotouch=i"=>\$monotouch,
37+
) or die ("illegal cmdline options");
38+
39+
40+
41+
if (-d $libmono)
42+
{
43+
rmtree($libmono);
44+
}
45+
46+
if (not $skipbuild)
47+
{
48+
#we need to manually set the compiler to gcc4, because the 10.4 sdk only shipped with the gcc4 headers
49+
#their setup is a bit broken as they dont autodetect this, but basically the gist is if you want to copmile
50+
#against the 10.4 sdk, you better use gcc4, otherwise things go boink.
51+
$ENV{CC} = "gcc-4.0";
52+
$ENV{CXX} = "gcc-4.0";
53+
54+
if ($cleanbuild)
55+
{
56+
rmtree($monoprefix);
57+
chdir("$root/mono/eglib") eq 1 or die ("Failed chdir 1");
58+
system("make","clean");
59+
}
60+
chdir("$root/mono") eq 1 or die ("failed to chdir 2");
61+
if ($cleanbuild)
62+
{
63+
my $withMonotouch = $monotouch ? "yes" : "no";
64+
my $withUnity = $unity ? "yes" : "no";
65+
66+
chdir("$root/mono/eglib") eq 1 or die("failed to chdir 3");
67+
print(">>>Calling autoreconf in eglib\n");
68+
system("autoreconf -i") eq 0 or die ("failed autoreconfing eglib");
69+
chdir("$root/mono") eq 1 or die("failed to chdir4");
70+
print(">>>Calling autoreconf in mono\n");
71+
system("autoreconf -i") eq 0 or die("failed to autoreconf mono");
72+
print(">>>Calling configure in mono\n");
73+
system("./configure","--prefix=$monoprefix","--with-monotouch=$withMonotouch","-with-unity=$withUnity", "--with-glib=embedded","--with-mcs-docs=no","--with-macversion=10.4", "--disable-nls") eq 0 or die ("failing autogenning mono");
74+
print("calling make clean in mono\n");
75+
system("make","clean") eq 0 or die ("failed to make clean");
76+
}
77+
system("make") eq 0 or die ("Failed running make");
78+
system("make install") eq 0 or die ("Failed running make install");
79+
print(">>>Making micro lib\n");
80+
chdir("$root/mcs/class/corlib") eq 1 or die("failed to chdir corlib");
81+
system("make PROFILE=monotouch_bootstrap") eq 0 or die ("Failed making monotouch bootstrap");
82+
system("make PROFILE=monotouch MICRO=1 clean") eq 0 or die ("Failed cleaning micro corlib");
83+
system("make PROFILE=monotouch MICRO=1") eq 0 or die ("Failed making micro corlib");
84+
85+
}
86+
chdir ($root);
87+
88+
$File::Copy::Recursive::CopyLink = 0; #make sure we copy files as files and not as symlinks, as TC unfortunately doesn't pick up symlinks.
89+
90+
mkpath("$libmono/2.0");
91+
dircopy("$monoprefix/lib/mono/2.0","$libmono/2.0");
92+
system("rm $libmono/2.0/*.mdb");
93+
mkpath("$libmono/micro");
94+
system("cp $root/mcs/class/lib/monotouch/mscorlib.dll $libmono/micro") eq 0 or die("Failed to copy micro corlib");
95+
system("cp $monoprefix/lib/mono/gac/Mono.Cecil/*/Mono.Cecil.dll $libmono/2.0") eq 0 or die("failed to copy Mono.Cecil.dll");
96+
system("cp -r $monoprefix/bin $monodistro/") eq 0 or die ("failed copying bin folder");
97+
98+
system("cp -r $monoprefix/etc $monodistro/") eq 0 or die("failed copy 4");
99+
mkpath("$root/builds/headers/mono");
100+
system("cp -r $monoprefix/include/mono-1.0/mono $root/builds/headers/") eq 0 or die("failed copy 5");
101+
system("cp $root/mono/eglib/src/glib.h $root/builds/headers/") eq 0 or die("failed copying glib.h");
102+
system("cp $root/mono/eglib/src/eglib-config.hw $root/builds/headers/") eq 0 or die ("failed copying eglib-config.hw");
103+
system('perl -e \"s/\\bmono_/mangledmono_/g;\" -pi $(find '.$root.'/builds/headers -type f)');
104+
105+
sub CopyIgnoringHiddenFiles
106+
{
107+
my $sourceDir = shift;
108+
my $targetDir = shift;
109+
110+
#really need to find a better way to copy a dir, ignoring .svn's than rsync.
111+
system("rsync -a -v --exclude='.*' $sourceDir $targetDir") eq 0 or die("failed to rsync $sourceDir to $targetDir");
112+
}
113+
114+
CopyIgnoringHiddenFiles("add_to_build_results/monodistribution/", "$monoprefix/");
115+
116+
sub cp
117+
{
118+
my $cmdLine = shift;
119+
system("cp $cmdLine") eq 0 or die("failed to copy '$cmdLine'");
120+
}
121+
122+
sub CopyAssemblies
123+
{
124+
my $sourceFolder = shift;
125+
my $targetFolder = shift;
126+
127+
print "Copying assemblies from '$sourceFolder' to '$targetFolder'...\n";
128+
129+
mkpath($targetFolder);
130+
cp("$sourceFolder/*.dll $targetFolder/");
131+
cp("$sourceFolder/*.exe $targetFolder/");
132+
cp("$sourceFolder/*.mdb $targetFolder/");
133+
}
134+
135+
sub CopyProfileAssemblies
136+
{
137+
my $sourceName = shift;
138+
my $targetName = shift;
139+
CopyProfileAssembliesToPrefix($sourceName, $targetName, $monodistro)
140+
}
141+
142+
sub CopyProfileAssembliesToPrefix
143+
{
144+
my $sourceName = shift;
145+
my $targetName = shift;
146+
my $prefix = shift;
147+
148+
my $targetDir = "$prefix/lib/mono/$targetName";
149+
CopyAssemblies("$root/mcs/class/lib/$sourceName", $targetDir);
150+
}
151+
152+
my $securityAttributesPath = "tuning/SecurityAttributes";
153+
154+
sub InjectSecurityAttributesOnProfile
155+
{
156+
if ($injectSecurityAttributes)
157+
{
158+
my $profile = shift;
159+
RunXBuildTargetOnProfile("Install", $profile);
160+
}
161+
}
162+
163+
sub XBuild
164+
{
165+
system("$monoprefix/bin/xbuild", @_) eq 0 or die("Failed to xbuild @_");
166+
}
167+
168+
sub RunXBuildTargetOnProfile
169+
{
170+
my $target = shift;
171+
my $profile = shift;
172+
173+
XBuild("$securityAttributesPath/SecurityAttributes.proj", "/p:Profile=$profile", "/p:ProfilePrefix=$monodistro", "/t:$target") eq 0 or die("failed to run target '$target' on $profile");
174+
}
175+
176+
sub PackageSecurityAttributeInjectionTools
177+
{
178+
if ($injectSecurityAttributes)
179+
{
180+
my $libSecAttrs = "$lib/SecurityAttributes";
181+
CopyAssemblies("$securityAttributesPath/bin", $libSecAttrs);
182+
cp("$root/mcs/tools/security/sn.exe $libSecAttrs/");
183+
}
184+
}
185+
186+
my $monoprefixUnity = "$monoprefix/lib/mono/unity";
187+
my $monodistroLibMono = "$monodistro/lib/mono";
188+
my $monodistroUnity = "$monodistroLibMono/unity";
189+
my $monoprefixUnityWeb = "$monoprefix/lib/mono/unity_web";
190+
my $monodistroUnityWeb = "$monodistro/lib/mono/unity_web";
191+
192+
sub UnityBooc
193+
{
194+
my $commandLine = shift;
195+
196+
system("$monoprefixUnity/booc -debug- $commandLine") eq 0 or die("booc failed to execute: $commandLine");
197+
}
198+
199+
sub BuildUnityScriptForUnity
200+
{
201+
my $booCheckout = "external/boo";
202+
203+
GitClone("git://github.com/bamboo/boo.git", $booCheckout);
204+
UnityXBuild("$booCheckout/src/booc/booc.csproj");
205+
206+
cp("$booCheckout/ide-build/Boo.Lang*.dll $monoprefixUnity/");
207+
cp("$booCheckout/ide-build/booc.exe $monoprefixUnity/");
208+
UnityBooc("-out:$monoprefixUnity/Boo.Lang.Extensions.dll -noconfig -nostdlib -srcdir:$booCheckout/src/Boo.Lang.Extensions -r:System.dll -r:mscorlib.dll -r:Boo.Lang.dll");
209+
UnityBooc("-out:$monoprefixUnity/Boo.Lang.Useful.dll -srcdir:$booCheckout/src/Boo.Lang.Useful -r:Boo.Lang.Parser");
210+
UnityBooc("-out:$monoprefixUnity/Boo.Lang.PatternMatching.dll -srcdir:$booCheckout/src/Boo.Lang.PatternMatching");
211+
212+
# micro profile version
213+
UnityXBuild("$booCheckout/src/Boo.Lang/Boo.Lang.csproj", "Micro-Release");
214+
cp("$booCheckout/src/Boo.Lang/bin/Micro-Release/Boo.Lang.dll $monodistroLibMono/micro/");
215+
216+
my $usCheckout = "external/unityscript";
217+
GitClone("git://github.com/bamboo/unityscript.git", $usCheckout);
218+
219+
my $UnityScriptLangDLL = "$monoprefixUnity/UnityScript.Lang.dll";
220+
UnityBooc("-out:$UnityScriptLangDLL -srcdir:$usCheckout/src/UnityScript.Lang");
221+
222+
my $UnityScriptDLL = "$monoprefixUnity/UnityScript.dll";
223+
UnityBooc("-out:$UnityScriptDLL -srcdir:$usCheckout/src/UnityScript -r:$UnityScriptLangDLL -r:Boo.Lang.Parser.dll -r:Boo.Lang.PatternMatching.dll");
224+
UnityBooc("-out:$monoprefixUnity/us.exe -srcdir:$usCheckout/src/us -r:$UnityScriptLangDLL -r:$UnityScriptDLL -r:Boo.Lang.Useful.dll");
225+
226+
# unityscript test suite
227+
my $UnityScriptTestsCSharpDLL = "$usCheckout/src/UnityScript.Tests.CSharp/bin/Debug/UnityScript.Tests.CSharp.dll";
228+
UnityXBuild("$usCheckout/src/UnityScript.Tests.CSharp/UnityScript.Tests.CSharp.csproj", "Debug");
229+
230+
my $usBuildDir = "$usCheckout/build";
231+
mkdir($usBuildDir);
232+
233+
my $UnityScriptTestsDLL = <$usBuildDir/UnityScript.Tests.dll>;
234+
UnityBooc("-out:$UnityScriptTestsDLL -srcdir:$usCheckout/src/UnityScript.Tests -r:$UnityScriptLangDLL -r:$UnityScriptDLL -r:$UnityScriptTestsCSharpDLL -r:Boo.Lang.Compiler.dll -r:Boo.Lang.Useful.dll");
235+
236+
cp("$UnityScriptTestsCSharpDLL $usBuildDir/");
237+
cp("$monoprefixUnity/Boo.* $usBuildDir/");
238+
cp("$monoprefixUnity/UnityScript.* $usBuildDir/");
239+
cp("$monoprefixUnity/us.exe $usBuildDir/");
240+
241+
system(<$monoprefix/bin/nunit-console2>, "-noshadow", "-exclude=FailsOnMono", $UnityScriptTestsDLL) eq 0 or die("UnityScript test suite failed");
242+
}
243+
244+
sub UnityXBuild
245+
{
246+
my $projectFile = shift;
247+
248+
my $optionalConfiguration = shift;
249+
my $configuration = defined($optionalConfiguration) ? $optionalConfiguration : "Release";
250+
251+
my $target = "Rebuild";
252+
my $commandLine = "$monoprefix/bin/xbuild $projectFile /p:CscToolExe=smcs /p:CscToolPath=$monoprefixUnity /p:MonoTouch=True /t:$target /p:Configuration=$configuration /p:AssemblySearchPaths=$monoprefixUnity";
253+
254+
system($commandLine) eq 0 or die("Failed to xbuild '$projectFile' for unity");
255+
}
256+
257+
sub GitClone
258+
{
259+
my $repo = shift;
260+
my $localFolder = shift;
261+
if (-d $localFolder) {
262+
return;
263+
}
264+
system("git clone $repo $localFolder") eq 0 or die("git clone $repo $localFolder failed!");
265+
}
266+
267+
sub BuildCecilForUnity
268+
{
269+
my $useCecilLight = 0;
270+
271+
my $cecilCheckout = "mcs/class/Mono.Cecil";
272+
273+
if ($useCecilLight) {
274+
275+
$cecilCheckout = "external/cecil";
276+
GitClone("git://github.com/lucasmeijer/cecil.git", $cecilCheckout);
277+
278+
}
279+
280+
UnityXBuild("$cecilCheckout/Mono.Cecil.csproj");
281+
cp("$cecilCheckout/bin/Release/Mono.Cecil.dll $monoprefixUnity/");
282+
283+
}
284+
285+
sub AddRequiredExecutePermissionsToUnity
286+
{
287+
my @scripts = ("smcs", "booc", "us");
288+
for my $script (@scripts) {
289+
chmod(0777, $monoprefixUnity . "/$script");
290+
}
291+
}
292+
293+
sub RunCSProj
294+
{
295+
my $csprojnoext = shift;
296+
297+
XBuild("$csprojnoext.csproj");
298+
299+
my $dir = dirname($csprojnoext);
300+
my $basename = basename($csprojnoext);
301+
my $exe = "$dir/bin/Debug/$basename.exe";
302+
303+
my @args = ();
304+
push(@args,"$monoprefix/bin/cli");
305+
push(@args,$exe);
306+
307+
print("Starting $exer\n");
308+
my $ret = system(@args);
309+
print("$exe finished. exitcode: $ret\n");
310+
$ret eq 0 or die("Failed running $exe");
311+
}
312+
313+
sub RunLinker()
314+
{
315+
RunCSProj("tuning/UnityProfileShaper/UnityProfileShaper");
316+
}
317+
318+
sub RunSecurityInjection
319+
{
320+
RunCSProj("tuning/SecurityAttributes/DetectMethodPrivileges/DetectMethodPrivileges");
321+
}
322+
323+
sub CopyUnityScriptAndBooFromUnityProfileTo20
324+
{
325+
my $twozeroprofile = "$monodistro/lib/mono/2.0";
326+
system("cp $monodistroUnity/Boo* $twozeroprofile/") && die("failed copying");
327+
system("cp $monodistroUnity/boo* $twozeroprofile/") && die("failed copying");
328+
system("cp $monodistroUnity/us* $twozeroprofile/") && die("failed copying");
329+
system("cp $monodistroUnity/UnityScript* $twozeroprofile/") && die("failed copying");
330+
331+
}
332+
333+
334+
if ($unity)
335+
{
336+
CopyProfileAssembliesToPrefix("unity", "unity", $monoprefix);
337+
338+
AddRequiredExecutePermissionsToUnity();
339+
BuildUnityScriptForUnity();
340+
BuildCecilForUnity();
341+
342+
CopyAssemblies($monoprefixUnity,$monodistroUnity);
343+
#now, we have a functioning, raw, unity profile in builds/monodistribution/lib/mono/unity
344+
#we're now going to transform that into the unity_web profile by running it trough the linker, and decorating it with security attributes.
345+
346+
CopyUnityScriptAndBooFromUnityProfileTo20();
347+
348+
RunLinker();
349+
RunSecurityInjection();
350+
}
351+
352+
#Overlaying files
353+
CopyIgnoringHiddenFiles("add_to_build_results/", "$root/builds/");
354+
355+
#zip up the results for teamcity
356+
chdir("$root/builds");
357+
system("tar -hpczf ../ZippedClasslibs.tar.gz *") && die("Failed to zip up classlibs for teamcity");

0 commit comments

Comments
 (0)