forked from WebKit/WebKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-webkit
executable file
·445 lines (367 loc) · 16.6 KB
/
build-webkit
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
#!/usr/bin/env perl
# Copyright (C) 2005-2019 Apple Inc. All rights reserved.
# Copyright (C) 2009 Google Inc. All rights reserved.
# Copyright (C) 2010 moiji-mobile.com All rights reserved.
# Copyright (C) 2011 Research In Motion Limited. All rights reserved.
# Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. Neither the name of Apple Inc. ("Apple") nor the names of
# its contributors may be used to endorse or promote products derived
# from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Build script wrapper for the WebKit Open Source Project.
use strict;
use warnings;
use File::Basename;
use File::Find;
use File::Spec;
use FindBin;
use Getopt::Long qw(:config pass_through no_auto_abbrev);
use lib $FindBin::Bin;
use webkitdirs;
use List::Util qw(first);
use webkitperl::FeatureList qw(getFeatureOptionList);
use POSIX;
use Text::ParseWords;
sub writeCongrats();
checkRequiredSystemConfig();
setConfiguration();
if (shouldBuildForCrossTarget()) {
print("Enabling cross-build for target machine: '". getCrossTargetName() . "'\n");
my @command = (File::Spec->catfile(sourceDir(), "Tools", "Scripts", "build-webkit"));
runInCrossTargetEnvironment(@command);
} elsif (shouldUseFlatpak()) {
print "Building flatpak based environment\n";
my @command = (File::Spec->catfile(sourceDir(), "Tools", "Scripts", "build-webkit"));
runInFlatpak(@command);
}
my $originalWorkingDirectory = getcwd();
chdirWebKit();
my $showHelp = 0;
my $verbose = 0;
my $clean = 0;
my $minimal = 0;
my $installHeaders;
my $installLibs;
my $prefixPath;
my $makeArgs = "";
my @cmakeArgs;
my $onlyWebKitProject = 0;
my $coverageSupport = 0;
my $shouldRunStaticAnalyzer = 0;
my $noExperimentalFeatures = 0;
my $ltoMode = "default";
my $useWorkspace = 1;
my $startTime = time();
my $archs32bit = 0;
my $skipLibraryUpdate = 0;
my $useCCache = -1;
my $exportCompileCommands = 0;
my @features = getFeatureOptionList();
# Additional environment parameters
push @ARGV, parse_line('\s+', 0, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
# Initialize values from defaults
foreach (@ARGV) {
if ($_ eq '--minimal') {
$minimal = 1;
} elsif ($_ eq 'ARCHS=i386' or $_ eq 'ARCHS=armv7' or $_ eq 'ARCHS=armv7s') {
$archs32bit = 1;
}
}
# Feature flags default to undefined, where they will inherit the default value
# specified by the build system, or to 'off' if --minimal is specified.
foreach (@features) {
${$_->{value}} = ($minimal ? 0 : undef);
}
my $programName = basename($0);
my $usage = <<EOF;
Usage: $programName [options] [options to pass to build system]
-h, --help Show this help message
-v, --verbose Show verbose build output
--clean Cleanup the build directory
--generate-project-only Only generate project files
--debug Compile with Debug configuration
--release Compile with Release configuration
--sdk=<sdk> Use a specific Xcode SDK (Apple platforms only)
--ios-device Use "iphoneos.internal" SDK if installed, else "iphoneos" SDK (iOS only)
--device DEPRECATED alias of --ios-device
--ios-simulator Use "iphonesimulator.internal" SDK if installed, else "iphonesimulator" SDK (iOS only)
--simulator DEPRECATED alias of --ios-simulator
--tvos-device Use "appletvos.internal" SDK if installed, else "appletvos" SDK (tvOS only)
--tvos-simulator Use "appletvsimulator" (tvOS only)
--watchos-device Use "watchos.internal" SDK if installed, else "watchos" SDK (watchOS only)
--watchos-simulator Use "watchsimulator" (watchOS only)
--coverage Enable code coverage support (Mac only)
--analyze Enable static anaylsis (Apple platforms only)
--lto-mode=<mode> Set Link Time Optimization mode (full, thin, or none) (LLVM only)
--no-use-workspace Build projects one at a time instead of using WebKit.xcworkspace (Apple platforms only)
--cross-target=<target_machine> Use the cross-toolchain-helper to build WebKit for the specified machine (Linux platforms only)
--gtk Build the GTK+ port
--wpe Build the WPE port
--wincairo Build the Windows port
--playstation Build the PlayStation port
--inspector-frontend Copy Web Inspector user interface resources to the build directory
--prefix=<path> Set installation prefix to the given path (CMake only, except Windows)
--makeargs=<arguments> Optional Makefile flags
--cmakeargs=<arguments> One or more optional CMake flags (e.g. --cmakeargs="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
--minimal No optional features, unless explicitly enabled
--no-experimental-features No experimental features, unless explicitly enabled (CMake only)
--only-webkit Build only the WebKit project
--skip-library-update Skip the check to see if windows libraries are up to date
--[no-]use-ccache Enable (or disable) CCache, if available
--export-compile-commands Generate compile_commands.json (Apple platforms only)
EOF
my %options = (
'h|help' => \$showHelp,
'v|verbose' => \$verbose,
'clean' => \$clean,
'install-headers=s' => \$installHeaders,
'install-libs=s' => \$installLibs,
'prefix=s' => \$prefixPath,
'makeargs=s' => \$makeArgs,
'cmakeargs=s' => \@cmakeArgs,
'minimal' => \$minimal,
'only-webkit' => \$onlyWebKitProject,
'coverage' => \$coverageSupport,
'analyze' => \$shouldRunStaticAnalyzer,
'no-experimental-features' => \$noExperimentalFeatures,
'lto-mode=s' => \$ltoMode,
'use-workspace!' => \$useWorkspace,
'skip-library-update' => \$skipLibraryUpdate,
'use-ccache!' => \$useCCache,
'export-compile-commands' => \$exportCompileCommands
);
# Build usage text and options list from features
foreach (@features) {
my $opt = sprintf("%-35s", " --[no-]$_->{option}");
$usage .= "$opt $_->{desc}\n";
$options{"$_->{option}!"} = $_->{value};
}
GetOptions(%options);
if ($showHelp) {
print STDERR $usage;
exit 1;
}
$ENV{'VERBOSE'} = 1 if $verbose;
if ($useCCache == 1) {
$ENV{'WK_USE_CCACHE'} = "YES";
} elsif ($useCCache == 0) {
$ENV{'WK_USE_CCACHE'} = "NO";
}
$ENV{'EXPORT_COMPILE_COMMANDS'} = "YES" if $exportCompileCommands;
my $productDir = productDir();
# Check that all the project directories are there.
my @projects = ("Source/JavaScriptCore");
if (isAppleCocoaWebKit()) {
push @projects, ("Source/WebGPU");
}
push @projects, ("Source/WebCore");
push @projects, ("Source/WebKitLegacy");
# Build WTF as a separate static library on ports which support it.
splice @projects, 0, 0, "Source/WTF" if isWinCairo();
splice @projects, 0, 0, "Source/bmalloc" if isAppleCocoaWebKit();
# Ports using CMake will check if directories exist in the CMake configuration.
if (!isCMakeBuild()) {
for my $dir (@projects) {
if (! -d $dir) {
die "Error: No $dir directory found. Please do a fresh checkout.\n";
}
}
}
if ((isAppleWebKit() || isWinCairo() || isPlayStation()) && !-d "WebKitLibraries") {
die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
}
my @options = ();
if (isAppleCocoaWebKit()) {
if (!$useWorkspace) {
# Ignore any workspace set by set-webkit-configuration
overrideConfiguredXcodeWorkspace("");
}
if (xcodeVersion() ge "13.3" && xcodeVersion() lt "15.0" && !defined($ENV{UseSRCROOTSupportForTAPI})) {
# The call to XcodeOptions below checks this environment variable and
# sets TAPI_USE_SRCROOT for xcconfigs.
$ENV{UseSRCROOTSupportForTAPI} = "YES";
}
push @options, XcodeOptions();
sub option($$)
{
my ($feature, $isEnabled) = @_;
return "" if not defined $isEnabled;
return $feature . "=" . ($isEnabled ? $feature : "");
}
foreach (@features) {
my $option = option($_->{define}, ${$_->{value}});
push @options, $option unless $option eq "";
}
# In workspaces, build order is determined by XCBuild.
if (!$useWorkspace) {
print STDERR "warning: Building with --no-use-workspace is " .
"deprecated.\nIf you have a workflow requirement that depends " .
"on building targets in manual order, please document it in " .
"https://bugs.webkit.org/show_bug.cgi?id=241295.\n";
# ANGLE and libwebrtc must come before WebCore
splice @projects, 0, 0, ("Source/ThirdParty/ANGLE");
# if (not $archs32bit and (portName() eq Mac or portName() eq iOS or portName() eq watchOS)) {
if (portName() eq Mac or portName() eq iOS) {
splice @projects, 0, 0, ("Source/ThirdParty/libwebrtc");
}
push @projects, ("Source/WebKit");
if (!isEmbeddedWebKit()) {
push @projects, ("Tools/MiniBrowser");
# WebInspectorUI must come after JavaScriptCore and WebCore but before WebKit and WebKit2
my $webKitIndex = first { $projects[$_] eq "Source/WebKitLegacy" } 0..$#projects;
splice(@projects, $webKitIndex, 0, "Source/WebInspectorUI");
}
if (isAppleMacWebKit()) {
push @projects, ("Tools/lldb/lldbWebKitTester");
}
# Build Tools needed for Apple ports (except for tvOS)
push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
}
} elsif (isWinCairo() && !$skipLibraryUpdate) {
(system("python Tools/Scripts/update-webkit-wincairo-libs.py") == 0) or die;
}
# If asked to build just the WebKit project, overwrite the projects
# list after all of the port specific tweaks have been made to
# build options, etc.
@projects = ("Source/WebKitLegacy") if $onlyWebKitProject;
my $result = 0;
if (isInspectorFrontend()) {
die "The --inspector-frontend option is not supported for CMake-based builds." if isCMakeBuild();
@projects = ("Source/WebInspectorUI");
}
if (isCMakeBuild() && !isAnyWindows()) {
if (!canUseNinja() || defined($ENV{NUMBER_OF_PROCESSORS})) {
# If the user environment is not setting a specific number of process,
# then don't pass the number of jobs to Ninja. Because Ninja will
# automatically determine the number of jobs to run in parallel.
$makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
}
my $maxCPULoad = maxCPULoad() if $makeArgs !~ /-l\s*\d+\.?\d*/;
$makeArgs .= " -l" . maxCPULoad() if defined $maxCPULoad;
# We remove CMakeCache to avoid the bots reusing cached flags when
# we enable new features. This forces a reconfiguration.
my @featureArgs = cmakeArgsFromFeatures(@features, !$noExperimentalFeatures);
removeCMakeCache(@featureArgs);
buildCMakeProjectOrExit($clean, $prefixPath, $makeArgs, @featureArgs, @cmakeArgs);
}
my $baseProductDir = baseProductDir();
if (isWinCairo() || isPlayStation()) {
my @featureArgs = cmakeArgsFromFeatures(@features, !$noExperimentalFeatures);
removeCMakeCache(@featureArgs);
chdirWebKit();
if (exitStatus(generateBuildSystemFromCMakeProject($prefixPath, @featureArgs, @cmakeArgs))) {
die "Run Visual Studio installation vcvars.bat before build-webkit when using ninja";
}
exit 0 if isGenerateProjectOnly();
chdirWebKit();
if (canUseNinja()) {
chdir File::Spec->catdir($baseProductDir, configuration());
$result = system("ninja");
} else {
$result = buildVisualStudioProject(File::Spec->catfile($baseProductDir, configuration(), "WebKit.sln"), $clean);
}
if (exitStatus($result)) {
exit exitStatus($result);
}
} elsif (isAppleCocoaWebKit() && !isCMakeBuild()) {
exit 0 if isGenerateProjectOnly();
my @local_options = @options;
push @local_options, XcodeCoverageSupportOptions() if $coverageSupport;
push @local_options, XcodeStaticAnalyzerOption() if $shouldRunStaticAnalyzer;
push @local_options, "WK_LTO_MODE=$ltoMode" if ($ltoMode ne "default");
# FIXME: Move this setting to xcconfigs once all local Xcode builds of WebKit
# happen in the workspace. When this is only passed on the command line, it
# invalidates build results made in the IDE (rdar://88135402).
## When we know we're in a workspace (and not an individual project), turn
## on dependency validation errors. Other conditions (e.g. whether we're in
## a script phase or not) influence the actual VALIDATE_DEPENDENCIES setting
## recognized by the build system.
#push @local_options, "WK_VALIDATE_DEPENDENCIES=YES_ERROR" if $useWorkspace;
markBaseProductDirectoryAsCreatedByXcodeBuildSystem();
# Build, and abort if the build fails.
if ($useWorkspace) {
my $scheme = $onlyWebKitProject ? "WebKitLegacy" : "Everything up to WebKit + Tools";
$result = buildXcodeScheme($scheme, $clean, @local_options, @ARGV);
if (exitStatus($result)) {
exit exitStatus($result);
}
} else {
for my $dir (@projects) {
chdir $dir or die;
$result = 0;
my $project = basename($dir);
my $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
$result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
# Various build* calls above may change the CWD.
chdirWebKit();
if (exitStatus($result)) {
exit exitStatus($result);
}
}
}
if (isInspectorFrontend()) {
exit exitStatus($result);
}
if ($clean) {
# No need to have build-imagediff do cleaning, the build directory has already been deleted.
exit exitStatus($result);
}
# Build ImageDiff for host
my @command = File::Spec->catfile(getcwd(), "/Tools/Scripts/build-imagediff");
chdirWebKit();
if (!-e $command[0]) {
die "build-imagediff script not found";
}
push @command, argumentsForConfiguration();
push @command, @ARGV;
@command = extractNonMacOSHostConfiguration(\@command);
$result = system(@command);
if (exitStatus($result)) {
exit exitStatus($result);
}
}
# Don't report the "WebKit is now built" message after a clean operation.
exit if $clean;
# Don't report congrats message if build was interrupted by the user.
exit if ($result & 127) == SIGINT;
# Explicitly chdir back to where exit will take us anyway, since the following "launcher"
# message is relative to that directory.
chdir $originalWorkingDirectory;
# Write out congratulations message.
writeCongrats();
exit 0;
sub writeCongrats()
{
my $launcherPath = launcherPath();
my $launcherName = launcherName();
my $endTime = time();
my $buildTime = formatBuildTime($endTime - $startTime);
print "\n";
print "====================================================================\n";
print " WebKit is now built ($buildTime). \n";
if ($launcherPath && $launcherName) {
print " To run $launcherName with this newly-built code, use the\n";
print " \"$launcherPath\" script.\n";
}
print "====================================================================\n";
}