-
Notifications
You must be signed in to change notification settings - Fork 19
/
build_win_wrapper.pl
218 lines (195 loc) · 6 KB
/
build_win_wrapper.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
use Cwd;
use Cwd 'abs_path';
use Getopt::Long;
use File::Basename;
use File::Path;
use Config;
print ">>> My Path: $ENV{PATH}\n\n";
my $monoroot = File::Spec->rel2abs(dirname(__FILE__) . "/../..");
my $monoroot = abs_path($monoroot);
my $buildScriptsRoot = "$monoroot/external/buildscripts";
print ">>> Mono checkout found in $monoroot\n\n";
my $cygwinRootWindows = "";
my $monoInstallLinux = "";
my $checkoutOnTheFly=0;
my $buildDeps = "";
my $forceDefaultBuildDeps = 0;
my @thisScriptArgs = ();
my @passAlongArgs = ();
foreach my $arg (@ARGV)
{
push @backupArgs, $arg;
if ($arg =~ /^--cygwin=/)
{
push @thisScriptArgs, $arg;
}
elsif ($arg =~ /^--existingmono=/)
{
push @thisScriptArgs, $arg;
}
elsif ($arg =~ /^--checkoutonthefly=/)
{
push @thisScriptArgs, $arg;
push @passAlongArgs, $arg;
}
elsif ($arg =~ /^--builddeps=/)
{
push @thisScriptArgs, $arg;
push @passAlongArgs, $arg;
}
elsif ($arg =~ /^--forcedefaultbuilddeps=/)
{
push @thisScriptArgs, $arg;
push @passAlongArgs, $arg;
}
else
{
push @passAlongArgs, $arg;
}
}
print(">>> This Script Args = @thisScriptArgs\n");
print(">>> Pass Along Args = @passAlongArgs\n");
@ARGV = @thisScriptArgs;
GetOptions(
'cygwin=s'=>\$cygwinRootWindows,
'existingmono=s'=>\$monoInstallLinux,
'checkoutonthefly=i'=>\$checkoutOnTheFly,
'builddeps=s'=>\$buildDeps,
'forcedefaultbuilddeps=i'=>\$forceDefaultBuildDeps,
);
my $externalBuildDeps = "";
if ($buildDeps ne "")
{
$externalBuildDeps = $buildDeps;
}
else
{
if (-d "$monoroot/external/mono-build-deps" || $forceDefaultBuildDeps)
{
$externalBuildDeps = "$monoroot/external/mono-build-deps";
}
if (!(-d "$externalBuildDeps"))
{
if (not $checkoutonthefly && $cygwinRootWindows eq "")
{
print(">>> No external build deps found and --cygwin not used. Might as well try to check them out. If the checkout fails, we'll continue, but the build will probably fail\n");
}
# Check out on the fly
print(">>> Checking out mono build dependencies to : $externalBuildDeps\n");
my $repo = "https://ono.unity3d.com/unity-extra/mono-build-deps";
print(">>> Cloning $repo at $externalBuildDeps\n");
my $checkoutResult = system("hg", "clone", $repo, "$externalBuildDeps");
if ($checkoutOnTheFly && $checkoutResult ne 0)
{
die("failed to checkout mono build dependencies\n");
}
}
}
print(">>> externalBuildDeps = $externalBuildDeps\n");
my $SevenZip = "$externalBuildDeps/7z/win64/7za.exe";
# Attempt to find common default cygwin install locations
if ($cygwinRootWindows eq "")
{
print(">>> No cygwin install specified. Looking for defaults...\n");
my $externalCygwin = "$externalBuildDeps/cygwin64/builds";
my $externalCygwinZip = "$externalBuildDeps/cygwin64/builds.zip";
if (-d "$externalCygwin")
{
$cygwinRootWindows = $externalCygwin;
print(">>> Found Cygwin at : $cygwinRootWindows\n");
}
elsif(-f "$externalCygwinZip")
{
print(">>> Found unextracted cygwin builds.zip : $externalCygwinZip\n");
print(">>> Using 7z : $SevenZip\n");
print(">>> Extracting...\n");
system("$SevenZip", "x", "$externalCygwinZip", "-o$externalBuildDeps/cygwin64") eq 0 or die("Failed extracting cygwin\n");
$cygwinRootWindows = $externalCygwin;
}
else
{
if ($forceDefaultBuildDeps)
{
die("\nCould not fined Cygwin in default external build deps location : $externalBuildDeps\n")
}
else
{
if (-d "C:\\Cygwin64")
{
$cygwinRootWindows = "C:\\Cygwin64";
print(">>> Found Cygwin at : $cygwinRootWindows\n");
}
elsif (-d "C:\\Cygwin")
{
$cygwinRootWindows = "C:\\Cygwin";
print(">>> Found Cygwin at : $cygwinRootWindows\n");
}
else
{
die("\nCould not fined Cygwin. Define path using --cygwin=<path>\n")
}
}
}
}
else
{
print(">>> Cygwin Path = $cygwinRootWindows\n");
}
if ($monoInstallLinux eq "")
{
print(">>> No mono install specified. Looking for defaults...\n");
my $externalMono = "$externalBuildDeps/mono/win/builds";
my $externalMonoZip = "$externalBuildDeps/mono/win/builds.zip";
if (-d "$externalMono")
{
$monoInstallLinux = $externalMono;
$monoInstallLinux =~ s/\\/\//g;
print(">>> Found Mono at : $monoInstallLinux\n");
}
elsif(-f "$externalMonoZip")
{
print(">>> Found unextracted mono builds.zip : $externalMonoZip\n");
print(">>> Using 7z : $SevenZip\n");
print(">>> Extracting...\n");
system("$SevenZip", "x", "$externalMonoZip", "-o$externalBuildDeps/mono/win") eq 0 or die("Failed extracting mono\n");
$monoInstallLinux = $externalMono;
$monoInstallLinux =~ s/\\/\//g;
print(">>> Found Mono at : $monoInstallLinux\n");
}
else
{
if ($forceDefaultBuildDeps)
{
die("\nCould not fined mono in default external build deps location : $externalBuildDeps\n")
}
else
{
if (-d "C:\\Program Files (x86)\\Mono")
{
# Pass over the cygwin format since I already have it escaped correctly to survive
# crossing over the shell
$monoInstallLinux = "/cygdrive/c/Program\\ Files\\ \\(x86\\)/Mono";
print(">>> Found Mono at : $monoInstallLinux\n");
}
else
{
die("\n--existingmono=<path> is required and should be in the cygwin path format\n");
}
}
}
}
else
{
$monoInstallLinux =~ s/\\/\//g;
print(">>> Linux Mono Path = $monoInstallLinux\n");
}
push @passAlongArgs, "--existingmono=$monoInstallLinux" if $monoInstallLinux ne "";
my $windowsPerl = $Config{perlpath};
print ">>> Perl Exe = $windowsPerl\n";
push @passAlongArgs, "--winperl=$windowsPerl";
push @passAlongArgs, "--winmonoroot=$monoroot";
# In some cases the file gets windowsified, to prevent issues in these cases, dos2unix the shell wrapper script before we run it
print ">>> Calling $cygwinRootWindows\\bin\\dos2unix.exe $monoroot/external/buildscripts/build_win_wrapper.sh";
system("$cygwinRootWindows\\bin\\dos2unix.exe", "$monoroot/external/buildscripts/build_win_wrapper.sh") eq 0 or die("failed building mono\n");
print ">>> Calling $cygwinRootWindows\\bin\\sh.exe with @passAlongArgs";
system("$cygwinRootWindows\\bin\\sh.exe", "$monoroot/external/buildscripts/build_win_wrapper.sh", @passAlongArgs) eq 0 or die("failed building mono\n");