3 # Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Apple Inc. All rights reserved.
4 # Copyright (C) 2009 Google Inc. All rights reserved.
5 # Copyright (C) 2010 moiji-mobile.com All rights reserved.
6 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
7 # Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
9 # Redistribution and use in source and binary forms, with or without
10 # modification, are permitted provided that the following conditions
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.
18 # 3. Neither the name of Apple Inc. ("Apple") nor the names of
19 # its contributors may be used to endorse or promote products derived
20 # from this software without specific prior written permission.
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.
33 # Build script wrapper for the WebKit Open Source Project.
40 use Getopt::Long qw(:config pass_through no_auto_abbrev);
41 use lib $FindBin::Bin;
43 use List::Util qw(first);
44 use webkitperl::FeatureList qw(getFeatureOptionList);
47 sub cMakeArgsFromFeatures();
50 my $originalWorkingDirectory = getcwd();
61 my $onlyWebKitProject = 0;
62 my $coverageSupport = 0;
63 my $shouldRunStaticAnalyzer = 0;
64 my $startTime = time();
66 my @features = getFeatureOptionList();
68 # Additional environment parameters
69 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
71 # Initialize values from defaults
73 if ($_ eq '--minimal') {
78 # Initialize values from defaults
80 ${$_->{value}} = ($minimal ? 0 : $_->{default});
83 my $programName = basename($0);
85 Usage: $programName [options] [options to pass to build system]
86 --help Show this help message
87 --clean Cleanup the build directory
88 --debug Compile with Debug configuration
89 --release Compile with Release configuration
90 --sdk=<sdk> Use a specific Xcode SDK (iOS and Mac only)
91 --device Use "iphoneos.internal" SDK if installed, else "iphoneos" SDK (iOS only)
92 --ios-simulator Use the current iphonesimulator SDK (iOS only)
93 --coverage Enable code coverage support (Mac only)
94 --analyze Enable static anaylsis (iOS and Mac only)
96 --efl Build the EFL port
97 --gtk Build the GTK+ port
98 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
100 --inspector-frontend Copy Web Inspector user interface resources to the build directory
102 --prefix=<path> Set installation prefix to the given path (Gtk/Efl only)
103 --makeargs=<arguments> Optional Makefile flags
104 --cmakeargs=<arguments> One or more optional CMake flags (e.g. --cmakeargs="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
106 --minimal No optional features, unless explicitly enabled
108 --only-webkit Build only the WebKit project
113 'help' => \$showHelp,
115 'install-headers=s' => \$installHeaders,
116 'install-libs=s' => \$installLibs,
117 'prefix=s' => \$prefixPath,
118 'makeargs=s' => \$makeArgs,
119 'cmakeargs=s' => \@cmakeArgs,
120 'minimal' => \$minimal,
121 'only-webkit' => \$onlyWebKitProject,
122 'coverage' => \$coverageSupport,
123 'analyze' => \$shouldRunStaticAnalyzer,
126 # Build usage text and options list from features
127 foreach (@features) {
128 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
129 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
130 $options{"$_->{option}!"} = $_->{value};
133 GetOptions(%options);
140 checkRequiredSystemConfig();
143 my $productDir = productDir();
145 # Check that all the project directories are there.
146 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
148 # Build WTF as a separate static library on ports which support it.
149 splice @projects, 0, 0, "Source/WTF" if isAppleWebKit() or isWinCairo();
151 splice @projects, 0, 0, "Source/bmalloc" if isAppleMacWebKit();
153 # Ports using CMake will check if directories exist in the CMake configuration.
154 if (!isCMakeBuild()) {
155 for my $dir (@projects) {
157 die "Error: No $dir directory found. Please do a fresh checkout.\n";
162 if ((isAppleWebKit() || isWinCairo()) && !-d "WebKitLibraries") {
163 die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
168 if (isAppleMacWebKit()) {
169 push @options, XcodeOptions();
172 my ($feature, $isEnabled, $defaultValue) = @_;
173 return "" if $defaultValue == $isEnabled;
174 return $feature . "=" . ($isEnabled ? $feature : "");
177 foreach (@features) {
178 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
179 push @options, $option unless $option eq "";
182 # ANGLE must come before WebCore
183 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
185 push @projects, ("Source/WebKit2");
187 if (!isIOSWebKit()) {
188 push @projects, ("Tools/MiniBrowser");
190 # WebInspectorUI must come after JavaScriptCore and WebCore but before WebKit and WebKit2
191 my $webKitIndex = first { $projects[$_] eq "Source/WebKit" } 0..$#projects;
192 splice(@projects, $webKitIndex, 0, "Source/WebInspectorUI");
194 # Copy library and header from WebKitLibraries to a findable place in the product directory.
195 my @copyLibrariesArgs = ("perl", "Tools/Scripts/copy-webkitlibraries-to-product-directory", "--wksi", productDir());
196 print(join(" ", @copyLibrariesArgs) . "\n");
197 (system(@copyLibrariesArgs) == 0) or die;
199 my @copyLibrariesArgs = ("perl", "Tools/Scripts/copy-webkitlibraries-to-product-directory", "--sdk", xcodeSDK(), "--wksi");
200 push @copyLibrariesArgs, productDir();
201 print(join(" ", @copyLibrariesArgs) . "\n");
202 (system(@copyLibrariesArgs) == 0) or die;
204 if (willUseIOSSimulatorSDK()) {
205 (system("perl", "Tools/Scripts/build-layouttestrelay", argumentsForConfiguration()) == 0) or die;
209 # Build Tools needed for Apple ports
210 push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
212 } elsif (isWinCairo()) {
213 (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
214 } elsif (isAppleWinWebKit()) {
215 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
216 # Will fail if WebKitSupportLibrary.zip is not in source root.
217 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
220 # If asked to build just the WebKit project, overwrite the projects
221 # list after all of the port specific tweaks have been made to
222 # build options, etc.
223 @projects = ("Source/WebKit") if $onlyWebKitProject;
227 if (isInspectorFrontend()) {
228 die "The --inspector-frontend option is not supported for CMake-based builds." if isCMakeBuild();
229 @projects = ("Source/WebInspectorUI");
232 if (isCMakeBuild() && !isAnyWindows()) {
234 # By default we build using all of the available CPUs.
235 $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
236 my $maxCPULoad = maxCPULoad() if $makeArgs !~ /-l\s*\d+\.?\d*/;
237 $makeArgs .= " -l" . maxCPULoad() if defined $maxCPULoad;
239 # We remove CMakeCache to avoid the bots to reuse cached flags when
240 # we enable new features. This forces a reconfiguration.
241 my @featureArgs = cMakeArgsFromFeatures();
242 removeCMakeCache(@featureArgs);
244 buildCMakeProjectOrExit($clean, $prefixPath, $makeArgs, (cmakeBasedPortArguments(), @featureArgs), @cmakeArgs);
247 my $baseProductDir = baseProductDir();
248 if (isAppleWinWebKit() || isWinCairo()) {
249 my @featureArgs = cMakeArgsFromFeatures();
250 removeCMakeCache(@featureArgs);
253 if (exitStatus(generateBuildSystemFromCMakeProject())) {
254 die "Run \"C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/vcvarsall.bat\" before build-webkit when using ninja";
258 chdir File::Spec->catdir($baseProductDir, configuration());
259 $result = system("ninja");
261 $result = buildVisualStudioProject(File::Spec->catfile("WebKitBuild", configuration(), "WebKit.sln"), $clean);
263 if (exitStatus($result)) {
264 my $scriptDir = relativeScriptsDir();
265 if (isAppleWinWebKit() || isWinCairo()) {
266 print "\n\n===== BUILD FAILED ======\n\n";
267 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
268 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
270 exit exitStatus($result);
272 } elsif (isAppleMacWebKit() && !isCMakeBuild()) {
273 # Build, and abort if the build fails.
274 for my $dir (@projects) {
278 my $project = basename($dir);
280 my @local_options = @options;
281 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport;
282 push @local_options, XcodeStaticAnalyzerOption() if $shouldRunStaticAnalyzer;
283 my $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
284 $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
286 # Various build* calls above may change the CWD.
289 if (exitStatus($result)) {
290 exit exitStatus($result);
295 # Don't report the "WebKit is now built" message after a clean operation.
298 # Don't report congrats message if build was interrupted by the user.
299 exit if ($result & 127) == SIGINT;
301 # Explicitly chdir back to where exit will take us anyway, since the following "launcher"
302 # message is relative to that directory.
303 chdir $originalWorkingDirectory;
305 # Write out congratulations message.
310 sub cMakeArgsFromFeatures()
313 foreach (@features) {
314 my $featureName = $_->{define};
316 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
317 push @args, "-D$featureName=$featureEnabled";
325 my $launcherPath = launcherPath();
326 my $launcherName = launcherName();
327 my $endTime = time();
328 my $buildTime = formatBuildTime($endTime - $startTime);
331 print "====================================================================\n";
332 print " WebKit is now built ($buildTime). \n";
333 if ($launcherPath && $launcherName) {
334 print " To run $launcherName with this newly-built code, use the\n";
335 print " \"$launcherPath\" script.\n";
337 print "====================================================================\n";