blob: b4e8c0496caa9912bf9b7e0d9a8db03161b70e7c [file] [log] [blame]
commit-queue@webkit.org026ee042018-01-04 07:18:18 +00001#!/usr/bin/env perl
mitz@apple.com10955a5a2010-12-18 00:02:12 +00002
bfulgham@apple.com28e3e642019-09-20 04:55:55 +00003# Copyright (C) 2005-2019 Apple Inc. All rights reserved.
mitz@apple.com10955a5a2010-12-18 00:02:12 +00004# Copyright (C) 2009 Google Inc. All rights reserved.
5# Copyright (C) 2010 moiji-mobile.com All rights reserved.
dbates@webkit.orga29f8cc2011-03-14 18:23:24 +00006# Copyright (C) 2011 Research In Motion Limited. All rights reserved.
marcelo.lira@openbossa.orge8121e02013-11-27 06:05:27 +00007# Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
mitz@apple.com10955a5a2010-12-18 00:02:12 +00008#
9# Redistribution and use in source and binary forms, with or without
10# modification, are permitted provided that the following conditions
11# are met:
12#
13# 1. Redistributions of source code must retain the above copyright
14# notice, this list of conditions and the following disclaimer.
15# 2. Redistributions in binary form must reproduce the above copyright
16# notice, this list of conditions and the following disclaimer in the
17# documentation and/or other materials provided with the distribution.
mjs@apple.com92047332014-03-15 04:08:27 +000018# 3. Neither the name of Apple Inc. ("Apple") nor the names of
mitz@apple.com10955a5a2010-12-18 00:02:12 +000019# its contributors may be used to endorse or promote products derived
20# from this software without specific prior written permission.
21#
22# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
23# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
26# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
29# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33# Build script wrapper for the WebKit Open Source Project.
34
35use strict;
commit-queue@webkit.org026ee042018-01-04 07:18:18 +000036use warnings;
mitz@apple.com10955a5a2010-12-18 00:02:12 +000037use File::Basename;
38use File::Find;
39use File::Spec;
40use FindBin;
marcelo.lira@openbossa.orge8121e02013-11-27 06:05:27 +000041use Getopt::Long qw(:config pass_through no_auto_abbrev);
mitz@apple.com10955a5a2010-12-18 00:02:12 +000042use lib $FindBin::Bin;
43use webkitdirs;
dbates@webkit.orgfb315be2014-01-10 23:36:58 +000044use List::Util qw(first);
eric@webkit.org19dfb112012-05-04 01:06:47 +000045use webkitperl::FeatureList qw(getFeatureOptionList);
mitz@apple.com10955a5a2010-12-18 00:02:12 +000046use POSIX;
commit-queue@webkit.orgc167b962020-01-08 14:07:49 +000047use Text::ParseWords;
mitz@apple.com10955a5a2010-12-18 00:02:12 +000048
mitz@apple.com10955a5a2010-12-18 00:02:12 +000049sub writeCongrats();
50
commit-queue@webkit.orgbe882f62018-06-29 17:47:17 +000051checkRequiredSystemConfig();
52setConfiguration();
53
54if (shouldUseFlatpak()) {
55 print "Building flatpak based environment\n";
philn@webkit.org7ee60562020-03-18 09:54:55 +000056 my @command = (File::Spec->catfile(sourceDir(), "Tools", "Scripts", "build-webkit"));
57 runInFlatpak(@command);
commit-queue@webkit.orgbe882f62018-06-29 17:47:17 +000058}
59
mitz@apple.com10955a5a2010-12-18 00:02:12 +000060my $originalWorkingDirectory = getcwd();
61chdirWebKit();
62
63my $showHelp = 0;
timothy_horton@apple.comf1f0f5d2017-09-27 01:00:31 +000064my $verbose = 0;
mitz@apple.com10955a5a2010-12-18 00:02:12 +000065my $clean = 0;
66my $minimal = 0;
mitz@apple.com10955a5a2010-12-18 00:02:12 +000067my $installHeaders;
68my $installLibs;
69my $prefixPath;
dbates@webkit.orga29f8cc2011-03-14 18:23:24 +000070my $makeArgs = "";
ossy@webkit.orgac40d532016-08-09 09:11:06 +000071my @cmakeArgs;
joepeck@webkit.orga24df342011-05-05 17:49:53 +000072my $onlyWebKitProject = 0;
eric@webkit.org6983a0d2012-05-03 23:09:41 +000073my $coverageSupport = 0;
dbates@webkit.orgdf85a292014-07-28 20:48:50 +000074my $shouldRunStaticAnalyzer = 0;
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +000075my $noExperimentalFeatures = 0;
krollin@apple.com2ba23ff2018-08-27 17:16:17 +000076my $ltoMode = "default";
emw@apple.comc6719492022-06-13 19:20:59 +000077my $useWorkspace = 1;
mitz@apple.com10955a5a2010-12-18 00:02:12 +000078my $startTime = time();
achristensen@apple.comec67bb62017-02-28 07:11:13 +000079my $archs32bit = 0;
commit-queue@webkit.org5eb4a622017-10-17 02:30:58 +000080my $skipLibraryUpdate = 0;
timothy_horton@apple.comc1e6d8d2017-10-21 21:42:51 +000081my $useCCache = -1;
commit-queue@webkit.org99d26d42022-02-20 16:01:42 +000082my $exportCompileCommands = 0;
mitz@apple.com10955a5a2010-12-18 00:02:12 +000083
eric@webkit.org19dfb112012-05-04 01:06:47 +000084my @features = getFeatureOptionList();
mitz@apple.com10955a5a2010-12-18 00:02:12 +000085
mitz@apple.com10955a5a2010-12-18 00:02:12 +000086# Additional environment parameters
commit-queue@webkit.orgc167b962020-01-08 14:07:49 +000087push @ARGV, parse_line('\s+', 0, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
mitz@apple.com10955a5a2010-12-18 00:02:12 +000088
89# Initialize values from defaults
90foreach (@ARGV) {
91 if ($_ eq '--minimal') {
92 $minimal = 1;
achristensen@apple.comec67bb62017-02-28 07:11:13 +000093 } elsif ($_ eq 'ARCHS=i386' or $_ eq 'ARCHS=armv7' or $_ eq 'ARCHS=armv7s') {
94 $archs32bit = 1;
mitz@apple.com10955a5a2010-12-18 00:02:12 +000095 }
96}
97
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +000098# Feature flags default to undefined, where they will inherit the default value
99# specified by the build system, or to 'off' if --minimal is specified.
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000100foreach (@features) {
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000101 ${$_->{value}} = ($minimal ? 0 : undef);
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000102}
103
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000104my $programName = basename($0);
105my $usage = <<EOF;
106Usage: $programName [options] [options to pass to build system]
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000107 -h, --help Show this help message
108 -v, --verbose Show verbose build output
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000109 --clean Cleanup the build directory
commit-queue@webkit.orgebcbe062017-07-21 16:02:22 +0000110 --generate-project-only Only generate project files
commit-queue@webkit.org941fbe62013-02-09 19:09:03 +0000111 --debug Compile with Debug configuration
112 --release Compile with Release configuration
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000113 --sdk=<sdk> Use a specific Xcode SDK (Apple platforms only)
jbedard@apple.com46dabb72017-03-09 19:46:19 +0000114 --ios-device Use "iphoneos.internal" SDK if installed, else "iphoneos" SDK (iOS only)
115 --device DEPRECATED alias of --ios-device
jbedard@apple.comc1075452018-06-07 16:24:49 +0000116 --ios-simulator Use "iphonesimulator.internal" SDK if installed, else "iphonesimulator" SDK (iOS only)
jbedard@apple.com46dabb72017-03-09 19:46:19 +0000117 --simulator DEPRECATED alias of --ios-simulator
jbedard@apple.com6c6fca22020-06-04 19:42:08 +0000118 --tvos-device Use "appletvos.internal" SDK if installed, else "appletvos" SDK (tvOS only)
119 --tvos-simulator Use "appletvsimulator" (tvOS only)
120 --watchos-device Use "watchos.internal" SDK if installed, else "watchos" SDK (watchOS only)
121 --watchos-simulator Use "watchsimulator" (watchOS only)
dbates@webkit.orgdf85a292014-07-28 20:48:50 +0000122 --coverage Enable code coverage support (Mac only)
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000123 --analyze Enable static anaylsis (Apple platforms only)
chris.reid@sony.com0f616ac2019-05-02 23:39:35 +0000124 --lto-mode=<mode> Set Link Time Optimization mode (full, thin, or none) (LLVM only)
emw@apple.comc6719492022-06-13 19:20:59 +0000125 --no-use-workspace Build projects one at a time instead of using WebKit.xcworkspace (Apple platforms only)
paroga@webkit.orgbe8cbfb2011-01-03 21:04:17 +0000126
bfulgham@apple.com28e3e642019-09-20 04:55:55 +0000127 --ftw Build the FTW Windows port
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000128 --gtk Build the GTK+ port
zandobersek@gmail.com75ce5872017-05-09 11:07:57 +0000129 --wpe Build the WPE port
paroga@webkit.orgbe8cbfb2011-01-03 21:04:17 +0000130 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
don.olmstead@sony.comb837f672018-10-31 04:00:45 +0000131 --playstation Build the PlayStation port
paroga@webkit.orgbe8cbfb2011-01-03 21:04:17 +0000132
burg@cs.washington.edu148b17a2014-08-28 19:19:33 +0000133 --inspector-frontend Copy Web Inspector user interface resources to the build directory
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000134
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000135 --prefix=<path> Set installation prefix to the given path (CMake only, except Windows)
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000136 --makeargs=<arguments> Optional Makefile flags
ossy@webkit.orgac40d532016-08-09 09:11:06 +0000137 --cmakeargs=<arguments> One or more optional CMake flags (e.g. --cmakeargs="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000138
thakis@chromium.org00499452011-05-02 17:54:33 +0000139 --minimal No optional features, unless explicitly enabled
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000140 --no-experimental-features No experimental features, unless explicitly enabled (CMake only)
thakis@chromium.org00499452011-05-02 17:54:33 +0000141
joepeck@webkit.orga24df342011-05-05 17:49:53 +0000142 --only-webkit Build only the WebKit project
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000143
commit-queue@webkit.org5eb4a622017-10-17 02:30:58 +0000144 --skip-library-update Skip the check to see if windows libraries are up to date
145
timothy_horton@apple.comc1e6d8d2017-10-21 21:42:51 +0000146 --[no-]use-ccache Enable (or disable) CCache, if available
147
commit-queue@webkit.org99d26d42022-02-20 16:01:42 +0000148 --export-compile-commands Generate compile_commands.json (Apple platforms only)
149
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000150EOF
151
152my %options = (
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000153 'h|help' => \$showHelp,
timothy_horton@apple.comf1f0f5d2017-09-27 01:00:31 +0000154 'v|verbose' => \$verbose,
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000155 'clean' => \$clean,
156 'install-headers=s' => \$installHeaders,
157 'install-libs=s' => \$installLibs,
158 'prefix=s' => \$prefixPath,
159 'makeargs=s' => \$makeArgs,
ossy@webkit.orgac40d532016-08-09 09:11:06 +0000160 'cmakeargs=s' => \@cmakeArgs,
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000161 'minimal' => \$minimal,
joepeck@webkit.orga24df342011-05-05 17:49:53 +0000162 'only-webkit' => \$onlyWebKitProject,
eric@webkit.org6983a0d2012-05-03 23:09:41 +0000163 'coverage' => \$coverageSupport,
dbates@webkit.orgdf85a292014-07-28 20:48:50 +0000164 'analyze' => \$shouldRunStaticAnalyzer,
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000165 'no-experimental-features' => \$noExperimentalFeatures,
krollin@apple.com2ba23ff2018-08-27 17:16:17 +0000166 'lto-mode=s' => \$ltoMode,
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000167 'use-workspace!' => \$useWorkspace,
timothy_horton@apple.comc1e6d8d2017-10-21 21:42:51 +0000168 'skip-library-update' => \$skipLibraryUpdate,
169 'use-ccache!' => \$useCCache,
commit-queue@webkit.org99d26d42022-02-20 16:01:42 +0000170 'export-compile-commands' => \$exportCompileCommands
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000171);
172
173# Build usage text and options list from features
174foreach (@features) {
175 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000176 $usage .= "$opt $_->{desc}\n";
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000177 $options{"$_->{option}!"} = $_->{value};
178}
179
180GetOptions(%options);
181
182if ($showHelp) {
183 print STDERR $usage;
184 exit 1;
185}
186
timothy_horton@apple.comf1f0f5d2017-09-27 01:00:31 +0000187$ENV{'VERBOSE'} = 1 if $verbose;
188
timothy_horton@apple.comc1e6d8d2017-10-21 21:42:51 +0000189if ($useCCache == 1) {
190 $ENV{'WK_USE_CCACHE'} = "YES";
191} elsif ($useCCache == 0) {
192 $ENV{'WK_USE_CCACHE'} = "NO";
193}
194
commit-queue@webkit.org99d26d42022-02-20 16:01:42 +0000195$ENV{'EXPORT_COMPILE_COMMANDS'} = "YES" if $exportCompileCommands;
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000196
197my $productDir = productDir();
198
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000199# Check that all the project directories are there.
mmaxfield@apple.com4d15b9b2021-11-10 22:49:56 +0000200my @projects = ("Source/JavaScriptCore");
201if (isAppleCocoaWebKit()) {
202 push @projects, ("Source/WebGPU");
203}
204push @projects, ("Source/WebCore");
205push @projects, ("Source/WebKitLegacy");
206
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000207
eric@webkit.org159a9c72012-03-10 01:03:10 +0000208# Build WTF as a separate static library on ports which support it.
bfulgham@apple.com28e3e642019-09-20 04:55:55 +0000209splice @projects, 0, 0, "Source/WTF" if isAppleWebKit() or isWinCairo() or isFTW();
eric@webkit.org159a9c72012-03-10 01:03:10 +0000210
commit-queue@webkit.org9694ed62017-02-09 23:46:56 +0000211splice @projects, 0, 0, "Source/bmalloc" if isAppleCocoaWebKit();
ggaren@apple.com672f75e2014-04-08 05:31:41 +0000212
gyuyoung.kim@webkit.org8ad4f362016-08-13 06:11:49 +0000213# Ports using CMake will check if directories exist in the CMake configuration.
214if (!isCMakeBuild()) {
215 for my $dir (@projects) {
216 if (! -d $dir) {
217 die "Error: No $dir directory found. Please do a fresh checkout.\n";
218 }
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000219 }
220}
221
bfulgham@apple.com28e3e642019-09-20 04:55:55 +0000222if ((isAppleWebKit() || isWinCairo() || isPlayStation() || isFTW()) && !-d "WebKitLibraries") {
ossy@webkit.org443c2fb2011-04-05 15:07:22 +0000223 die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
224}
225
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000226my @options = ();
227
commit-queue@webkit.org9694ed62017-02-09 23:46:56 +0000228if (isAppleCocoaWebKit()) {
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000229 push @options, XcodeOptions();
krollin@apple.com2c6d7452019-05-07 21:38:27 +0000230
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000231 sub option($$)
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000232 {
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000233 my ($feature, $isEnabled) = @_;
234 return "" if not defined $isEnabled;
psolanki@apple.com40057812011-01-28 20:27:22 +0000235 return $feature . "=" . ($isEnabled ? $feature : "");
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000236 }
237
238 foreach (@features) {
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000239 my $option = option($_->{define}, ${$_->{value}});
eric@webkit.org6983a0d2012-05-03 23:09:41 +0000240 push @options, $option unless $option eq "";
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000241 }
242
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000243 # In workspaces, build order is determined by XCBuild.
244 if (!$useWorkspace) {
emw@apple.comc6719492022-06-13 19:20:59 +0000245 print STDERR "warning: Building with --no-use-workspace is " .
246 "deprecated.\nIf you have a workflow requirement that depends " .
247 "on building targets in manual order, please document it in " .
248 "https://bugs.webkit.org/show_bug.cgi?id=241295.\n";
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000249 # ANGLE and libwebrtc must come before WebCore
250 splice @projects, 0, 0, ("Source/ThirdParty/ANGLE");
251 # if (not $archs32bit and (portName() eq Mac or portName() eq iOS or portName() eq watchOS)) {
252 if (portName() eq Mac or portName() eq iOS) {
253 splice @projects, 0, 0, ("Source/ThirdParty/libwebrtc");
254 }
255
256 push @projects, ("Source/WebKit");
257
258 if (!isEmbeddedWebKit()) {
259 push @projects, ("Tools/MiniBrowser");
260
261 # WebInspectorUI must come after JavaScriptCore and WebCore but before WebKit and WebKit2
262 my $webKitIndex = first { $projects[$_] eq "Source/WebKitLegacy" } 0..$#projects;
263 splice(@projects, $webKitIndex, 0, "Source/WebInspectorUI");
264 }
265
266 if (isAppleMacWebKit()) {
267 push @projects, ("Tools/lldb/lldbWebKitTester");
268 }
269
270 # Build Tools needed for Apple ports (except for tvOS)
271 push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
achristensen@apple.comeb5404b2017-02-22 07:59:59 +0000272 }
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000273
commit-queue@webkit.org5eb4a622017-10-17 02:30:58 +0000274} elsif (isWinCairo() && !$skipLibraryUpdate) {
don.olmstead@sony.coma67ac422017-08-25 17:23:20 +0000275 (system("python Tools/Scripts/update-webkit-wincairo-libs.py") == 0) or die;
commit-queue@webkit.org5eb4a622017-10-17 02:30:58 +0000276} elsif (isAppleWinWebKit() && !$skipLibraryUpdate) {
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000277 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
278 # Will fail if WebKitSupportLibrary.zip is not in source root.
279 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
don.olmstead@sony.comfe956242017-12-21 19:13:40 +0000280 (system("perl Tools/Scripts/update-webkit-auxiliary-libs") == 0) or die;
281 setupAppleWinEnv()
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000282}
283
joepeck@webkit.orga24df342011-05-05 17:49:53 +0000284# If asked to build just the WebKit project, overwrite the projects
285# list after all of the port specific tweaks have been made to
286# build options, etc.
matthew_hanson@apple.com02a35fb2017-07-14 02:29:11 +0000287@projects = ("Source/WebKitLegacy") if $onlyWebKitProject;
joepeck@webkit.orga24df342011-05-05 17:49:53 +0000288
vestbo@webkit.orgf014d632012-01-20 17:35:12 +0000289my $result = 0;
290
commit-queue@webkit.org4fa53982013-09-26 20:54:06 +0000291if (isInspectorFrontend()) {
burg@cs.washington.edu148b17a2014-08-28 19:19:33 +0000292 die "The --inspector-frontend option is not supported for CMake-based builds." if isCMakeBuild();
commit-queue@webkit.org4fa53982013-09-26 20:54:06 +0000293 @projects = ("Source/WebInspectorUI");
294}
295
bfulgham@apple.com6d17b502015-10-30 17:05:58 +0000296if (isCMakeBuild() && !isAnyWindows()) {
clopez@igalia.com49e9c7c2017-09-25 12:21:47 +0000297 if (!canUseNinja() || defined($ENV{NUMBER_OF_PROCESSORS})) {
298 # If the user environment is not setting a specific number of process,
299 # then don't pass the number of jobs to Ninja. Because Ninja will
300 # automatically determine the number of jobs to run in parallel.
timothy_horton@apple.com5a73e952017-09-18 16:54:44 +0000301 $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
302 }
commit-queue@webkit.org7c0519752012-07-18 12:59:23 +0000303
ossy@webkit.orga1f81af2014-09-25 10:14:57 +0000304 my $maxCPULoad = maxCPULoad() if $makeArgs !~ /-l\s*\d+\.?\d*/;
305 $makeArgs .= " -l" . maxCPULoad() if defined $maxCPULoad;
mrobinson@webkit.org06f46f92014-01-22 19:55:57 +0000306
mcatanzaro@igalia.comb63f0102017-11-22 18:52:52 +0000307 # We remove CMakeCache to avoid the bots reusing cached flags when
commit-queue@webkit.org7c0519752012-07-18 12:59:23 +0000308 # we enable new features. This forces a reconfiguration.
dbates@webkit.org9c97e742018-06-30 02:06:23 +0000309 my @featureArgs = cmakeArgsFromFeatures(@features, !$noExperimentalFeatures);
mrobinson@webkit.org06f46f92014-01-22 19:55:57 +0000310 removeCMakeCache(@featureArgs);
commit-queue@webkit.org7c0519752012-07-18 12:59:23 +0000311
don.olmstead@sony.com7e25f132018-11-06 22:10:30 +0000312 buildCMakeProjectOrExit($clean, $prefixPath, $makeArgs, @featureArgs, @cmakeArgs);
paroga@webkit.orgbe8cbfb2011-01-03 21:04:17 +0000313}
314
achristensen@apple.coma2276592015-09-18 18:00:32 +0000315my $baseProductDir = baseProductDir();
bfulgham@apple.com28e3e642019-09-20 04:55:55 +0000316if (isAppleWinWebKit() || isWinCairo() || isPlayStation() || isFTW()) {
dbates@webkit.org9c97e742018-06-30 02:06:23 +0000317 my @featureArgs = cmakeArgsFromFeatures(@features, !$noExperimentalFeatures);
pvollan@apple.comd2bda6f2016-06-15 17:08:08 +0000318 removeCMakeCache(@featureArgs);
319
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000320 chdirWebKit();
don.olmstead@sony.com7e25f132018-11-06 22:10:30 +0000321 if (exitStatus(generateBuildSystemFromCMakeProject($prefixPath, @featureArgs, @cmakeArgs))) {
commit-queue@webkit.org7fff7df2017-12-06 02:18:57 +0000322 die "Run Visual Studio 2017 installation vcvars.bat before build-webkit when using ninja";
achristensen@apple.coma2276592015-09-18 18:00:32 +0000323 }
commit-queue@webkit.orgebcbe062017-07-21 16:02:22 +0000324
325 exit 0 if isGenerateProjectOnly();
326
achristensen@apple.coma2276592015-09-18 18:00:32 +0000327 chdirWebKit();
328 if (canUseNinja()) {
commit-queue@webkit.org78377dc2016-03-24 05:13:35 +0000329 chdir File::Spec->catdir($baseProductDir, configuration());
achristensen@apple.coma2276592015-09-18 18:00:32 +0000330 $result = system("ninja");
331 } else {
commit-queue@webkit.orgb5558232017-02-28 20:36:43 +0000332 $result = buildVisualStudioProject(File::Spec->catfile($baseProductDir, configuration(), "WebKit.sln"), $clean);
achristensen@apple.coma2276592015-09-18 18:00:32 +0000333 }
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000334 if (exitStatus($result)) {
335 my $scriptDir = relativeScriptsDir();
bfulgham@apple.com28e3e642019-09-20 04:55:55 +0000336 if (isAppleWinWebKit() || isWinCairo() || isFTW()) {
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000337 print "\n\n===== BUILD FAILED ======\n\n";
338 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000339 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
340 }
341 exit exitStatus($result);
342 }
commit-queue@webkit.org9694ed62017-02-09 23:46:56 +0000343} elsif (isAppleCocoaWebKit() && !isCMakeBuild()) {
commit-queue@webkit.orgebcbe062017-07-21 16:02:22 +0000344 exit 0 if isGenerateProjectOnly();
345
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000346 my @local_options = @options;
347 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport;
348 push @local_options, XcodeStaticAnalyzerOption() if $shouldRunStaticAnalyzer;
349 push @local_options, "WK_LTO_MODE=$ltoMode" if ($ltoMode ne "default");
emw@apple.com3ab0cce2022-04-12 23:02:14 +0000350 # When we know we're in a workspace (and not an individual project), turn
351 # on dependency validation errors. Other conditions (e.g. whether we're in
352 # a script phase or not) influence the actual VALIDATE_DEPENDENCIES setting
353 # recognized by the build system.
354 push @local_options, "WK_VALIDATE_DEPENDENCIES=YES_ERROR" if $useWorkspace;
355
356 markBaseProductDirectoryAsCreatedByXcodeBuildSystem();
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000357
achristensen@apple.coma2276592015-09-18 18:00:32 +0000358 # Build, and abort if the build fails.
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000359 if ($useWorkspace) {
360 my $scheme = $onlyWebKitProject ? "WebKitLegacy" : "All Modules";
361 $result = buildXCodeWorkspace("WebKit.xcworkspace", $scheme, $clean, @local_options, @ARGV);
achristensen@apple.coma2276592015-09-18 18:00:32 +0000362 if (exitStatus($result)) {
363 exit exitStatus($result);
364 }
commit-queue@webkit.orgb402bd72022-01-26 19:22:04 +0000365 } else {
366 for my $dir (@projects) {
367 chdir $dir or die;
368 $result = 0;
369
370 my $project = basename($dir);
371 my $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
372 $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
373
374 # Various build* calls above may change the CWD.
375 chdirWebKit();
376
377 if (exitStatus($result)) {
378 exit exitStatus($result);
379 }
380 }
jbedard@apple.com18dbcb72018-09-21 17:13:34 +0000381 }
jbedard@apple.com1cd28b42017-04-13 20:08:35 +0000382
bburg@apple.com0f405402020-08-11 23:57:15 +0000383 if (isInspectorFrontend()) {
384 exit exitStatus($result);
385 }
386
emw@apple.comd5643bb2022-06-15 22:46:32 +0000387 if ($clean) {
388 # No need to have build-imagediff do cleaning, the build directory has already been deleted.
389 exit exitStatus($result);
390 }
391
jbedard@apple.com18dbcb72018-09-21 17:13:34 +0000392 # Build ImageDiff for host
393 my @command = File::Spec->catfile(getcwd(), "/Tools/Scripts/build-imagediff");
394 chdirWebKit();
395 if (!-e $command[0]) {
396 die "build-imagediff script not found";
397 }
jbedard@apple.com1cd28b42017-04-13 20:08:35 +0000398
jbedard@apple.com18dbcb72018-09-21 17:13:34 +0000399 push @command, argumentsForConfiguration();
400 push @command, @ARGV;
401 @command = extractNonMacOSHostConfiguration(\@command);
402 $result = system(@command);
403 if (exitStatus($result)) {
404 exit exitStatus($result);
achristensen@apple.coma2276592015-09-18 18:00:32 +0000405 }
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000406}
407
408# Don't report the "WebKit is now built" message after a clean operation.
409exit if $clean;
410
vestbo@webkit.orgf014d632012-01-20 17:35:12 +0000411# Don't report congrats message if build was interrupted by the user.
412exit if ($result & 127) == SIGINT;
413
commit-queue@webkit.orgb81b0f52012-03-17 00:13:06 +0000414# Explicitly chdir back to where exit will take us anyway, since the following "launcher"
415# message is relative to that directory.
416chdir $originalWorkingDirectory;
417
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000418# Write out congratulations message.
419writeCongrats();
420
421exit 0;
422
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000423sub writeCongrats()
424{
425 my $launcherPath = launcherPath();
426 my $launcherName = launcherName();
427 my $endTime = time();
428 my $buildTime = formatBuildTime($endTime - $startTime);
429
430 print "\n";
commit-queue@webkit.org526d8db2012-11-12 07:24:24 +0000431 print "====================================================================\n";
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000432 print " WebKit is now built ($buildTime). \n";
commit-queue@webkit.org714a24b2014-02-10 13:16:01 +0000433 if ($launcherPath && $launcherName) {
434 print " To run $launcherName with this newly-built code, use the\n";
435 print " \"$launcherPath\" script.\n";
436 }
commit-queue@webkit.org526d8db2012-11-12 07:24:24 +0000437 print "====================================================================\n";
mitz@apple.com10955a5a2010-12-18 00:02:12 +0000438}