1 # Copyright (C) 2005-2007, 2010-2014 Apple Inc. All rights reserved.
2 # Copyright (C) 2009 Google Inc. All rights reserved.
3 # Copyright (C) 2011 Research In Motion Limited. All rights reserved.
4 # Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies).
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. Neither the name of Apple Inc. ("Apple") nor the names of
16 # its contributors may be used to endorse or promote products derived
17 # from this software without specific prior written permission.
19 # THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
20 # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 # DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
23 # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24 # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
26 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 # Module to share code to get to WebKit directories.
36 use Digest::MD5 qw(md5_hex);
39 use File::Path qw(mkpath rmtree);
48 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
52 &XcodeCoverageSupportOptions
54 &XcodeOptionStringNoConfig
56 &XcodeStaticAnalyzerOption
57 &appDisplayNameFromBundle
61 &cmakeBasedPortArguments
65 &findOrCreateSimulatorForIOSDevice
66 &installAndLaunchIOSWebKitAppInSimulator
67 &iosSimulatorDeviceByName
71 &printHelpAndExitForRunAndDebugWebKitAppIfNeeded
78 &setupMacWebKitEnvironment
79 &sharedCommandLineOptions
80 &sharedCommandLineOptionsUsage
87 use constant USE_OPEN_COMMAND => 1; # Used in runMacWebKitApp().
88 use constant INCLUDE_OPTIONS_FOR_DEBUGGING => 1;
96 my @baseProductDirOption;
99 my $configurationForVisualStudio;
100 my $configurationProductDir;
102 my $currentSVNRevision;
104 my $didLoadIPhoneSimulatorNotification;
112 my $isInspectorFrontend;
114 my $shouldTargetWebProcess;
115 my $shouldUseXPCServiceForWebProcess;
116 my $shouldUseGuardMalloc;
119 # Variables for Win32 support
120 my $programFilesPath;
124 my $windowsSourceDir;
126 my $willUseVCExpressWhenBuilding = 0;
128 # Defined in VCSUtils.
131 sub findMatchingArguments($$);
134 sub determineSourceDir
136 return if $sourceDir;
137 $sourceDir = $FindBin::Bin;
138 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
140 # walks up path checking each directory to see if it is the main WebKit project dir,
141 # defined by containing Sources, WebCore, and WebKit
142 until ((-d "$sourceDir/Source" && -d "$sourceDir/Source/WebCore" && -d "$sourceDir/Source/WebKit") || (-d "$sourceDir/Internal" && -d "$sourceDir/OpenSource"))
144 if ($sourceDir !~ s|/[^/]+$||) {
145 die "Could not find top level webkit directory above source directory using FindBin.\n";
149 $sourceDir = "$sourceDir/OpenSource" if -d "$sourceDir/OpenSource";
152 sub currentPerlPath()
156 $thisPerl .= $Config{_exe} unless $thisPerl =~ m/$Config{_exe}$/i;
161 # used for scripts which are stored in a non-standard location
167 sub determineNinjaVersion
169 chomp(my $ninjaVersion = `ninja --version`);
170 return $ninjaVersion;
173 sub determineXcodeVersion
175 return if defined $xcodeVersion;
176 my $xcodebuildVersionOutput = `xcodebuild -version`;
177 $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : "3.0";
180 sub readXcodeUserDefault($)
182 my ($unprefixedKey) = @_;
184 determineXcodeVersion();
186 my $xcodeDefaultsDomain = (eval "v$xcodeVersion" lt v4) ? "com.apple.Xcode" : "com.apple.dt.Xcode";
187 my $xcodeDefaultsPrefix = (eval "v$xcodeVersion" lt v4) ? "PBX" : "IDE";
188 my $devnull = File::Spec->devnull();
190 my $value = `defaults read $xcodeDefaultsDomain ${xcodeDefaultsPrefix}${unprefixedKey} 2> ${devnull}`;
197 sub determineBaseProductDir
199 return if defined $baseProductDir;
200 determineSourceDir();
202 my $setSharedPrecompsDir;
203 $baseProductDir = $ENV{"WEBKIT_OUTPUTDIR"};
205 if (!defined($baseProductDir) and isAppleMacWebKit()) {
206 # Silently remove ~/Library/Preferences/xcodebuild.plist which can
207 # cause build failure. The presence of
208 # ~/Library/Preferences/xcodebuild.plist can prevent xcodebuild from
209 # respecting global settings such as a custom build products directory
210 # (<rdar://problem/5585899>).
211 my $personalPlistFile = $ENV{HOME} . "/Library/Preferences/xcodebuild.plist";
212 if (-e $personalPlistFile) {
213 unlink($personalPlistFile) || die "Could not delete $personalPlistFile: $!";
216 determineXcodeVersion();
218 if (eval "v$xcodeVersion" ge v4) {
219 my $buildLocationStyle = join '', readXcodeUserDefault("BuildLocationStyle");
220 if ($buildLocationStyle eq "Custom") {
221 my $buildLocationType = join '', readXcodeUserDefault("CustomBuildLocationType");
222 # FIXME: Read CustomBuildIntermediatesPath and set OBJROOT accordingly.
223 $baseProductDir = readXcodeUserDefault("CustomBuildProductsPath") if $buildLocationType eq "Absolute";
226 # DeterminedByTargets corresponds to a setting of "Legacy" in Xcode.
227 # It is the only build location style for which SHARED_PRECOMPS_DIR is not
228 # overridden when building from within Xcode.
229 $setSharedPrecompsDir = 1 if $buildLocationStyle ne "DeterminedByTargets";
232 if (!defined($baseProductDir)) {
233 $baseProductDir = join '', readXcodeUserDefault("ApplicationwideBuildSettings");
234 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
237 undef $baseProductDir unless $baseProductDir =~ /^\//;
240 if (!defined($baseProductDir)) { # Port-specific checks failed, use default
241 $baseProductDir = "$sourceDir/WebKitBuild";
244 if (isGit() && isGitBranchBuild()) {
245 my $branch = gitBranch();
246 $baseProductDir = "$baseProductDir/$branch";
249 if (isAppleMacWebKit()) {
250 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
251 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
252 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
253 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
254 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
255 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir");
256 push(@baseProductDirOption, "SHARED_PRECOMPS_DIR=${baseProductDir}/PrecompiledHeaders") if $setSharedPrecompsDir;
260 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
262 $ENV{"WEBKIT_OUTPUTDIR"} = $dosBuildPath;
263 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
264 chomp $unixBuildPath;
265 $baseProductDir = $unixBuildPath;
269 sub setBaseProductDir($)
271 ($baseProductDir) = @_;
274 sub determineConfiguration
276 return if defined $configuration;
277 determineBaseProductDir();
278 if (open CONFIGURATION, "$baseProductDir/Configuration") {
279 $configuration = <CONFIGURATION>;
282 if ($configuration) {
283 chomp $configuration;
284 # compatibility for people who have old Configuration files
285 $configuration = "Release" if $configuration eq "Deployment";
286 $configuration = "Debug" if $configuration eq "Development";
288 $configuration = "Release";
291 if ($configuration && isWinCairo()) {
292 unless ($configuration =~ /_WinCairo$/) {
293 $configuration .= "_WinCairo";
298 sub determineArchitecture
300 return if defined $architecture;
301 # make sure $architecture is defined in all cases
304 determineBaseProductDir();
307 if (isAppleMacWebKit()) {
308 if (open ARCHITECTURE, "$baseProductDir/Architecture") {
309 $architecture = <ARCHITECTURE>;
315 if (not defined $xcodeSDK or $xcodeSDK =~ /^(\/$|macosx)/) {
316 my $supports64Bit = `sysctl -n hw.optional.x86_64`;
317 chomp $supports64Bit;
318 $architecture = 'x86_64' if $supports64Bit;
319 } elsif ($xcodeSDK =~ /^iphonesimulator/) {
320 $architecture = 'x86_64';
321 } elsif ($xcodeSDK =~ /^iphoneos/) {
322 $architecture = 'armv7';
325 } elsif (isEfl() || isGtk()) {
326 my $host_processor = "";
327 $host_processor = `cmake --system-information | grep CMAKE_SYSTEM_PROCESSOR`;
328 if ($host_processor =~ m/^CMAKE_SYSTEM_PROCESSOR \"([^"]+)\"/) {
329 # We have a configured build tree; use it.
331 $architecture = 'x86_64' if $architecture eq 'amd64';
335 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
336 # Fall back to output of `arch', if it is present.
337 $architecture = `arch`;
341 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
342 # Fall back to output of `uname -m', if it is present.
343 $architecture = `uname -m`;
347 $architecture = 'x86_64' if ($architecture =~ /amd64/ && isBSD());
350 sub determineNumberOfCPUs
352 return if defined $numberOfCPUs;
353 if (defined($ENV{NUMBER_OF_PROCESSORS})) {
354 $numberOfCPUs = $ENV{NUMBER_OF_PROCESSORS};
355 } elsif (isLinux()) {
356 # First try the nproc utility, if it exists. If we get no
357 # results fall back to just interpretting /proc directly.
358 chomp($numberOfCPUs = `nproc --all 2> /dev/null`);
359 if ($numberOfCPUs eq "") {
360 $numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`);
362 } elsif (isWindows() || isCygwin()) {
364 $numberOfCPUs = `ls /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor | wc -w`;
365 } elsif (isDarwin() || isBSD()) {
366 chomp($numberOfCPUs = `sysctl -n hw.ncpu`);
370 sub determineMaxCPULoad
372 return if defined $maxCPULoad;
373 if (defined($ENV{MAX_CPU_LOAD})) {
374 $maxCPULoad = $ENV{MAX_CPU_LOAD};
380 my ($productDir) = @_;
382 $jscName .= "_debug" if configuration() eq "Debug_All";
383 $jscName .= ".exe" if (isWindows() || isCygwin());
384 return "$productDir/$jscName" if -e "$productDir/$jscName";
385 return "$productDir/JavaScriptCore.framework/Resources/$jscName";
388 sub argumentsForConfiguration()
390 determineConfiguration();
391 determineArchitecture();
395 push(@args, '--debug') if ($configuration =~ "^Debug");
396 push(@args, '--release') if ($configuration =~ "^Release");
397 push(@args, '--device') if (defined $xcodeSDK && $xcodeSDK =~ /^iphoneos/);
398 push(@args, '--sim') if (defined $xcodeSDK && $xcodeSDK =~ /^iphonesimulator/);
399 push(@args, '--ios-simulator') if (defined $xcodeSDK && $xcodeSDK =~ /^iphonesimulator/);
400 push(@args, '--32-bit') if ($architecture ne "x86_64" and !isWin64());
401 push(@args, '--64-bit') if (isWin64());
402 push(@args, '--gtk') if isGtk();
403 push(@args, '--efl') if isEfl();
404 push(@args, '--wincairo') if isWinCairo();
405 push(@args, '--inspector-frontend') if isInspectorFrontend();
409 sub determineXcodeSDK
411 return if defined $xcodeSDK;
413 if (checkForArgumentAndRemoveFromARGVGettingValue("--sdk", \$sdk)) {
416 if (checkForArgumentAndRemoveFromARGV("--device")) {
417 $xcodeSDK ||= 'iphoneos.internal';
419 if (checkForArgumentAndRemoveFromARGV("--sim") ||
420 checkForArgumentAndRemoveFromARGV("--simulator") ||
421 checkForArgumentAndRemoveFromARGV("--ios-simulator")) {
422 $xcodeSDK ||= 'iphonesimulator';
432 sub xcodeSDKPlatformName()
435 return "" if !defined $xcodeSDK;
436 return "iphoneos" if $xcodeSDK =~ /iphoneos/i;
437 return "iphonesimulator" if $xcodeSDK =~ /iphonesimulator/i;
438 return "macosx" if $xcodeSDK =~ /macosx/i;
439 die "Couldn't determine platform name from Xcode SDK";
446 die "Can't find the SDK path because no Xcode SDK was specified" if not $xcodeSDK;
448 my $sdkPath = `xcrun --sdk $xcodeSDK --show-sdk-path` if $xcodeSDK;
449 die 'Failed to get SDK path from xcrun' if $?;
459 die "Can't find the SDK version because no Xcode SDK was specified" if !$xcodeSDK;
461 chomp(my $sdkVersion = `xcrun --sdk $xcodeSDK --show-sdk-version`);
462 die "Failed to get SDK version from xcrun" if exitStatus($?);
469 return $programFilesPath if defined $programFilesPath;
471 $programFilesPath = $ENV{'PROGRAMFILES(X86)'} || $ENV{'PROGRAMFILES'} || "C:\\Program Files";
473 return $programFilesPath;
476 sub visualStudioInstallDir
478 return $vsInstallDir if defined $vsInstallDir;
480 if ($ENV{'VSINSTALLDIR'}) {
481 $vsInstallDir = $ENV{'VSINSTALLDIR'};
482 $vsInstallDir =~ s|[\\/]$||;
484 $vsInstallDir = File::Spec->catdir(programFilesPath(), "Microsoft Visual Studio 12.0");
486 chomp($vsInstallDir = `cygpath "$vsInstallDir"`) if isCygwin();
488 return $vsInstallDir;
491 sub visualStudioVersion
493 return $vsVersion if defined $vsVersion;
495 my $installDir = visualStudioInstallDir();
497 $vsVersion = ($installDir =~ /Microsoft Visual Studio ([0-9]+\.[0-9]*)/) ? $1 : "12";
502 sub determineConfigurationForVisualStudio
504 return if defined $configurationForVisualStudio;
505 determineConfiguration();
506 # FIXME: We should detect when Debug_All or Production has been chosen.
507 $configurationForVisualStudio = $configuration . (isWin64() ? "|x64" : "|Win32");
510 sub usesPerConfigurationBuildDirectory
512 # [Gtk] We don't have Release/Debug configurations in straight
513 # autotool builds (non build-webkit). In this case and if
514 # WEBKIT_OUTPUTDIR exist, use that as our configuration dir. This will
515 # allows us to run run-webkit-tests without using build-webkit.
516 return ($ENV{"WEBKIT_OUTPUTDIR"} && isGtk()) || isAppleWinWebKit();
519 sub determineConfigurationProductDir
521 return if defined $configurationProductDir;
522 determineBaseProductDir();
523 determineConfiguration();
524 if (isAppleWinWebKit() || isWinCairo()) {
525 my $binDir = isWin64() ? "bin64" : "bin32";
526 $configurationProductDir = File::Spec->catdir($baseProductDir, $configuration, $binDir);
528 if (usesPerConfigurationBuildDirectory()) {
529 $configurationProductDir = "$baseProductDir";
531 $configurationProductDir = "$baseProductDir/$configuration";
532 $configurationProductDir .= "-" . xcodeSDKPlatformName() if isIOSWebKit();
537 sub setConfigurationProductDir($)
539 ($configurationProductDir) = @_;
542 sub determineCurrentSVNRevision
544 # We always update the current SVN revision here, and leave the caching
545 # to currentSVNRevision(), so that changes to the SVN revision while the
546 # script is running can be picked up by calling this function again.
547 determineSourceDir();
548 $currentSVNRevision = svnRevisionForDirectory($sourceDir);
549 return $currentSVNRevision;
555 determineSourceDir();
556 chdir $sourceDir or die;
561 determineBaseProductDir();
562 return $baseProductDir;
567 determineSourceDir();
573 determineConfigurationProductDir();
574 return $configurationProductDir;
579 my $productDir = productDir();
580 $productDir .= "/bin" if (isEfl() || isGtk());
587 determineConfiguration();
588 return $configuration;
591 sub configurationForVisualStudio()
593 determineConfigurationForVisualStudio();
594 return $configurationForVisualStudio;
597 sub currentSVNRevision
599 determineCurrentSVNRevision() if not defined $currentSVNRevision;
600 return $currentSVNRevision;
605 determineGenerateDsym();
606 return $generateDsym;
609 sub determineGenerateDsym()
611 return if defined($generateDsym);
612 $generateDsym = checkForArgumentAndRemoveFromARGV("--dsym");
615 sub argumentsForXcode()
618 push @args, "DEBUG_INFORMATION_FORMAT=dwarf-with-dsym" if generateDsym();
624 determineBaseProductDir();
625 determineConfiguration();
626 determineArchitecture();
629 my @sdkOption = ($xcodeSDK ? "SDKROOT=$xcodeSDK" : ());
630 my @architectureOption = ($architecture ? "ARCHS=$architecture" : ());
632 return (@baseProductDirOption, "-configuration", $configuration, @architectureOption, @sdkOption, argumentsForXcode());
635 sub XcodeOptionString
637 return join " ", XcodeOptions();
640 sub XcodeOptionStringNoConfig
642 return join " ", @baseProductDirOption;
645 sub XcodeCoverageSupportOptions()
647 my @coverageSupportOptions = ();
648 push @coverageSupportOptions, "GCC_GENERATE_TEST_COVERAGE_FILES=YES";
649 push @coverageSupportOptions, "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES";
650 return @coverageSupportOptions;
653 sub XcodeStaticAnalyzerOption()
655 return "RUN_CLANG_STATIC_ANALYZER=YES";
658 my $passedConfiguration;
659 my $searchedForPassedConfiguration;
660 sub determinePassedConfiguration
662 return if $searchedForPassedConfiguration;
663 $searchedForPassedConfiguration = 1;
664 $passedConfiguration = undef;
666 if (checkForArgumentAndRemoveFromARGV("--debug")) {
667 $passedConfiguration = "Debug";
668 } elsif(checkForArgumentAndRemoveFromARGV("--release")) {
669 $passedConfiguration = "Release";
670 } elsif (checkForArgumentAndRemoveFromARGV("--profile") || checkForArgumentAndRemoveFromARGV("--profiling")) {
671 $passedConfiguration = "Profiling";
674 $passedConfiguration .= "_WinCairo" if (defined($passedConfiguration) && isWinCairo() && isCygwin());
677 sub passedConfiguration
679 determinePassedConfiguration();
680 return $passedConfiguration;
687 if (my $config = shift @_) {
688 $configuration = $config;
692 determinePassedConfiguration();
693 $configuration = $passedConfiguration if $passedConfiguration;
697 my $passedArchitecture;
698 my $searchedForPassedArchitecture;
699 sub determinePassedArchitecture
701 return if $searchedForPassedArchitecture;
702 $searchedForPassedArchitecture = 1;
704 $passedArchitecture = undef;
705 if (checkForArgumentAndRemoveFromARGV("--32-bit")) {
706 if (isAppleMacWebKit()) {
707 # PLATFORM_IOS: Don't run `arch` command inside Simulator environment
709 delete $ENV{DYLD_ROOT_PATH};
710 delete $ENV{DYLD_FRAMEWORK_PATH};
712 $passedArchitecture = `arch`;
713 chomp $passedArchitecture;
718 sub passedArchitecture
720 determinePassedArchitecture();
721 return $passedArchitecture;
726 determineArchitecture();
727 return $architecture;
732 determineNumberOfCPUs();
733 return $numberOfCPUs;
738 determineMaxCPULoad();
744 if (my $arch = shift @_) {
745 $architecture = $arch;
749 determinePassedArchitecture();
750 $architecture = $passedArchitecture if $passedArchitecture;
753 sub skipSafariExecutableEntitlementChecks
755 return `defaults read /Library/Preferences/org.webkit.BuildConfiguration SkipSafariExecutableEntitlementChecks 2>/dev/null` eq "1\n";
758 sub executableHasEntitlements
760 my $executablePath = shift;
761 return (`codesign -d --entitlements - $executablePath 2>&1` =~ /<key>/);
764 sub safariPathFromSafariBundle
766 my ($safariBundle) = @_;
768 die "Safari path is only relevant on Apple Mac platform\n" unless isAppleMacWebKit();
770 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
771 return $safariPath if skipSafariExecutableEntitlementChecks();
773 my $safariForWebKitDevelopmentPath = "$safariBundle/Contents/MacOS/SafariForWebKitDevelopment";
774 return $safariForWebKitDevelopmentPath if -f $safariForWebKitDevelopmentPath && executableHasEntitlements($safariPath);
779 sub installedSafariPath
781 return safariPathFromSafariBundle("/Applications/Safari.app");
787 die "Safari path is only relevant on Apple Mac platform\n" unless isAppleMacWebKit();
789 # Use WEBKIT_SAFARI environment variable if present.
790 my $safariBundle = $ENV{WEBKIT_SAFARI};
791 if (!$safariBundle) {
792 determineConfigurationProductDir();
793 # Use Safari.app in product directory if present (good for Safari development team).
794 if (-d "$configurationProductDir/Safari.app") {
795 $safariBundle = "$configurationProductDir/Safari.app";
797 if (!$safariBundle) {
798 return installedSafariPath();
801 my $safariPath = safariPathFromSafariBundle($safariBundle);
802 die "Can't find executable at $safariPath.\n" if !-x $safariPath;
806 sub builtDylibPathForName
808 my $libraryName = shift;
809 determineConfigurationProductDir();
812 my $extension = isDarwin() ? ".dylib" : ".so";
813 return "$configurationProductDir/lib/libwebkit2gtk-4.0" . $extension;
816 return "$configurationProductDir/lib/libewebkit2.so";
819 return "$configurationProductDir/$libraryName.framework/$libraryName";
821 if (isAppleMacWebKit()) {
822 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
824 if (isAppleWinWebKit()) {
825 if ($libraryName eq "JavaScriptCore") {
826 return "$baseProductDir/lib/$libraryName.lib";
828 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
832 die "Unsupported platform, can't determine built library locations.\nTry `build-webkit --help` for more information.\n";
835 # Check to see that all the frameworks are built.
836 sub checkFrameworks # FIXME: This is a poor name since only the Mac calls built WebCore a Framework.
838 return if isCygwin() || isWindows();
839 my @frameworks = ("JavaScriptCore", "WebCore");
840 push(@frameworks, "WebKit") if isAppleMacWebKit(); # FIXME: This seems wrong, all ports should have a WebKit these days.
841 for my $framework (@frameworks) {
842 my $path = builtDylibPathForName($framework);
843 die "Can't find built framework at \"$path\".\n" unless -e $path;
847 sub isInspectorFrontend()
849 determineIsInspectorFrontend();
850 return $isInspectorFrontend;
853 sub determineIsInspectorFrontend()
855 return if defined($isInspectorFrontend);
856 $isInspectorFrontend = checkForArgumentAndRemoveFromARGV("--inspector-frontend");
862 my $devnull = File::Spec->devnull();
863 return `$command --version 2> $devnull`;
866 sub checkForArgumentAndRemoveFromARGV($)
868 my $argToCheck = shift;
869 return checkForArgumentAndRemoveFromArrayRef($argToCheck, \@ARGV);
872 sub checkForArgumentAndRemoveFromArrayRefGettingValue($$$)
874 my ($argToCheck, $valueRef, $arrayRef) = @_;
875 my $argumentStartRegEx = qr#^$argToCheck(?:=\S|$)#;
877 for (; $i < @$arrayRef; ++$i) {
878 last if $arrayRef->[$i] =~ $argumentStartRegEx;
880 if ($i >= @$arrayRef) {
881 return $$valueRef = undef;
883 my ($key, $value) = split("=", $arrayRef->[$i]);
884 splice(@$arrayRef, $i, 1);
885 if (defined($value)) {
886 # e.g. --sdk=iphonesimulator
887 return $$valueRef = $value;
889 return $$valueRef = splice(@$arrayRef, $i, 1); # e.g. --sdk iphonesimulator
892 sub checkForArgumentAndRemoveFromARGVGettingValue($$)
894 my ($argToCheck, $valueRef) = @_;
895 return checkForArgumentAndRemoveFromArrayRefGettingValue($argToCheck, $valueRef, \@ARGV);
898 sub findMatchingArguments($$)
900 my ($argToCheck, $arrayRef) = @_;
902 foreach my $index (0 .. $#$arrayRef) {
903 my $opt = $$arrayRef[$index];
904 if ($opt =~ /^$argToCheck$/i ) {
905 push(@matchingIndices, $index);
908 return @matchingIndices;
913 my ($argToCheck, $arrayRef) = @_;
914 my @matchingIndices = findMatchingArguments($argToCheck, $arrayRef);
915 return scalar @matchingIndices > 0;
918 sub checkForArgumentAndRemoveFromArrayRef
920 my ($argToCheck, $arrayRef) = @_;
921 my @indicesToRemove = findMatchingArguments($argToCheck, $arrayRef);
922 my $removeOffset = 0;
923 foreach my $index (@indicesToRemove) {
924 splice(@$arrayRef, $index - $removeOffset++, 1);
926 return scalar @indicesToRemove > 0;
931 if (defined($isWK2)) {
934 if (checkForArgumentAndRemoveFromARGV("-2")) {
944 return if defined($isEfl);
945 $isEfl = checkForArgumentAndRemoveFromARGV("--efl");
956 return if defined($isGtk);
957 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
966 # Determine if this is debian, ubuntu, linspire, or something similar.
969 return -e "/etc/debian_version";
974 return -e "/etc/fedora-release";
979 determineIsWinCairo();
983 sub determineIsWinCairo()
985 return if defined($isWinCairo);
986 $isWinCairo = checkForArgumentAndRemoveFromARGV("--wincairo");
995 sub determineIsWin64()
997 return if defined($isWin64);
998 $isWin64 = checkForArgumentAndRemoveFromARGV("--64-bit");
1003 return ($^O eq "cygwin") || 0;
1008 return isWindows() || isCygwin();
1011 sub determineWinVersion()
1013 return if $winVersion;
1015 if (!isAnyWindows()) {
1020 my $versionString = `cmd /c ver`;
1021 $versionString =~ /(\d)\.(\d)\.(\d+)/;
1032 determineWinVersion();
1038 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 1 && winVersion()->{build} == 7600;
1041 sub isWindowsVista()
1043 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 0;
1048 return isAnyWindows() && winVersion()->{major} == 5 && winVersion()->{minor} == 1;
1053 return ($^O eq "darwin") || 0;
1058 return ($^O eq "MSWin32") || 0;
1063 return ($^O eq "linux") || 0;
1068 return ($^O eq "freebsd") || ($^O eq "openbsd") || ($^O eq "netbsd") || 0;
1073 return ($Config{archname} =~ /^arm[v\-]/) || ($Config{archname} =~ /^aarch64[v\-]/);
1076 sub isCrossCompilation()
1079 $compiler = $ENV{'CC'} if (defined($ENV{'CC'}));
1080 if ($compiler =~ /gcc/) {
1081 my $compiler_options = `$compiler -v 2>&1`;
1082 my @host = $compiler_options =~ m/--host=(.*?)\s/;
1083 my @target = $compiler_options =~ m/--target=(.*?)\s/;
1085 return ($host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]);
1092 return isAppleMacWebKit() || isAppleWinWebKit();
1095 sub isAppleMacWebKit()
1097 return isDarwin() && !isGtk();
1100 sub isAppleWinWebKit()
1102 return (isCygwin() || isWindows()) && !isWinCairo() && !isGtk();
1105 sub iOSSimulatorDevicesPath
1107 return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";
1110 sub iOSSimulatorDevices
1112 eval "require Foundation";
1113 my $devicesPath = iOSSimulatorDevicesPath();
1114 opendir(DEVICES, $devicesPath);
1116 $_ =~ m/[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}/;
1121 Foundation::perlRefFromObjectRef(NSDictionary->dictionaryWithContentsOfFile_("$devicesPath/$_/device.plist"));
1127 sub createiOSSimulatorDevice
1130 my $deviceTypeId = shift;
1131 my $runtimeId = shift;
1133 my $created = system("xcrun", "--sdk", "iphonesimulator", "simctl", "create", $name, $deviceTypeId, $runtimeId) == 0;
1134 die "Couldn't create simulator device: $name $deviceTypeId $runtimeId" if not $created;
1136 system("xcrun", "--sdk", "iphonesimulator", "simctl", "list");
1138 print "Waiting for device to be created ...\n";
1140 for (my $tries = 0; $tries < 5; $tries++){
1141 my @devices = iOSSimulatorDevices();
1142 foreach my $device (@devices) {
1143 return $device if $device->{name} eq $name and $device->{deviceType} eq $deviceTypeId and $device->{runtime} eq $runtimeId;
1147 die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
1150 sub deleteiOSSimulatorDevice
1153 return system("xcrun", "--sdk", "iphonesimulator", "simctl", "delete", $udid);
1156 sub willUseIOSDeviceSDKWhenBuilding()
1158 return xcodeSDKPlatformName() eq "iphoneos";
1161 sub willUseIOSSimulatorSDKWhenBuilding()
1163 return xcodeSDKPlatformName() eq "iphonesimulator";
1168 determineXcodeSDK();
1169 return isAppleMacWebKit() && (willUseIOSDeviceSDKWhenBuilding() || willUseIOSSimulatorSDKWhenBuilding());
1172 sub determineNmPath()
1176 if (isAppleMacWebKit()) {
1177 $nmPath = `xcrun -find nm`;
1180 $nmPath = "nm" if !$nmPath;
1189 sub determineOSXVersion()
1191 return if $osXVersion;
1198 my $version = `sw_vers -productVersion`;
1199 my @splitVersion = split(/\./, $version);
1200 @splitVersion >= 2 or die "Invalid version $version";
1202 "major" => $splitVersion[0],
1203 "minor" => $splitVersion[1],
1204 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
1210 determineOSXVersion();
1216 return $ENV{'OS'} eq 'Windows_NT';
1219 sub shouldTargetWebProcess
1221 determineShouldTargetWebProcess();
1222 return $shouldTargetWebProcess;
1225 sub determineShouldTargetWebProcess
1227 return if defined($shouldTargetWebProcess);
1228 $shouldTargetWebProcess = checkForArgumentAndRemoveFromARGV("--target-web-process");
1231 sub shouldUseXPCServiceForWebProcess
1233 determineShouldUseXPCServiceForWebProcess();
1234 return $shouldUseXPCServiceForWebProcess;
1237 sub determineShouldUseXPCServiceForWebProcess
1239 return if defined($shouldUseXPCServiceForWebProcess);
1240 $shouldUseXPCServiceForWebProcess = checkForArgumentAndRemoveFromARGV("--use-web-process-xpc-service");
1245 determineDebugger();
1249 sub determineDebugger
1251 return if defined($debugger);
1253 determineXcodeVersion();
1254 if (eval "v$xcodeVersion" ge v4.5) {
1260 if (checkForArgumentAndRemoveFromARGV("--use-lldb")) {
1264 if (checkForArgumentAndRemoveFromARGV("--use-gdb")) {
1269 sub appendToEnvironmentVariableList
1271 my ($environmentVariableName, $value) = @_;
1273 if (defined($ENV{$environmentVariableName})) {
1274 $ENV{$environmentVariableName} .= ":" . $value;
1276 $ENV{$environmentVariableName} = $value;
1280 sub sharedCommandLineOptions()
1283 "g|guard-malloc" => \$shouldUseGuardMalloc,
1287 sub sharedCommandLineOptionsUsage
1292 '-g|--guard-malloc' => 'Use guardmalloc when running executable',
1295 my $indent = " " x ($opts{indent} || 2);
1296 my $switchWidth = List::Util::max(int($opts{switchWidth}), List::Util::max(map { length($_) } keys %switches) + ($opts{brackets} ? 2 : 0));
1298 my $result = "Common switches:\n";
1300 for my $switch (keys %switches) {
1301 my $switchName = $opts{brackets} ? "[" . $switch . "]" : $switch;
1302 $result .= sprintf("%s%-" . $switchWidth . "s %s\n", $indent, $switchName, $switches{$switch});
1308 sub setUpGuardMallocIfNeeded
1314 if (!defined($shouldUseGuardMalloc)) {
1315 $shouldUseGuardMalloc = checkForArgumentAndRemoveFromARGV("-g") || checkForArgumentAndRemoveFromARGV("--guard-malloc");
1318 if ($shouldUseGuardMalloc) {
1319 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", "/usr/lib/libgmalloc.dylib");
1323 sub relativeScriptsDir()
1325 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel($FindBin::Bin, getcwd()), "");
1326 if ($scriptDir eq "") {
1334 my $relativeScriptsPath = relativeScriptsDir();
1335 if (isGtk() || isEfl()) {
1336 return "$relativeScriptsPath/run-launcher";
1337 } elsif (isAppleWebKit()) {
1338 return "$relativeScriptsPath/run-safari";
1344 if (isGtk() || isEfl()) {
1345 return "MiniBrowser";
1346 } elsif (isAppleMacWebKit()) {
1348 } elsif (isAppleWinWebKit()) {
1349 return "WinLauncher";
1353 sub checkRequiredSystemConfig
1356 chomp(my $productVersion = `sw_vers -productVersion`);
1357 if (eval "v$productVersion" lt v10.7.5) {
1358 print "*************************************************************\n";
1359 print "Mac OS X Version 10.7.5 or later is required to build WebKit.\n";
1360 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
1361 print "*************************************************************\n";
1363 my $xcodebuildVersionOutput = `xcodebuild -version`;
1364 my $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : undef;
1365 if (!$xcodeVersion || $xcodeVersion && eval "v$xcodeVersion" lt v4.6) {
1366 print "*************************************************************\n";
1367 print "Xcode Version 4.6 or later is required to build WebKit.\n";
1368 print "You have an earlier version of Xcode, thus the build will\n";
1369 print "most likely fail. The latest Xcode is available from the App Store.\n";
1370 print "*************************************************************\n";
1372 } elsif (isGtk() or isEfl() or isWindows()) {
1373 my @cmds = qw(bison gperf flex);
1375 my $oldPath = $ENV{PATH};
1376 foreach my $cmd (@cmds) {
1377 push @missing, $cmd if not commandExists($cmd);
1381 my $list = join ", ", @missing;
1382 die "ERROR: $list missing but required to build WebKit.\n";
1385 # Win32 and other platforms may want to check for minimum config
1388 sub determineWindowsSourceDir()
1390 return if $windowsSourceDir;
1391 $windowsSourceDir = sourceDir();
1392 chomp($windowsSourceDir = `cygpath -w '$windowsSourceDir'`) if isCygwin();
1395 sub windowsSourceDir()
1397 determineWindowsSourceDir();
1398 return $windowsSourceDir;
1401 sub windowsSourceSourceDir()
1403 return windowsSourceDir() . "\\Source";
1406 sub windowsLibrariesDir()
1408 return windowsSourceDir() . "\\WebKitLibraries\\win";
1411 sub windowsOutputDir()
1413 return windowsSourceDir() . "\\WebKitBuild";
1419 my $val = system qw(regtool get), '\\HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\' . $font . ' (TrueType)';
1423 sub checkInstalledTools()
1425 # SVN 1.7.10 is known to be compatible with current servers. SVN 1.8.x seems to be missing some authentication
1426 # protocols we use for svn.webkit.org:
1427 my $svnVersion = `svn --version | grep "\\sversion"`;
1429 if (!$? and $svnVersion =~ /1\.8\./) {
1430 print "svn 1.7.10 is known to be compatible with our servers. You are running $svnVersion,\nwhich may not work properly.\n"
1433 # environment variables. Avoid until this is corrected.
1434 my $pythonVer = `python --version 2>&1`;
1435 die "You must have Python installed to build WebKit.\n" if ($?);
1437 # cURL 7.34.0 has a bug that prevents authentication with opensource.apple.com (and other things using SSL3).
1438 my $curlVer = `curl --version | grep "curl"`;
1440 if (!$? and $curlVer =~ /libcurl\/7\.34\.0/) {
1441 print "cURL version 7.34.0 has a bug that prevents authentication with SSL v2 or v3.\n";
1442 print "cURL 7.33.0 is known to work. The cURL projects is preparing an update to\n";
1443 print "correct this problem.\n\n";
1444 die "Please install a working cURL and try again.\n";
1447 # MathML requires fonts that do not ship with Windows (at least through Windows 8). Warn the user if they are missing
1448 my @fonts = qw(STIXGeneral-Regular MathJax_Main-Regular);
1450 foreach my $font (@fonts) {
1451 push @missing, $font if not fontExists($font);
1454 if (scalar @missing > 0) {
1455 print "*************************************************************\n";
1456 print "Mathematical fonts, such as STIX and MathJax, are needed to\n";
1457 print "use the MathML feature. You do not appear to have these fonts\n";
1458 print "on your system.\n\n";
1459 print "You can download a suitable set of fonts from the following URL:\n";
1460 print "https://developer.mozilla.org/Mozilla/MathML_Projects/Fonts\n";
1461 print "*************************************************************\n";
1464 print "Installed tools are correct for the WebKit build.\n";
1467 sub setupAppleWinEnv()
1469 return unless isAppleWinWebKit();
1471 checkInstalledTools();
1473 if (isWindowsNT()) {
1474 my $restartNeeded = 0;
1475 my %variablesToSet = ();
1477 # FIXME: We should remove this explicit version check for cygwin once we stop supporting Cygwin 1.7.9 or older versions.
1478 # https://bugs.webkit.org/show_bug.cgi?id=85791
1479 my $uname_version = (POSIX::uname())[2];
1480 $uname_version =~ s/\(.*\)//; # Remove the trailing cygwin version, if any.
1481 if (version->parse($uname_version) < version->parse("1.7.10")) {
1482 # Setting the environment variable 'CYGWIN' to 'tty' makes cygwin enable extra support (i.e., termios)
1483 # for UNIX-like ttys in the Windows console
1484 $variablesToSet{CYGWIN} = "tty" unless $ENV{CYGWIN};
1487 # Those environment variables must be set to be able to build inside Visual Studio.
1488 $variablesToSet{WEBKIT_LIBRARIES} = windowsLibrariesDir() unless $ENV{WEBKIT_LIBRARIES};
1489 $variablesToSet{WEBKIT_OUTPUTDIR} = windowsOutputDir() unless $ENV{WEBKIT_OUTPUTDIR};
1490 $variablesToSet{MSBUILDDISABLENODEREUSE} = "1" unless $ENV{MSBUILDDISABLENODEREUSE};
1492 foreach my $variable (keys %variablesToSet) {
1493 print "Setting the Environment Variable '" . $variable . "' to '" . $variablesToSet{$variable} . "'\n\n";
1494 system qw(regtool -s set), '\\HKEY_CURRENT_USER\\Environment\\' . $variable, $variablesToSet{$variable};
1495 $restartNeeded ||= $variable eq "WEBKIT_LIBRARIES" || $variable eq "WEBKIT_OUTPUTDIR";
1498 if ($restartNeeded) {
1499 print "Please restart your computer before attempting to build inside Visual Studio.\n\n";
1502 if (!defined $ENV{'WEBKIT_LIBRARIES'} || !$ENV{'WEBKIT_LIBRARIES'}) {
1503 print "Warning: You must set the 'WebKit_Libraries' environment variable\n";
1504 print " to be able build WebKit from within Visual Studio 2013 and newer.\n";
1505 print " Make sure that 'WebKit_Libraries' points to the\n";
1506 print " 'WebKitLibraries/win' directory, not the 'WebKitLibraries/' directory.\n\n";
1508 if (!defined $ENV{'WEBKIT_OUTPUTDIR'} || !$ENV{'WEBKIT_OUTPUTDIR'}) {
1509 print "Warning: You must set the 'WebKit_OutputDir' environment variable\n";
1510 print " to be able build WebKit from within Visual Studio 2013 and newer.\n\n";
1512 if (!defined $ENV{'MSBUILDDISABLENODEREUSE'} || !$ENV{'MSBUILDDISABLENODEREUSE'}) {
1513 print "Warning: You should set the 'MSBUILDDISABLENODEREUSE' environment variable to '1'\n";
1514 print " to avoid periodic locked log files when building.\n\n";
1517 # FIXME (125180): Remove the following temporary 64-bit support once official support is available.
1518 if (isWin64() and !$ENV{'WEBKIT_64_SUPPORT'}) {
1519 print "Warning: You must set the 'WEBKIT_64_SUPPORT' environment variable\n";
1520 print " to be able run WebKit or JavaScriptCore tests.\n\n";
1524 sub setupCygwinEnv()
1526 return if !isCygwin() && !isWindows();
1527 return if $vcBuildPath;
1529 my $programFilesPath = programFilesPath();
1530 $vcBuildPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE devenv.com));
1531 if (-e $vcBuildPath) {
1532 # Visual Studio is installed;
1533 if (visualStudioVersion() eq "12") {
1534 $vcBuildPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE devenv.exe));
1537 # Visual Studio not found, try VC++ Express
1538 $vcBuildPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE WDExpress.exe));
1539 if (! -e $vcBuildPath) {
1540 print "*************************************************************\n";
1541 print "Cannot find '$vcBuildPath'\n";
1542 print "Please execute the file 'vcvars32.bat' from\n";
1543 print "'$programFilesPath\\Microsoft Visual Studio 12.0\\VC\\bin\\'\n";
1544 print "to setup the necessary environment variables.\n";
1545 print "*************************************************************\n";
1548 $willUseVCExpressWhenBuilding = 1;
1551 print "Building results into: ", baseProductDir(), "\n";
1552 print "WEBKIT_OUTPUTDIR is set to: ", $ENV{"WEBKIT_OUTPUTDIR"}, "\n";
1553 print "WEBKIT_LIBRARIES is set to: ", $ENV{"WEBKIT_LIBRARIES"}, "\n";
1554 # FIXME (125180): Remove the following temporary 64-bit support once official support is available.
1555 print "WEBKIT_64_SUPPORT is set to: ", $ENV{"WEBKIT_64_SUPPORT"}, "\n" if isWin64();
1558 sub dieIfWindowsPlatformSDKNotInstalled
1560 my $registry32Path = "/proc/registry/";
1561 my $registry64Path = "/proc/registry64/";
1562 my @windowsPlatformSDKRegistryEntries = (
1563 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v8.0A",
1564 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v8.0",
1565 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.1A",
1566 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.0A",
1567 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1",
1570 # FIXME: It would be better to detect whether we are using 32- or 64-bit Windows
1571 # and only check the appropriate entry. But for now we just blindly check both.
1572 my $recommendedPlatformSDK = $windowsPlatformSDKRegistryEntries[0];
1574 while (@windowsPlatformSDKRegistryEntries) {
1575 my $windowsPlatformSDKRegistryEntry = shift @windowsPlatformSDKRegistryEntries;
1576 return if (-e $registry32Path . $windowsPlatformSDKRegistryEntry) || (-e $registry64Path . $windowsPlatformSDKRegistryEntry);
1579 print "*************************************************************\n";
1580 print "Cannot find registry entry '$recommendedPlatformSDK'.\n";
1581 print "Please download and install the Microsoft Windows SDK\n";
1582 print "from <http://www.microsoft.com/en-us/download/details.aspx?id=8279>.\n\n";
1583 print "Then follow step 2 in the Windows section of the \"Installing Developer\n";
1584 print "Tools\" instructions at <http://www.webkit.org/building/tools.html>.\n";
1585 print "*************************************************************\n";
1589 sub buildXCodeProject($$@)
1591 my ($project, $clean, @extraOptions) = @_;
1594 push(@extraOptions, "-alltargets");
1595 push(@extraOptions, "clean");
1598 push(@extraOptions, ("-sdk", "iphonesimulator")) if willUseIOSSimulatorSDKWhenBuilding();
1599 push(@extraOptions, ("-sdk", "iphoneos.internal")) if willUseIOSDeviceSDKWhenBuilding();
1601 chomp($ENV{DSYMUTIL_NUM_THREADS} = `sysctl -n hw.activecpu`);
1602 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
1605 sub usingVisualStudioExpress()
1608 return $willUseVCExpressWhenBuilding;
1611 sub buildVisualStudioProject
1613 my ($project, $clean) = @_;
1616 my $config = configurationForVisualStudio();
1618 dieIfWindowsPlatformSDKNotInstalled() if $willUseVCExpressWhenBuilding;
1620 chomp($project = `cygpath -w "$project"`) if isCygwin();
1622 my $action = "/build";
1627 my @command = ($vcBuildPath, $project, $action, $config);
1629 print join(" ", @command), "\n";
1630 return system @command;
1633 sub getJhbuildPath()
1635 my @jhbuildPath = File::Spec->splitdir(baseProductDir());
1636 if (isGit() && isGitBranchBuild() && gitBranch()) {
1640 push(@jhbuildPath, "DependenciesEFL");
1642 push(@jhbuildPath, "DependenciesGTK");
1644 die "Cannot get JHBuild path for platform that isn't GTK+ or EFL.\n";
1646 return File::Spec->catdir(@jhbuildPath);
1649 sub isCachedArgumentfileOutOfDate($@)
1651 my ($filename, $currentContents) = @_;
1653 if (! -e $filename) {
1657 open(CONTENTS_FILE, $filename);
1658 chomp(my $previousContents = <CONTENTS_FILE>);
1659 close(CONTENTS_FILE);
1661 if ($previousContents ne $currentContents) {
1662 print "Contents for file $filename have changed.\n";
1663 print "Previous contents were: $previousContents\n\n";
1664 print "New contents are: $currentContents\n";
1671 sub jhbuildWrapperPrefixIfNeeded()
1673 if (-e getJhbuildPath()) {
1674 my @prefix = (File::Spec->catfile(sourceDir(), "Tools", "jhbuild", "jhbuild-wrapper"));
1676 push(@prefix, "--efl");
1678 push(@prefix, "--gtk");
1680 push(@prefix, "run");
1688 sub cmakeCachePath()
1690 return File::Spec->catdir(baseProductDir(), configuration(), "CMakeCache.txt");
1693 sub shouldRemoveCMakeCache(@)
1695 my ($cacheFilePath, @buildArgs) = @_;
1697 # We check this first, because we always want to create this file for a fresh build.
1698 my $productDir = File::Spec->catdir(baseProductDir(), configuration());
1699 my $optionsCache = File::Spec->catdir($productDir, "build-webkit-options.txt");
1700 my $joinedBuildArgs = join(" ", @buildArgs);
1701 if (isCachedArgumentfileOutOfDate($optionsCache, $joinedBuildArgs)) {
1702 File::Path::mkpath($productDir) unless -d $productDir;
1703 open(CACHED_ARGUMENTS, ">", $optionsCache);
1704 print CACHED_ARGUMENTS $joinedBuildArgs;
1705 close(CACHED_ARGUMENTS);
1710 my $cmakeCache = cmakeCachePath();
1711 unless (-e $cmakeCache) {
1715 my $cacheFileModifiedTime = stat($cmakeCache)->mtime;
1716 my $platformConfiguration = File::Spec->catdir(sourceDir(), "Source", "cmake", "Options" . cmakeBasedPortName() . ".cmake");
1717 if ($cacheFileModifiedTime < stat($platformConfiguration)->mtime) {
1721 my $globalConfiguration = File::Spec->catdir(sourceDir(), "Source", "cmake", "OptionsCommon.cmake");
1722 if ($cacheFileModifiedTime < stat($globalConfiguration)->mtime) {
1729 sub removeCMakeCache(@)
1731 my (@buildArgs) = @_;
1732 if (shouldRemoveCMakeCache(@buildArgs)) {
1733 my $cmakeCache = cmakeCachePath();
1734 unlink($cmakeCache) if -e $cmakeCache;
1740 # Test both ninja and ninja-build. Fedora uses ninja-build and has patched CMake to also call ninja-build.
1741 system('which ninja > /dev/null || which ninja-build > /dev/null');
1745 sub canUseEclipse(@)
1747 system('which eclipse > /dev/null');
1751 sub cmakeGeneratedBuildfile(@)
1753 my ($willUseNinja) = @_;
1754 if ($willUseNinja) {
1755 return File::Spec->catfile(baseProductDir(), configuration(), "build.ninja")
1757 return File::Spec->catfile(baseProductDir(), configuration(), "Makefile")
1761 sub generateBuildSystemFromCMakeProject
1763 my ($port, $prefixPath, @cmakeArgs, $additionalCMakeArgs) = @_;
1764 my $config = configuration();
1765 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1766 File::Path::mkpath($buildPath) unless -d $buildPath;
1767 my $originalWorkingDirectory = getcwd();
1768 chdir($buildPath) or die;
1770 # We try to be smart about when to rerun cmake, so that we can have faster incremental builds.
1771 my $willUseNinja = canUseNinja();
1772 if (-e cmakeCachePath() && -e cmakeGeneratedBuildfile($willUseNinja)) {
1777 push @args, "-DPORT=\"$port\"";
1778 push @args, "-DCMAKE_INSTALL_PREFIX=\"$prefixPath\"" if $prefixPath;
1779 push @args, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" if isGtk();
1780 if ($config =~ /release/i) {
1781 push @args, "-DCMAKE_BUILD_TYPE=Release";
1782 } elsif ($config =~ /debug/i) {
1783 push @args, "-DCMAKE_BUILD_TYPE=Debug";
1786 if ($willUseNinja) {
1788 if (canUseEclipse()) {
1789 push @args, "'Eclipse CDT4 - Ninja'";
1791 push @args, "Ninja";
1795 # GTK+ has a production mode, but build-webkit should always use developer mode.
1796 push @args, "-DDEVELOPER_MODE=ON" if isEfl() || isGtk();
1798 # Don't warn variables which aren't used by cmake ports.
1799 push @args, "--no-warn-unused-cli";
1800 push @args, @cmakeArgs if @cmakeArgs;
1801 push @args, $additionalCMakeArgs if $additionalCMakeArgs;
1803 push @args, '"' . sourceDir() . '"';
1805 # Compiler options to keep floating point values consistent
1806 # between 32-bit and 64-bit architectures.
1807 determineArchitecture();
1808 if ($architecture ne "x86_64" && !isARM() && !isCrossCompilation()) {
1809 $ENV{'CXXFLAGS'} = "-march=pentium4 -msse2 -mfpmath=sse " . ($ENV{'CXXFLAGS'} || "");
1812 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1813 # parsed for shell metacharacters.
1814 my $wrapper = join(" ", jhbuildWrapperPrefixIfNeeded()) . " ";
1815 my $returnCode = system($wrapper . "cmake @args");
1817 chdir($originalWorkingDirectory);
1821 sub buildCMakeGeneratedProject($)
1823 my ($makeArgs) = @_;
1824 my $config = configuration();
1825 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1826 if (! -d $buildPath) {
1827 die "Must call generateBuildSystemFromCMakeProject() before building CMake project.";
1830 my $command = "cmake";
1831 my @args = ("--build", $buildPath, "--config", $config);
1832 push @args, ("--", $makeArgs) if $makeArgs;
1834 # GTK can use a build script to preserve colors and pretty-printing.
1835 if (isGtk() && -e "$buildPath/build.sh") {
1836 chdir "$buildPath" or die;
1837 $command = "$buildPath/build.sh";
1838 @args = ($makeArgs);
1841 if ($ENV{VERBOSE} && canUseNinja()) {
1843 push @args, "-d keeprsp" if (version->parse(determineNinjaVersion()) >= version->parse("1.4.0"));
1846 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1847 # parsed for shell metacharacters. In particular, $makeArgs may contain such metacharacters.
1848 my $wrapper = join(" ", jhbuildWrapperPrefixIfNeeded()) . " ";
1849 return system($wrapper . "$command @args");
1853 sub cleanCMakeGeneratedProject()
1855 my $config = configuration();
1856 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1857 if (-d $buildPath) {
1858 return system("cmake", "--build", $buildPath, "--config", $config, "--target", "clean");
1863 sub buildCMakeProjectOrExit($$$$@)
1865 my ($clean, $port, $prefixPath, $makeArgs, @cmakeArgs) = @_;
1868 exit(exitStatus(cleanCMakeGeneratedProject())) if $clean;
1870 if (isEfl() && checkForArgumentAndRemoveFromARGV("--update-efl")) {
1871 system("perl", "$sourceDir/Tools/Scripts/update-webkitefl-libs") == 0 or die $!;
1874 if (isGtk() && checkForArgumentAndRemoveFromARGV("--update-gtk")) {
1875 system("perl", "$sourceDir/Tools/Scripts/update-webkitgtk-libs") == 0 or die $!;
1878 $returnCode = exitStatus(generateBuildSystemFromCMakeProject($port, $prefixPath, @cmakeArgs));
1879 exit($returnCode) if $returnCode;
1881 $returnCode = exitStatus(buildCMakeGeneratedProject($makeArgs));
1882 exit($returnCode) if $returnCode;
1886 sub cmakeBasedPortArguments()
1891 sub cmakeBasedPortName()
1893 return "Efl" if isEfl();
1894 return "GTK" if isGtk();
1900 return isEfl() || isGtk();
1905 my ($prompt, $default) = @_;
1906 my $defaultValue = $default ? "[$default]" : "";
1907 print "$prompt $defaultValue: ";
1908 chomp(my $input = <STDIN>);
1909 return $input ? $input : $default;
1912 sub appleApplicationSupportPath
1914 open INSTALL_DIR, "</proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Apple\ Inc./Apple\ Application\ Support/InstallDir";
1915 my $path = <INSTALL_DIR>;
1916 $path =~ s/[\r\n\x00].*//;
1919 my $unixPath = `cygpath -u '$path'`;
1924 sub setPathForRunningWebKitApp
1928 if (isAppleWinWebKit()) {
1929 $env->{PATH} = join(':', productDir(), appleApplicationSupportPath(), $env->{PATH} || "");
1930 } elsif (isWinCairo()) {
1931 my $winCairoBin = sourceDir() . "/WebKitLibraries/win/" . (isWin64() ? "bin64/" : "bin32/");
1932 my $gstreamerBin = isWin64() ? $ENV{"GSTREAMER_1_0_ROOT_X86_64"} . "bin" : $ENV{"GSTREAMER_1_0_ROOT_X86"} . "bin";
1933 $env->{PATH} = join(':', productDir(), $winCairoBin, $gstreamerBin, $env->{PATH} || "");
1937 sub printHelpAndExitForRunAndDebugWebKitAppIfNeeded
1939 return unless checkForArgumentAndRemoveFromARGV("--help");
1941 my ($includeOptionsForDebugging) = @_;
1944 Usage: @{[basename($0)]} [options] [args ...]
1945 --help Show this help message
1946 --no-saved-state Launch the application without state restoration (OS X 10.7 and later)
1947 -g|--guard-malloc Enable Guard Malloc (OS X only)
1948 --use-web-process-xpc-service Launch the Web Process as an XPC Service (OS X only)
1951 if ($includeOptionsForDebugging) {
1953 --target-web-process Debug the web process
1954 --use-gdb Use GDB (this is the default when using Xcode 4.4 or earlier)
1955 --use-lldb Use LLDB (this is the default when using Xcode 4.5 or later)
1962 sub argumentsForRunAndDebugMacWebKitApp()
1965 if (checkForArgumentAndRemoveFromARGV("--no-saved-state")) {
1966 push @args, ("-ApplePersistenceIgnoreStateQuietly", "YES");
1967 # FIXME: Don't set ApplePersistenceIgnoreState once all supported OS versions respect ApplePersistenceIgnoreStateQuietly (rdar://15032886).
1968 push @args, ("-ApplePersistenceIgnoreState", "YES");
1970 push @args, ("-WebKit2UseXPCServiceForWebProcess", "YES") if shouldUseXPCServiceForWebProcess();
1971 unshift @args, @ARGV;
1976 sub setupMacWebKitEnvironment($)
1978 my ($dyldFrameworkPath) = @_;
1980 $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
1982 $ENV{DYLD_FRAMEWORK_PATH} = $ENV{DYLD_FRAMEWORK_PATH} ? join(":", $dyldFrameworkPath, $ENV{DYLD_FRAMEWORK_PATH}) : $dyldFrameworkPath;
1983 $ENV{__XPC_DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
1984 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
1986 setUpGuardMallocIfNeeded();
1989 sub setupIOSWebKitEnvironment($)
1991 my ($dyldFrameworkPath) = @_;
1992 $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
1994 $ENV{DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
1995 $ENV{DYLD_LIBRARY_PATH} = $dyldFrameworkPath;
1997 setUpGuardMallocIfNeeded();
2000 sub installedMobileSafariBundle()
2002 return File::Spec->catfile(XcodeSDKPath(), "Applications", "MobileSafari.app");
2005 sub mobileSafariBundle()
2007 determineConfigurationProductDir();
2009 # Use MobileSafari.app in product directory if present.
2010 if (isAppleMacWebKit() && -d "$configurationProductDir/MobileSafari.app") {
2011 return "$configurationProductDir/MobileSafari.app";
2013 return installedMobileSafariBundle();
2016 sub plistPathFromBundle($)
2018 my ($appBundle) = @_;
2019 return "$appBundle/Info.plist" if -f "$appBundle/Info.plist"; # iOS app bundle
2020 return "$appBundle/Contents/Info.plist" if "$appBundle/Contents/Info.plist"; # Mac app bundle
2024 sub appIdentiferFromBundle($)
2026 my ($appBundle) = @_;
2027 my $plistPath = plistPathFromBundle($appBundle);
2028 chomp(my $bundleIdentifer = `defaults read '$plistPath' CFBundleIdentifier 2> /dev/null`);
2029 return $bundleIdentifer;
2032 sub appDisplayNameFromBundle($)
2034 my ($appBundle) = @_;
2035 my $plistPath = plistPathFromBundle($appBundle);
2036 chomp(my $bundleDisplayName = `defaults read '$plistPath' CFBundleDisplayName 2> /dev/null`);
2037 return $bundleDisplayName;
2040 sub loadIPhoneSimulatorNotificationIfNeeded()
2042 return if $didLoadIPhoneSimulatorNotification;
2043 push(@INC, productDir() . "/lib/perl5/darwin-thread-multi-2level");
2044 require IPhoneSimulatorNotification;
2045 $didLoadIPhoneSimulatorNotification = 1;
2048 sub openIOSSimulator()
2050 chomp(my $developerDirectory = $ENV{DEVELOPER_DIR} || `xcode-select --print-path`);
2051 my $iosSimulatorPath = File::Spec->catfile($developerDirectory, "Applications", "iOS Simulator.app");
2053 loadIPhoneSimulatorNotificationIfNeeded();
2055 my $iPhoneSimulatorNotification = new IPhoneSimulatorNotification;
2056 $iPhoneSimulatorNotification->startObservingReadyNotification();
2057 system("open", "-a", $iosSimulatorPath, "--args", "-SessionOnLaunch", "NO") == 0 or die "Failed to open $iosSimulatorPath: $!";
2058 while (!$iPhoneSimulatorNotification->hasReceivedReadyNotification()) {
2059 my $date = NSDate->alloc()->initWithTimeIntervalSinceNow_(0.1);
2060 NSRunLoop->currentRunLoop->runUntilDate_($date);
2063 $iPhoneSimulatorNotification->stopObservingReadyNotification();
2066 sub iosSimulatorDeviceByName($)
2068 my ($simulatorName) = @_;
2069 my @devices = grep {$_->{name} eq $simulatorName} iOSSimulatorDevices();
2070 my $deviceToUse = $devices[0];
2072 print "Warning: Found more than one simulator device named '$simulatorName'.\n";
2073 print " Using simulator device with UDID: $deviceToUse->{UDID}.\n";
2074 print " To see the list of simulator devices, run:\n";
2075 print " xcrun --sdk iphonesimulator simctl list\n";
2077 return $deviceToUse;
2080 sub iosSimulatorRuntime()
2082 my $xcodeSDKVersion = xcodeSDKVersion();
2083 $xcodeSDKVersion =~ s/\./-/;
2084 return "com.apple.CoreSimulator.SimRuntime.iOS-$xcodeSDKVersion";
2087 sub findOrCreateSimulatorForIOSDevice($)
2089 my ($simulatorNameSuffix) = @_;
2091 my $simulatorDeviceType;
2092 if (architecture() eq "x86_64") {
2093 $simulatorName = "iPhone 5s " . $simulatorNameSuffix;
2094 $simulatorDeviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5s";
2096 $simulatorName = "iPhone 5 " . $simulatorNameSuffix;
2097 $simulatorDeviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
2099 my $simulatedDevice = iosSimulatorDeviceByName($simulatorName);
2100 return $simulatedDevice if $simulatedDevice;
2101 return createiOSSimulatorDevice($simulatorName, $simulatorDeviceType, iosSimulatorRuntime());
2104 sub runIOSWebKitAppInSimulator($;$)
2106 my ($appBundle, $simulatorOptions) = @_;
2107 my $productDir = productDir();
2108 my $appDisplayName = appDisplayNameFromBundle($appBundle);
2109 print "Starting $appDisplayName with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2111 $simulatorOptions = {} unless $simulatorOptions;
2114 %simulatorENV = %{$simulatorOptions->{applicationEnvironment}} if $simulatorOptions->{applicationEnvironment};
2116 local %ENV; # Shadow global-scope %ENV so that changes to it will not be seen outside of this scope.
2117 setupIOSWebKitEnvironment($productDir);
2118 %simulatorENV = %ENV;
2120 $simulatorOptions->{applicationEnvironment} = \%simulatorENV;
2121 return installAndLaunchIOSWebKitAppInSimulator($appBundle, findOrCreateSimulatorForIOSDevice("For WebKit Development"), $simulatorOptions) <= 0;
2124 # Launches the iOS WebKit-based application in the specified simulator device and dynamically
2125 # linked against the built WebKit. The application will be installed if applicable.
2128 # $appBundle: the path to the app bundle to launch.
2129 # $simulatedDevice: the simulator device to use to run the app.
2130 # $simulatorOptions: a hash reference representing optional simulator options.
2131 # sessionUUID: a unique identifer to use for the iOS Simulator session. Defaults to an identifer
2132 # of the form "theAwesomeUniqueSessionIdentifierForX" where X is the display name of
2133 # the specified app.
2134 # applicationArguments: an array reference representing the arguments to pass to the app (defaults to \@ARGV).
2135 # applicationEnvironment: a hash reference representing the environment variables to use when launching the app (defaults to {}).
2137 # Returns the process identifier of the launched app.
2138 sub installAndLaunchIOSWebKitAppInSimulator($$;$)
2140 my ($appBundle, $simulatedDevice, $simulatorOptions) = @_;
2142 loadIPhoneSimulatorNotificationIfNeeded();
2144 my $makeNSDictionaryFromHash = sub {
2146 my $result = NSMutableDictionary->alloc()->initWithCapacity_(scalar(keys %{$dict}));
2147 for my $key (keys %{$dict}) {
2148 $result->setObject_forKey_(NSString->stringWithCString_($dict->{$key}), NSString->stringWithCString_($key));
2150 return $result->autorelease();
2152 my $makeNSArrayFromArray = sub {
2154 my $result = NSMutableArray->alloc()->initWithCapacity_(scalar(@{$array}));
2155 for my $item (@{$array}) {
2156 $result->addObject_(NSString->stringWithCString_($item));
2158 return $result->autorelease();
2161 my $simulatorENVHashRef = {};
2162 $simulatorENVHashRef = $simulatorOptions->{applicationEnvironment} if $simulatorOptions && $simulatorOptions->{applicationEnvironment};
2163 my $applicationArguments = \@ARGV;
2164 $applicationArguments = $simulatorOptions->{applicationArguments} if $simulatorOptions && $simulatorOptions->{applicationArguments};
2166 if ($simulatorOptions && $simulatorOptions->{sessionUUID}) {
2167 $sessionUUID = $simulatorOptions->{sessionUUID};
2169 $sessionUUID = "theAwesomeUniqueSessionIdentifierFor" . appDisplayNameFromBundle($appBundle);
2171 # FIXME: We should have the iOS application adopt the files descriptors for our standard output and error streams.
2173 applicationArguments => &$makeNSArrayFromArray($applicationArguments),
2174 applicationEnvironment => &$makeNSDictionaryFromHash($simulatorENVHashRef),
2175 applicationIdentifier => NSString->stringWithCString_(appIdentiferFromBundle($appBundle)),
2176 applicationPath => NSString->stringWithCString_($appBundle),
2177 deviceUDID => NSString->stringWithCString_($simulatedDevice->{UDID}),
2178 sessionUUID => NSString->stringWithCString_($sessionUUID),
2183 my $iPhoneSimulatorNotification = new IPhoneSimulatorNotification;
2184 $iPhoneSimulatorNotification->startObservingApplicationLaunchedNotification();
2185 $iPhoneSimulatorNotification->postStartSessionNotification($sessionInfo);
2186 while (!$iPhoneSimulatorNotification->hasReceivedApplicationLaunchedNotification()) {
2187 my $date = NSDate->alloc()->initWithTimeIntervalSinceNow_(0.1);
2188 NSRunLoop->currentRunLoop->runUntilDate_($date);
2191 $iPhoneSimulatorNotification->stopObservingApplicationLaunchedNotification();
2192 return $iPhoneSimulatorNotification->applicationLaunchedApplicationPID();
2195 sub runIOSWebKitApp($)
2197 my ($appBundle) = @_;
2198 if (willUseIOSDeviceSDKWhenBuilding()) {
2199 die "Only running Safari in iOS Simulator is supported now.";
2201 if (willUseIOSSimulatorSDKWhenBuilding()) {
2202 return runIOSWebKitAppInSimulator($appBundle);
2204 die "Not using an iOS SDK."
2207 sub runMacWebKitApp($;$)
2209 my ($appPath, $useOpenCommand) = @_;
2210 my $productDir = productDir();
2211 print "Starting @{[basename($appPath)]} with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2214 setupMacWebKitEnvironment($productDir);
2216 if (defined($useOpenCommand) && $useOpenCommand == USE_OPEN_COMMAND) {
2217 return system("open", "-W", "-a", $appPath, "--args", argumentsForRunAndDebugMacWebKitApp());
2219 if (architecture()) {
2220 return system "arch", "-" . architecture(), $appPath, argumentsForRunAndDebugMacWebKitApp();
2222 return system { $appPath } $appPath, argumentsForRunAndDebugMacWebKitApp();
2225 sub execMacWebKitAppForDebugging($)
2228 my $architectureSwitch;
2229 my $argumentsSeparator;
2231 if (debugger() eq "lldb") {
2232 $architectureSwitch = "--arch";
2233 $argumentsSeparator = "--";
2234 } elsif (debugger() eq "gdb") {
2235 $architectureSwitch = "-arch";
2236 $argumentsSeparator = "--args";
2238 die "Unknown debugger $debugger.\n";
2241 my $debuggerPath = `xcrun -find $debugger`;
2242 chomp $debuggerPath;
2243 die "Can't find the $debugger executable.\n" unless -x $debuggerPath;
2245 my $productDir = productDir();
2246 setupMacWebKitEnvironment($productDir);
2248 my @architectureFlags = ($architectureSwitch, architecture());
2249 if (!shouldTargetWebProcess()) {
2250 print "Starting @{[basename($appPath)]} under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2251 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $appPath, argumentsForRunAndDebugMacWebKitApp() or die;
2253 if (shouldUseXPCServiceForWebProcess()) {
2254 die "Targetting the Web Process is not compatible with using an XPC Service for the Web Process at this time.";
2257 my $webProcessShimPath = File::Spec->catfile($productDir, "SecItemShim.dylib");
2258 my $webProcessPath = File::Spec->catdir($productDir, "WebProcess.app");
2259 my $webKit2ExecutablePath = File::Spec->catfile($productDir, "WebKit2.framework", "WebKit2");
2261 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", $webProcessShimPath);
2263 print "Starting WebProcess under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2264 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $webProcessPath, $webKit2ExecutablePath, "-type", "webprocess", "-client-executable", $appPath or die;
2270 if (isAppleMacWebKit()) {
2272 execMacWebKitAppForDebugging(safariPath());
2275 return 1; # Unsupported platform; can't debug Safari on this platform.
2280 if (isIOSWebKit()) {
2281 return runIOSWebKitApp(mobileSafariBundle());
2284 if (isAppleMacWebKit()) {
2285 return runMacWebKitApp(safariPath());
2288 if (isAppleWinWebKit()) {
2290 my $productDir = productDir();
2291 my $webKitLauncherPath = File::Spec->catfile(productDir(), "WinLauncher.exe");
2292 return system { $webKitLauncherPath } $webKitLauncherPath, @ARGV;
2295 return 1; # Unsupported platform; can't run Safari on this platform.
2300 if (isAppleMacWebKit()) {
2301 return runMacWebKitApp(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2307 sub debugMiniBrowser
2309 if (isAppleMacWebKit()) {
2310 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2316 sub runWebKitTestRunner
2318 if (isAppleMacWebKit()) {
2319 return runMacWebKitApp(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2325 sub debugWebKitTestRunner
2327 if (isAppleMacWebKit()) {
2328 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2334 sub readRegistryString
2336 my ($valueName) = @_;
2337 chomp(my $string = `regtool --wow32 get "$valueName"`);
2341 sub writeRegistryString
2343 my ($valueName, $string) = @_;
2345 my $error = system "regtool", "--wow32", "set", "-s", $valueName, $string;
2347 # On Windows Vista/7 with UAC enabled, regtool will fail to modify the registry, but will still
2348 # return a successful exit code. So we double-check here that the value we tried to write to the
2349 # registry was really written.
2350 return !$error && readRegistryString($valueName) eq $string;
2353 sub formatBuildTime($)
2355 my ($buildTime) = @_;
2357 my $buildHours = int($buildTime / 3600);
2358 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
2359 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
2362 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
2364 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
2367 sub runSvnUpdateAndResolveChangeLogs(@)
2369 my @svnOptions = @_;
2370 open UPDATE, "-|", "svn", "update", @svnOptions or die;
2371 my @conflictedChangeLogs;
2372 while (my $line = <UPDATE>) {
2374 $line =~ m/^C\s+(.+?)[\r\n]*$/;
2376 my $filename = normalizePath($1);
2377 push @conflictedChangeLogs, $filename if basename($filename) eq "ChangeLog";
2380 close UPDATE or die;
2382 if (@conflictedChangeLogs) {
2383 print "Attempting to merge conflicted ChangeLogs.\n";
2384 my $resolveChangeLogsPath = File::Spec->catfile(sourceDir(), "Tools", "Scripts", "resolve-ChangeLogs");
2385 (system($resolveChangeLogsPath, "--no-warnings", @conflictedChangeLogs) == 0)
2386 or die "Could not open resolve-ChangeLogs script: $!.\n";
2392 # Doing a git fetch first allows setups with svn-remote.svn.fetch = trunk:refs/remotes/origin/master
2393 # to perform the rebase much much faster.
2394 system("git", "fetch");
2396 system("git", "svn", "rebase") == 0 or die;
2398 # This will die if branch.$BRANCHNAME.merge isn't set, which is
2399 # almost certainly what we want.
2400 system("git", "pull") == 0 or die;