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 Computer, 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();
48 sub formatBuildTime($);
51 my $originalWorkingDirectory = getcwd();
62 my $onlyWebKitProject = 0;
65 my $coverageSupport = 0;
66 my $startTime = time();
68 my @features = getFeatureOptionList();
70 # Additional environment parameters
71 push @ARGV, split(/ /, $ENV{'BUILD_WEBKIT_ARGS'}) if ($ENV{'BUILD_WEBKIT_ARGS'});
73 # Initialize values from defaults
75 if ($_ eq '--minimal') {
80 # Initialize values from defaults
82 ${$_->{value}} = ($minimal ? 0 : $_->{default});
85 my $programName = basename($0);
87 Usage: $programName [options] [options to pass to build system]
88 --help Show this help message
89 --clean Cleanup the build directory
90 --debug Compile with Debug configuration
91 --release Compile with Release configuration
92 --sdk=<sdk> Use a specific Xcode SDK (iOS and Mac only)
93 --device Use the current iphoneos.internal SDK (iOS only)
94 --simulator Use the current iphonesimulator SDK (iOS only)
95 --coverage Enable Code Coverage support (Mac only)
97 --efl Build the EFL port
98 --gtk Build the GTK+ port
99 --wincairo Build using Cairo (rather than CoreGraphics) on Windows
100 --wince Build the WinCE port
102 --inspector-frontend Copy changes to the inspector front-end files to the build directory
104 --prefix=<path> Set installation prefix to the given path (Gtk/Efl only)
105 --makeargs=<arguments> Optional Makefile flags
106 --cmakeargs=<arguments> Optional CMake flags (e.g. --cmakeargs="-DFOO=bar -DCMAKE_PREFIX_PATH=/usr/local")
108 --minimal No optional features, unless explicitly enabled
110 --only-webkit Build only the WebKit project
111 --no-webkit1 Omit WebKit1 code from the build (EFL/GTK only)
112 --no-webkit2 Omit WebKit2 code from the build
117 'help' => \$showHelp,
119 'install-headers=s' => \$installHeaders,
120 'install-libs=s' => \$installLibs,
121 'prefix=s' => \$prefixPath,
122 'makeargs=s' => \$makeArgs,
123 'cmakeargs=s' => \$cmakeArgs,
124 'minimal' => \$minimal,
125 'only-webkit' => \$onlyWebKitProject,
126 'no-webkit1' => \$noWebKit1,
127 'no-webkit2' => \$noWebKit2,
128 'coverage' => \$coverageSupport,
131 # Build usage text and options list from features
132 foreach (@features) {
133 my $opt = sprintf("%-35s", " --[no-]$_->{option}");
134 $usage .= "$opt $_->{desc} (default: $_->{default})\n";
135 $options{"$_->{option}!"} = $_->{value};
138 GetOptions(%options);
145 checkRequiredSystemConfig();
148 my $productDir = productDir();
150 sub unlinkZeroFiles()
152 my $file = $File::Find::name;
153 # Remove 0 byte sized files, except
154 # - directories (Because they are always 0 byte sized on Windows)
155 # - .d files used for dependency tracking
156 if (! -d $file && ! -s $file && $file !~ m/\.d$/) {
158 print "0 byte sized file removed from build directory: $file\n";
162 # Check that all the project directories are there.
163 my @projects = ("Source/JavaScriptCore", "Source/WebCore", "Source/WebKit");
165 # Build WTF as a separate static library on ports which support it.
166 splice @projects, 0, 0, "Source/WTF" if isAppleMacWebKit() or isAppleWinWebKit() or isWinCairo();
168 for my $dir (@projects) {
170 die "Error: No $dir directory found. Please do a fresh checkout.\n";
174 if (!isIOSWebKit() && !-d "WebKitLibraries") {
175 die "Error: No WebKitLibraries directory found. Please do a fresh checkout.\n";
181 if (isAppleMacWebKit()) {
182 push @options, XcodeOptions();
185 my ($feature, $isEnabled, $defaultValue) = @_;
186 return "" if $defaultValue == $isEnabled;
187 return $feature . "=" . ($isEnabled ? $feature : "");
190 foreach (@features) {
191 my $option = option($_->{define}, ${$_->{value}}, $_->{default});
192 $hasFTLJIT = 1 if ($_->{define} eq "ENABLE_FTL_JIT") and (${$_->{value}});
193 push @options, $option unless $option eq "";
197 # FIXME: Remove the inclusion of both WebKit System Interface and WebKit Additions projects
198 # once the iOS build is stable.
200 # WebKitSystemInterface should always be built just before WebKit.
201 my $webKitIndex = first { $projects[$_] eq "Source/WebKit" } 0..$#projects;
202 splice(@projects, $webKitIndex, 0, "../Internal/WebKitSystemInterface");
204 # WebKitAdditions must come before WebCore
205 splice(@projects, 0, 0, "../Internal/WebKitAdditions");
207 # WebKit2 should always be built just before WebKit.
208 my $webKitIndex = first { $projects[$_] eq "Source/WebKit" } 0..$#projects;
209 splice(@projects, $webKitIndex, 0, "Source/WebKit2");
212 # ANGLE must come before WebCore
213 splice @projects, 0, 0, "Source/ThirdParty/ANGLE";
215 if (!isIOSWebKit()) {
216 push @projects, ("Tools/MiniBrowser");
218 # WebInspectorUI must come before WebKit and WebKit2
219 unshift @projects, ("Source/WebInspectorUI");
221 # Copy library and header from WebKitLibraries to a findable place in the product directory.
222 my @copyLibrariesArgs = ("perl", "Tools/Scripts/copy-webkitlibraries-to-product-directory", "--wksi");
224 push @copyLibrariesArgs, "--llvm";
226 push @copyLibrariesArgs, productDir();
227 print(join(" ", @copyLibrariesArgs) . "\n");
228 (system(@copyLibrariesArgs) == 0) or die;
230 push @projects, ("Source/WebKit2");
233 # Build Tools needed for Apple ports
234 push @projects, ("Tools/DumpRenderTree", "Tools/WebKitTestRunner", "Source/ThirdParty/gtest", "Tools/TestWebKitAPI");
236 } elsif (isWinCairo()) {
237 (system("perl Tools/Scripts/update-webkit-wincairo-libs") == 0) or die;
238 } elsif (isAppleWinWebKit()) {
239 # Copy WebKitSupportLibrary to the correct location in WebKitLibraries so it can be found.
240 # Will fail if WebKitSupportLibrary.zip is not in source root.
241 (system("perl Tools/Scripts/update-webkit-support-libs") == 0) or die;
244 # If asked to build just the WebKit project, overwrite the projects
245 # list after all of the port specific tweaks have been made to
246 # build options, etc.
247 @projects = ("Source/WebKit") if $onlyWebKitProject;
251 if (isInspectorFrontend()) {
252 $result = copyInspectorFrontendFiles();
253 exit exitStatus($result) if exitStatus($result);
254 @projects = ("Source/WebInspectorUI");
257 if (isCMakeBuild()) {
258 $cmakeArgs = "-DENABLE_WEBKIT=OFF " . $cmakeArgs if $noWebKit1;
259 $cmakeArgs = "-DENABLE_WEBKIT2=OFF " . $cmakeArgs if $noWebKit2;
261 # By default we build using all of the available CPUs.
263 $makeArgs .= ($makeArgs ? " " : "") . "-j" . numberOfCPUs() if $makeArgs !~ /-j\s*\d+/;
266 # We remove CMakeCache to avoid the bots to reuse cached flags when
267 # we enable new features. This forces a reconfiguration.
268 my @featureArgs = cMakeArgsFromFeatures();
269 removeCMakeCache(@featureArgs);
271 buildCMakeProjectOrExit($clean, cmakeBasedPortName(), $prefixPath, $makeArgs, (cmakeBasedPortArguments(), @featureArgs), $cmakeArgs);
274 # Build, and abort if the build fails.
275 for my $dir (@projects) {
279 # For Gtk the WebKit project builds all others
280 if (isGtkAutotools() && $dir ne "Source/WebKit") {
285 my $project = basename($dir);
286 my $baseProductDir = baseProductDir();
287 if (isGtkAutotools()) {
288 $result = buildGtkProject($project, $clean, $prefixPath, $makeArgs, $noWebKit1, $noWebKit2, @features);
289 } elsif (isAppleMacWebKit()) {
290 my @local_options = @options;
291 push @local_options, XcodeCoverageSupportOptions() if $coverageSupport;
292 my $projectPath = $project =~ /gtest/ ? "xcode/gtest" : $project;
294 push @local_options, qw(-target WebKitTestRunnerApp) if ($project eq "WebKitTestRunner") && !$clean;
296 $result = buildXCodeProject($projectPath, $clean, @local_options, @ARGV);
297 } elsif (isAppleWinWebKit() || isWinCairo()) {
298 if ($project eq "WebKit") {
299 my $webkitSolutionPath = "WebKit.vcxproj/WebKit.sln";
300 $result = buildVisualStudioProject($webkitSolutionPath, $clean);
301 my $vsConfiguration = configuration();
302 if (usingVisualStudioExpress()) {
303 # Visual Studio Express is so lame it can't stdout build failures.
304 # So we find its logs and dump them to the console ourselves.
305 open(my $OUTPUT_HANDLE, '<', "$baseProductDir/$vsConfiguration/BuildOutput.htm") or die "Could not open build log file at $baseProductDir/$vsConfiguration/BuildOutput.htm";
306 print while (<$OUTPUT_HANDLE>);
310 # Various build* calls above may change the CWD.
313 if (exitStatus($result)) {
314 my $scriptDir = relativeScriptsDir();
315 if (isAppleWinWebKit() || isWinCairo()) {
316 print "\n\n===== BUILD FAILED ======\n\n";
317 print "Please ensure you have run $scriptDir/update-webkit to install dependencies.\n\n";
318 print "You can view build errors by checking the BuildLog.htm files located at:\n$baseProductDir/obj/<project>/<config>.\n";
320 exit exitStatus($result);
324 # Don't report the "WebKit is now built" message after a clean operation.
327 # Don't report congrats message if build was interrupted by the user.
328 exit if ($result & 127) == SIGINT;
330 # Explicitly chdir back to where exit will take us anyway, since the following "launcher"
331 # message is relative to that directory.
332 chdir $originalWorkingDirectory;
334 # Write out congratulations message.
339 sub cMakeArgsFromFeatures()
342 foreach (@features) {
343 my $featureName = $_->{define};
345 my $featureEnabled = ${$_->{value}} ? "ON" : "OFF";
346 push @args, "-D$featureName=$featureEnabled";
352 sub formatBuildTime($)
354 my ($buildTime) = @_;
356 my $buildHours = int($buildTime / 3600);
357 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
358 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
361 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
363 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
368 my $launcherPath = launcherPath();
369 my $launcherName = launcherName();
370 my $endTime = time();
371 my $buildTime = formatBuildTime($endTime - $startTime);
374 print "====================================================================\n";
375 print " WebKit is now built ($buildTime). \n";
376 if ($launcherPath && $launcherName) {
377 print " To run $launcherName with this newly-built code, use the\n";
378 print " \"$launcherPath\" script.\n";
380 print "====================================================================\n";