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.
37 use Digest::MD5 qw(md5_hex);
41 use File::Path qw(make_path mkpath rmtree);
46 use Time::HiRes qw(usleep);
51 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
55 &XcodeCoverageSupportOptions
57 &XcodeOptionStringNoConfig
59 &XcodeStaticAnalyzerOption
60 &appDisplayNameFromBundle
64 &cmakeBasedPortArguments
68 &findOrCreateSimulatorForIOSDevice
69 &iosSimulatorDeviceByName
72 &printHelpAndExitForRunAndDebugWebKitAppIfNeeded
80 &setupMacWebKitEnvironment
81 &sharedCommandLineOptions
82 &sharedCommandLineOptionsUsage
83 SIMULATOR_DEVICE_SUFFIX_FOR_WEBKIT_DEVELOPMENT
90 use constant USE_OPEN_COMMAND => 1; # Used in runMacWebKitApp().
91 use constant INCLUDE_OPTIONS_FOR_DEBUGGING => 1;
92 use constant SIMULATOR_DEVICE_STATE_SHUTDOWN => "1";
93 use constant SIMULATOR_DEVICE_STATE_BOOTED => "3";
94 use constant SIMULATOR_DEVICE_SUFFIX_FOR_WEBKIT_DEVELOPMENT => "For WebKit Development";
103 my @baseProductDirOption;
106 my $configurationForVisualStudio;
107 my $configurationProductDir;
109 my $currentSVNRevision;
111 my $didLoadIPhoneSimulatorNotification;
119 my $isInspectorFrontend;
120 my $shouldTargetWebProcess;
121 my $shouldUseXPCServiceForWebProcess;
122 my $shouldUseGuardMalloc;
125 # Variables for Win32 support
126 my $programFilesPath;
129 my $msBuildInstallDir;
131 my $windowsSourceDir;
133 my $willUseVCExpressWhenBuilding = 0;
135 # Defined in VCSUtils.
138 sub findMatchingArguments($$);
141 sub determineSourceDir
143 return if $sourceDir;
144 $sourceDir = $FindBin::Bin;
145 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
147 # walks up path checking each directory to see if it is the main WebKit project dir,
148 # defined by containing Sources, WebCore, and WebKit
149 until ((-d File::Spec->catdir($sourceDir, "Source") && -d File::Spec->catdir($sourceDir, "Source", "WebCore") && -d File::Spec->catdir($sourceDir, "Source", "WebKit")) || (-d File::Spec->catdir($sourceDir, "Internal") && -d File::Spec->catdir($sourceDir, "OpenSource")))
151 if ($sourceDir !~ s|/[^/]+$||) {
152 die "Could not find top level webkit directory above source directory using FindBin.\n";
156 $sourceDir = File::Spec->catdir($sourceDir, "OpenSource") if -d File::Spec->catdir($sourceDir, "OpenSource");
159 sub currentPerlPath()
163 $thisPerl .= $Config{_exe} unless $thisPerl =~ m/$Config{_exe}$/i;
168 # used for scripts which are stored in a non-standard location
174 sub determineNinjaVersion
176 chomp(my $ninjaVersion = `ninja --version`);
177 return $ninjaVersion;
180 sub determineXcodeVersion
182 return if defined $xcodeVersion;
183 my $xcodebuildVersionOutput = `xcodebuild -version`;
184 $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : "3.0";
187 sub readXcodeUserDefault($)
189 my ($unprefixedKey) = @_;
191 determineXcodeVersion();
193 my $xcodeDefaultsDomain = (eval "v$xcodeVersion" lt v4) ? "com.apple.Xcode" : "com.apple.dt.Xcode";
194 my $xcodeDefaultsPrefix = (eval "v$xcodeVersion" lt v4) ? "PBX" : "IDE";
195 my $devnull = File::Spec->devnull();
197 my $value = `defaults read $xcodeDefaultsDomain ${xcodeDefaultsPrefix}${unprefixedKey} 2> ${devnull}`;
204 sub determineBaseProductDir
206 return if defined $baseProductDir;
207 determineSourceDir();
209 my $setSharedPrecompsDir;
210 $baseProductDir = $ENV{"WEBKIT_OUTPUTDIR"};
212 if (!defined($baseProductDir) and isAppleMacWebKit()) {
213 # Silently remove ~/Library/Preferences/xcodebuild.plist which can
214 # cause build failure. The presence of
215 # ~/Library/Preferences/xcodebuild.plist can prevent xcodebuild from
216 # respecting global settings such as a custom build products directory
217 # (<rdar://problem/5585899>).
218 my $personalPlistFile = $ENV{HOME} . "/Library/Preferences/xcodebuild.plist";
219 if (-e $personalPlistFile) {
220 unlink($personalPlistFile) || die "Could not delete $personalPlistFile: $!";
223 determineXcodeVersion();
225 if (eval "v$xcodeVersion" ge v4) {
226 my $buildLocationStyle = join '', readXcodeUserDefault("BuildLocationStyle");
227 if ($buildLocationStyle eq "Custom") {
228 my $buildLocationType = join '', readXcodeUserDefault("CustomBuildLocationType");
229 # FIXME: Read CustomBuildIntermediatesPath and set OBJROOT accordingly.
230 $baseProductDir = readXcodeUserDefault("CustomBuildProductsPath") if $buildLocationType eq "Absolute";
233 # DeterminedByTargets corresponds to a setting of "Legacy" in Xcode.
234 # It is the only build location style for which SHARED_PRECOMPS_DIR is not
235 # overridden when building from within Xcode.
236 $setSharedPrecompsDir = 1 if $buildLocationStyle ne "DeterminedByTargets";
239 if (!defined($baseProductDir)) {
240 $baseProductDir = join '', readXcodeUserDefault("ApplicationwideBuildSettings");
241 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
244 undef $baseProductDir unless $baseProductDir =~ /^\//;
247 if (!defined($baseProductDir)) { # Port-specific checks failed, use default
248 $baseProductDir = "$sourceDir/WebKitBuild";
251 if (isGit() && isGitBranchBuild()) {
252 my $branch = gitBranch();
253 $baseProductDir = "$baseProductDir/$branch";
256 if (isAppleMacWebKit()) {
257 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
258 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
259 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
260 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
261 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
262 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir");
263 push(@baseProductDirOption, "SHARED_PRECOMPS_DIR=${baseProductDir}/PrecompiledHeaders") if $setSharedPrecompsDir;
267 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
269 $ENV{"WEBKIT_OUTPUTDIR"} = $dosBuildPath;
270 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
271 chomp $unixBuildPath;
272 $baseProductDir = $unixBuildPath;
276 sub setBaseProductDir($)
278 ($baseProductDir) = @_;
281 sub determineConfiguration
283 return if defined $configuration;
284 determineBaseProductDir();
285 if (open CONFIGURATION, "$baseProductDir/Configuration") {
286 $configuration = <CONFIGURATION>;
289 if ($configuration) {
290 chomp $configuration;
291 # compatibility for people who have old Configuration files
292 $configuration = "Release" if $configuration eq "Deployment";
293 $configuration = "Debug" if $configuration eq "Development";
295 $configuration = "Release";
299 sub determineArchitecture
301 return if defined $architecture;
302 # make sure $architecture is defined in all cases
305 determineBaseProductDir();
308 if (isAppleMacWebKit()) {
309 if (open ARCHITECTURE, "$baseProductDir/Architecture") {
310 $architecture = <ARCHITECTURE>;
316 if (not defined $xcodeSDK or $xcodeSDK =~ /^(\/$|macosx)/) {
317 my $supports64Bit = `sysctl -n hw.optional.x86_64`;
318 chomp $supports64Bit;
319 $architecture = 'x86_64' if $supports64Bit;
320 } elsif ($xcodeSDK =~ /^iphonesimulator/) {
321 $architecture = 'x86_64';
322 } elsif ($xcodeSDK =~ /^iphoneos/) {
323 $architecture = 'armv7';
326 } elsif (isEfl() || isGtk()) {
327 my $host_processor = "";
328 $host_processor = `cmake --system-information | grep CMAKE_SYSTEM_PROCESSOR`;
329 if ($host_processor =~ m/^CMAKE_SYSTEM_PROCESSOR \"([^"]+)\"/) {
330 # We have a configured build tree; use it.
332 $architecture = 'x86_64' if $architecture eq 'amd64';
336 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
337 # Fall back to output of `arch', if it is present.
338 $architecture = `arch`;
342 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
343 # Fall back to output of `uname -m', if it is present.
344 $architecture = `uname -m`;
348 $architecture = 'x86_64' if ($architecture =~ /amd64/ && isBSD());
351 sub determineASanIsEnabled
353 return if defined $asanIsEnabled;
354 determineBaseProductDir();
357 my $asanConfigurationValue;
359 if (open ASAN, "$baseProductDir/ASan") {
360 $asanConfigurationValue = <ASAN>;
362 chomp $asanConfigurationValue;
363 $asanIsEnabled = 1 if $asanConfigurationValue eq "YES";
367 sub determineNumberOfCPUs
369 return if defined $numberOfCPUs;
370 if (defined($ENV{NUMBER_OF_PROCESSORS})) {
371 $numberOfCPUs = $ENV{NUMBER_OF_PROCESSORS};
372 } elsif (isLinux()) {
373 # First try the nproc utility, if it exists. If we get no
374 # results fall back to just interpretting /proc directly.
375 chomp($numberOfCPUs = `nproc --all 2> /dev/null`);
376 if ($numberOfCPUs eq "") {
377 $numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`);
379 } elsif (isWindows() || isCygwin()) {
381 $numberOfCPUs = `ls /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor | wc -w`;
382 } elsif (isDarwin() || isBSD()) {
383 chomp($numberOfCPUs = `sysctl -n hw.ncpu`);
387 sub determineMaxCPULoad
389 return if defined $maxCPULoad;
390 if (defined($ENV{MAX_CPU_LOAD})) {
391 $maxCPULoad = $ENV{MAX_CPU_LOAD};
397 my ($productDir) = @_;
399 $jscName .= "_debug" if configuration() eq "Debug_All";
400 $jscName .= ".exe" if (isWindows() || isCygwin());
401 return "$productDir/$jscName" if -e "$productDir/$jscName";
402 return "$productDir/JavaScriptCore.framework/Resources/$jscName";
405 sub argumentsForConfiguration()
407 determineConfiguration();
408 determineArchitecture();
412 # FIXME: Is it necessary to pass --debug, --release, --32-bit or --64-bit?
413 # These are determined automatically from stored configuration.
414 push(@args, '--debug') if ($configuration =~ "^Debug");
415 push(@args, '--release') if ($configuration =~ "^Release");
416 push(@args, '--device') if (defined $xcodeSDK && $xcodeSDK =~ /^iphoneos/);
417 push(@args, '--ios-simulator') if (defined $xcodeSDK && $xcodeSDK =~ /^iphonesimulator/);
418 push(@args, '--32-bit') if ($architecture ne "x86_64" and !isWin64());
419 push(@args, '--64-bit') if (isWin64());
420 push(@args, '--gtk') if isGtk();
421 push(@args, '--efl') if isEfl();
422 push(@args, '--wincairo') if isWinCairo();
423 push(@args, '--inspector-frontend') if isInspectorFrontend();
427 sub determineXcodeSDK
429 return if defined $xcodeSDK;
431 if (checkForArgumentAndRemoveFromARGVGettingValue("--sdk", \$sdk)) {
434 if (checkForArgumentAndRemoveFromARGV("--device")) {
435 my $hasInternalSDK = exitStatus(system("xcrun --sdk iphoneos.internal --show-sdk-version > /dev/null 2>&1")) == 0;
436 $xcodeSDK ||= $hasInternalSDK ? "iphoneos.internal" : "iphoneos";
438 if (checkForArgumentAndRemoveFromARGV("--ios-simulator")) {
439 $xcodeSDK ||= 'iphonesimulator';
455 sub xcodeSDKPlatformName()
458 return "" if !defined $xcodeSDK;
459 return "iphoneos" if $xcodeSDK =~ /iphoneos/i;
460 return "iphonesimulator" if $xcodeSDK =~ /iphonesimulator/i;
461 return "macosx" if $xcodeSDK =~ /macosx/i;
462 die "Couldn't determine platform name from Xcode SDK";
469 die "Can't find the SDK path because no Xcode SDK was specified" if not $xcodeSDK;
471 my $sdkPath = `xcrun --sdk $xcodeSDK --show-sdk-path` if $xcodeSDK;
472 die 'Failed to get SDK path from xcrun' if $?;
482 die "Can't find the SDK version because no Xcode SDK was specified" if !$xcodeSDK;
484 chomp(my $sdkVersion = `xcrun --sdk $xcodeSDK --show-sdk-version`);
485 die "Failed to get SDK version from xcrun" if exitStatus($?);
492 return $programFilesPath if defined $programFilesPath;
494 $programFilesPath = $ENV{'PROGRAMFILES(X86)'} || $ENV{'PROGRAMFILES'} || "C:\\Program Files";
496 return $programFilesPath;
499 sub visualStudioInstallDir
501 return $vsInstallDir if defined $vsInstallDir;
503 if ($ENV{'VSINSTALLDIR'}) {
504 $vsInstallDir = $ENV{'VSINSTALLDIR'};
505 $vsInstallDir =~ s|[\\/]$||;
507 $vsInstallDir = File::Spec->catdir(programFilesPath(), "Microsoft Visual Studio 14.0");
509 chomp($vsInstallDir = `cygpath "$vsInstallDir"`) if isCygwin();
511 print "Using Visual Studio: $vsInstallDir\n";
512 return $vsInstallDir;
515 sub msBuildInstallDir
517 return $msBuildInstallDir if defined $msBuildInstallDir;
519 $msBuildInstallDir = File::Spec->catdir(programFilesPath(), "MSBuild", "14.0", "Bin");
521 chomp($msBuildInstallDir = `cygpath "$msBuildInstallDir"`) if isCygwin();
523 print "Using MSBuild: $msBuildInstallDir\n";
524 return $msBuildInstallDir;
527 sub visualStudioVersion
529 return $vsVersion if defined $vsVersion;
531 my $installDir = visualStudioInstallDir();
533 $vsVersion = ($installDir =~ /Microsoft Visual Studio ([0-9]+\.[0-9]*)/) ? $1 : "14";
535 print "Using Visual Studio $vsVersion\n";
539 sub determineConfigurationForVisualStudio
541 return if defined $configurationForVisualStudio;
542 determineConfiguration();
543 # FIXME: We should detect when Debug_All or Production has been chosen.
544 $configurationForVisualStudio = "/p:Configuration=" . $configuration;
547 sub usesPerConfigurationBuildDirectory
549 # [Gtk] We don't have Release/Debug configurations in straight
550 # autotool builds (non build-webkit). In this case and if
551 # WEBKIT_OUTPUTDIR exist, use that as our configuration dir. This will
552 # allows us to run run-webkit-tests without using build-webkit.
553 return ($ENV{"WEBKIT_OUTPUTDIR"} && isGtk()) || isAppleWinWebKit();
556 sub determineConfigurationProductDir
558 return if defined $configurationProductDir;
559 determineBaseProductDir();
560 determineConfiguration();
561 if (isAppleWinWebKit() || isWinCairo()) {
562 my $binDir = isWin64() ? "bin64" : "bin32";
563 $configurationProductDir = File::Spec->catdir($baseProductDir, $configuration, $binDir);
565 if (usesPerConfigurationBuildDirectory()) {
566 $configurationProductDir = "$baseProductDir";
568 $configurationProductDir = "$baseProductDir/$configuration";
569 $configurationProductDir .= "-" . xcodeSDKPlatformName() if isIOSWebKit();
574 sub setConfigurationProductDir($)
576 ($configurationProductDir) = @_;
579 sub determineCurrentSVNRevision
581 # We always update the current SVN revision here, and leave the caching
582 # to currentSVNRevision(), so that changes to the SVN revision while the
583 # script is running can be picked up by calling this function again.
584 determineSourceDir();
585 $currentSVNRevision = svnRevisionForDirectory($sourceDir);
586 return $currentSVNRevision;
592 determineSourceDir();
593 chdir $sourceDir or die;
598 determineBaseProductDir();
599 return $baseProductDir;
604 determineSourceDir();
610 determineConfigurationProductDir();
611 return $configurationProductDir;
616 my $productDir = productDir();
617 $productDir .= "/bin" if (isEfl() || isGtk());
624 determineConfiguration();
625 return $configuration;
630 determineASanIsEnabled();
631 return $asanIsEnabled;
634 sub configurationForVisualStudio()
636 determineConfigurationForVisualStudio();
637 return $configurationForVisualStudio;
640 sub currentSVNRevision
642 determineCurrentSVNRevision() if not defined $currentSVNRevision;
643 return $currentSVNRevision;
648 determineGenerateDsym();
649 return $generateDsym;
652 sub determineGenerateDsym()
654 return if defined($generateDsym);
655 $generateDsym = checkForArgumentAndRemoveFromARGV("--dsym");
658 sub argumentsForXcode()
661 push @args, "DEBUG_INFORMATION_FORMAT=dwarf-with-dsym" if generateDsym();
667 determineBaseProductDir();
668 determineConfiguration();
669 determineArchitecture();
670 determineASanIsEnabled();
673 my @sdkOption = ($xcodeSDK ? "SDKROOT=$xcodeSDK" : ());
674 my @architectureOption = ($architecture ? "ARCHS=$architecture" : ());
675 my @asanOption = ($asanIsEnabled ? ("-xcconfig", sourceDir() . "/Tools/asan/asan.xcconfig", "ASAN_IGNORE=" . sourceDir() . "/Tools/asan/webkit-asan-ignore.txt") : ());
677 return ("-UseSanitizedBuildSystemEnvironment=YES", @baseProductDirOption, "-configuration", $configuration, @architectureOption, @sdkOption, @asanOption, argumentsForXcode());
680 sub XcodeOptionString
682 return join " ", XcodeOptions();
685 sub XcodeOptionStringNoConfig
687 return join " ", @baseProductDirOption;
690 sub XcodeCoverageSupportOptions()
692 my @coverageSupportOptions = ();
693 push @coverageSupportOptions, "GCC_GENERATE_TEST_COVERAGE_FILES=YES";
694 push @coverageSupportOptions, "GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES";
695 return @coverageSupportOptions;
698 sub XcodeStaticAnalyzerOption()
700 return "RUN_CLANG_STATIC_ANALYZER=YES";
703 my $passedConfiguration;
704 my $searchedForPassedConfiguration;
705 sub determinePassedConfiguration
707 return if $searchedForPassedConfiguration;
708 $searchedForPassedConfiguration = 1;
709 $passedConfiguration = undef;
711 if (checkForArgumentAndRemoveFromARGV("--debug")) {
712 $passedConfiguration = "Debug";
713 } elsif(checkForArgumentAndRemoveFromARGV("--release")) {
714 $passedConfiguration = "Release";
715 } elsif (checkForArgumentAndRemoveFromARGV("--profile") || checkForArgumentAndRemoveFromARGV("--profiling")) {
716 $passedConfiguration = "Profiling";
720 sub passedConfiguration
722 determinePassedConfiguration();
723 return $passedConfiguration;
730 if (my $config = shift @_) {
731 $configuration = $config;
735 determinePassedConfiguration();
736 $configuration = $passedConfiguration if $passedConfiguration;
740 my $passedArchitecture;
741 my $searchedForPassedArchitecture;
742 sub determinePassedArchitecture
744 return if $searchedForPassedArchitecture;
745 $searchedForPassedArchitecture = 1;
747 $passedArchitecture = undef;
748 if (checkForArgumentAndRemoveFromARGV("--32-bit")) {
749 if (isAppleMacWebKit()) {
750 # PLATFORM_IOS: Don't run `arch` command inside Simulator environment
752 delete $ENV{DYLD_ROOT_PATH};
753 delete $ENV{DYLD_FRAMEWORK_PATH};
755 $passedArchitecture = `arch`;
756 chomp $passedArchitecture;
761 sub passedArchitecture
763 determinePassedArchitecture();
764 return $passedArchitecture;
769 determineArchitecture();
770 return $architecture;
775 determineNumberOfCPUs();
776 return $numberOfCPUs;
781 determineMaxCPULoad();
787 if (my $arch = shift @_) {
788 $architecture = $arch;
792 determinePassedArchitecture();
793 $architecture = $passedArchitecture if $passedArchitecture;
796 sub skipSafariExecutableEntitlementChecks
798 return `defaults read /Library/Preferences/org.webkit.BuildConfiguration SkipSafariExecutableEntitlementChecks 2>/dev/null` eq "1\n";
801 sub executableHasEntitlements
803 my $executablePath = shift;
804 return (`codesign -d --entitlements - $executablePath 2>&1` =~ /<key>/);
807 sub safariPathFromSafariBundle
809 my ($safariBundle) = @_;
811 die "Safari path is only relevant on Apple Mac platform\n" unless isAppleMacWebKit();
813 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
814 return $safariPath if skipSafariExecutableEntitlementChecks();
816 my $safariForWebKitDevelopmentPath = "$safariBundle/Contents/MacOS/SafariForWebKitDevelopment";
817 return $safariForWebKitDevelopmentPath if -f $safariForWebKitDevelopmentPath && executableHasEntitlements($safariPath);
822 sub installedSafariPath
824 return safariPathFromSafariBundle("/Applications/Safari.app");
830 die "Safari path is only relevant on Apple Mac platform\n" unless isAppleMacWebKit();
832 # Use WEBKIT_SAFARI environment variable if present.
833 my $safariBundle = $ENV{WEBKIT_SAFARI};
834 if (!$safariBundle) {
835 determineConfigurationProductDir();
836 # Use Safari.app in product directory if present (good for Safari development team).
837 if (-d "$configurationProductDir/Safari.app") {
838 $safariBundle = "$configurationProductDir/Safari.app";
840 if (!$safariBundle) {
841 return installedSafariPath();
844 my $safariPath = safariPathFromSafariBundle($safariBundle);
845 die "Can't find executable at $safariPath.\n" if !-x $safariPath;
849 sub builtDylibPathForName
851 my $libraryName = shift;
852 determineConfigurationProductDir();
855 my $extension = isDarwin() ? ".dylib" : ".so";
856 return "$configurationProductDir/lib/libwebkit2gtk-4.0" . $extension;
859 return "$configurationProductDir/lib/libewebkit2.so";
862 return "$configurationProductDir/$libraryName.framework/$libraryName";
864 if (isAppleMacWebKit()) {
865 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
867 if (isAppleWinWebKit()) {
868 if ($libraryName eq "JavaScriptCore") {
869 return "$baseProductDir/lib/$libraryName.lib";
871 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
875 die "Unsupported platform, can't determine built library locations.\nTry `build-webkit --help` for more information.\n";
878 # Check to see that all the frameworks are built.
879 sub checkFrameworks # FIXME: This is a poor name since only the Mac calls built WebCore a Framework.
881 return if isCygwin() || isWindows();
882 my @frameworks = ("JavaScriptCore", "WebCore");
883 push(@frameworks, "WebKit") if isAppleMacWebKit(); # FIXME: This seems wrong, all ports should have a WebKit these days.
884 for my $framework (@frameworks) {
885 my $path = builtDylibPathForName($framework);
886 die "Can't find built framework at \"$path\".\n" unless -e $path;
890 sub isInspectorFrontend()
892 determineIsInspectorFrontend();
893 return $isInspectorFrontend;
896 sub determineIsInspectorFrontend()
898 return if defined($isInspectorFrontend);
899 $isInspectorFrontend = checkForArgumentAndRemoveFromARGV("--inspector-frontend");
905 my $devnull = File::Spec->devnull();
907 if (isAnyWindows()) {
908 return exitStatus(system("where /q $command >$devnull 2>&1")) == 0;
910 return exitStatus(system("which $command >$devnull 2>&1")) == 0;
913 sub checkForArgumentAndRemoveFromARGV($)
915 my $argToCheck = shift;
916 return checkForArgumentAndRemoveFromArrayRef($argToCheck, \@ARGV);
919 sub checkForArgumentAndRemoveFromArrayRefGettingValue($$$)
921 my ($argToCheck, $valueRef, $arrayRef) = @_;
922 my $argumentStartRegEx = qr#^$argToCheck(?:=\S|$)#;
924 for (; $i < @$arrayRef; ++$i) {
925 last if $arrayRef->[$i] =~ $argumentStartRegEx;
927 if ($i >= @$arrayRef) {
928 return $$valueRef = undef;
930 my ($key, $value) = split("=", $arrayRef->[$i]);
931 splice(@$arrayRef, $i, 1);
932 if (defined($value)) {
933 # e.g. --sdk=iphonesimulator
934 return $$valueRef = $value;
936 return $$valueRef = splice(@$arrayRef, $i, 1); # e.g. --sdk iphonesimulator
939 sub checkForArgumentAndRemoveFromARGVGettingValue($$)
941 my ($argToCheck, $valueRef) = @_;
942 return checkForArgumentAndRemoveFromArrayRefGettingValue($argToCheck, $valueRef, \@ARGV);
945 sub findMatchingArguments($$)
947 my ($argToCheck, $arrayRef) = @_;
949 foreach my $index (0 .. $#$arrayRef) {
950 my $opt = $$arrayRef[$index];
951 if ($opt =~ /^$argToCheck$/i ) {
952 push(@matchingIndices, $index);
955 return @matchingIndices;
960 my ($argToCheck, $arrayRef) = @_;
961 my @matchingIndices = findMatchingArguments($argToCheck, $arrayRef);
962 return scalar @matchingIndices > 0;
965 sub checkForArgumentAndRemoveFromArrayRef
967 my ($argToCheck, $arrayRef) = @_;
968 my @indicesToRemove = findMatchingArguments($argToCheck, $arrayRef);
969 my $removeOffset = 0;
970 foreach my $index (@indicesToRemove) {
971 splice(@$arrayRef, $index - $removeOffset++, 1);
973 return scalar @indicesToRemove > 0;
978 return if defined($isEfl);
979 $isEfl = checkForArgumentAndRemoveFromARGV("--efl");
990 return if defined($isGtk);
991 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
1000 # Determine if this is debian, ubuntu, linspire, or something similar.
1003 return -e "/etc/debian_version";
1008 return -e "/etc/fedora-release";
1013 determineIsWinCairo();
1017 sub determineIsWinCairo()
1019 return if defined($isWinCairo);
1020 $isWinCairo = checkForArgumentAndRemoveFromARGV("--wincairo");
1029 sub determineIsWin64()
1031 return if defined($isWin64);
1032 $isWin64 = checkForArgumentAndRemoveFromARGV("--64-bit");
1037 return ($^O eq "cygwin") || 0;
1042 return isWindows() || isCygwin();
1045 sub determineWinVersion()
1047 return if $winVersion;
1049 if (!isAnyWindows()) {
1054 my $versionString = `cmd /c ver`;
1055 $versionString =~ /(\d)\.(\d)\.(\d+)/;
1066 determineWinVersion();
1072 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 1 && winVersion()->{build} == 7600;
1075 sub isWindowsVista()
1077 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 0;
1082 return isAnyWindows() && winVersion()->{major} == 5 && winVersion()->{minor} == 1;
1087 return ($^O eq "darwin") || 0;
1092 return ($^O eq "MSWin32") || 0;
1097 return ($^O eq "linux") || 0;
1102 return ($^O eq "freebsd") || ($^O eq "openbsd") || ($^O eq "netbsd") || 0;
1107 return ($Config{archname} =~ /^arm[v\-]/) || ($Config{archname} =~ /^aarch64[v\-]/);
1110 sub isCrossCompilation()
1113 $compiler = $ENV{'CC'} if (defined($ENV{'CC'}));
1114 if ($compiler =~ /gcc/) {
1115 my $compiler_options = `$compiler -v 2>&1`;
1116 my @host = $compiler_options =~ m/--host=(.*?)\s/;
1117 my @target = $compiler_options =~ m/--target=(.*?)\s/;
1119 return ($host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]);
1126 return isAppleMacWebKit() || isAppleWinWebKit();
1129 sub isAppleMacWebKit()
1131 return isDarwin() && !isGtk();
1134 sub isAppleWinWebKit()
1136 return (isCygwin() || isWindows()) && !isWinCairo() && !isGtk();
1139 sub iOSSimulatorDevicesPath
1141 return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";
1144 sub iOSSimulatorDevices
1146 eval "require Foundation";
1147 my $devicesPath = iOSSimulatorDevicesPath();
1148 opendir(DEVICES, $devicesPath);
1150 $_ =~ m/[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}/;
1154 # FIXME: We should parse the device.plist file ourself and map the dictionary keys in it to known
1155 # dictionary keys so as to decouple our representation of the plist from the actual structure
1156 # of the plist, which may change.
1158 Foundation::perlRefFromObjectRef(NSDictionary->dictionaryWithContentsOfFile_("$devicesPath/$_/device.plist"));
1164 sub createiOSSimulatorDevice
1167 my $deviceTypeId = shift;
1168 my $runtimeId = shift;
1170 my $created = system("xcrun", "--sdk", "iphonesimulator", "simctl", "create", $name, $deviceTypeId, $runtimeId) == 0;
1171 die "Couldn't create simulator device: $name $deviceTypeId $runtimeId" if not $created;
1173 system("xcrun", "--sdk", "iphonesimulator", "simctl", "list");
1175 print "Waiting for device to be created ...\n";
1177 for (my $tries = 0; $tries < 5; $tries++){
1178 my @devices = iOSSimulatorDevices();
1179 foreach my $device (@devices) {
1180 return $device if $device->{name} eq $name and $device->{deviceType} eq $deviceTypeId and $device->{runtime} eq $runtimeId;
1184 die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
1187 sub willUseIOSDeviceSDKWhenBuilding()
1189 return xcodeSDKPlatformName() eq "iphoneos";
1192 sub willUseIOSSimulatorSDKWhenBuilding()
1194 return xcodeSDKPlatformName() eq "iphonesimulator";
1199 determineXcodeSDK();
1200 return isAppleMacWebKit() && (willUseIOSDeviceSDKWhenBuilding() || willUseIOSSimulatorSDKWhenBuilding());
1203 sub determineNmPath()
1207 if (isAppleMacWebKit()) {
1208 $nmPath = `xcrun -find nm`;
1211 $nmPath = "nm" if !$nmPath;
1220 sub determineOSXVersion()
1222 return if $osXVersion;
1229 my $version = `sw_vers -productVersion`;
1230 my @splitVersion = split(/\./, $version);
1231 @splitVersion >= 2 or die "Invalid version $version";
1233 "major" => $splitVersion[0],
1234 "minor" => $splitVersion[1],
1235 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
1241 determineOSXVersion();
1247 return $ENV{'OS'} eq 'Windows_NT';
1250 sub shouldTargetWebProcess
1252 determineShouldTargetWebProcess();
1253 return $shouldTargetWebProcess;
1256 sub determineShouldTargetWebProcess
1258 return if defined($shouldTargetWebProcess);
1259 $shouldTargetWebProcess = checkForArgumentAndRemoveFromARGV("--target-web-process");
1262 sub shouldUseXPCServiceForWebProcess
1264 determineShouldUseXPCServiceForWebProcess();
1265 return $shouldUseXPCServiceForWebProcess;
1268 sub determineShouldUseXPCServiceForWebProcess
1270 return if defined($shouldUseXPCServiceForWebProcess);
1271 $shouldUseXPCServiceForWebProcess = checkForArgumentAndRemoveFromARGV("--use-web-process-xpc-service");
1276 determineDebugger();
1280 sub determineDebugger
1282 return if defined($debugger);
1284 determineXcodeVersion();
1285 if (eval "v$xcodeVersion" ge v4.5) {
1291 if (checkForArgumentAndRemoveFromARGV("--use-lldb")) {
1295 if (checkForArgumentAndRemoveFromARGV("--use-gdb")) {
1300 sub appendToEnvironmentVariableList
1302 my ($environmentVariableName, $value) = @_;
1304 if (defined($ENV{$environmentVariableName})) {
1305 $ENV{$environmentVariableName} .= ":" . $value;
1307 $ENV{$environmentVariableName} = $value;
1311 sub sharedCommandLineOptions()
1314 "g|guard-malloc" => \$shouldUseGuardMalloc,
1318 sub sharedCommandLineOptionsUsage
1323 '-g|--guard-malloc' => 'Use guardmalloc when running executable',
1326 my $indent = " " x ($opts{indent} || 2);
1327 my $switchWidth = List::Util::max(int($opts{switchWidth}), List::Util::max(map { length($_) } keys %switches) + ($opts{brackets} ? 2 : 0));
1329 my $result = "Common switches:\n";
1331 for my $switch (keys %switches) {
1332 my $switchName = $opts{brackets} ? "[" . $switch . "]" : $switch;
1333 $result .= sprintf("%s%-" . $switchWidth . "s %s\n", $indent, $switchName, $switches{$switch});
1339 sub setUpGuardMallocIfNeeded
1345 if (!defined($shouldUseGuardMalloc)) {
1346 $shouldUseGuardMalloc = checkForArgumentAndRemoveFromARGV("-g") || checkForArgumentAndRemoveFromARGV("--guard-malloc");
1349 if ($shouldUseGuardMalloc) {
1350 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", "/usr/lib/libgmalloc.dylib");
1354 sub relativeScriptsDir()
1356 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel($FindBin::Bin, getcwd()), "");
1357 if ($scriptDir eq "") {
1365 my $relativeScriptsPath = relativeScriptsDir();
1366 if (isGtk() || isEfl()) {
1367 return "$relativeScriptsPath/run-minibrowser";
1368 } elsif (isAppleWebKit()) {
1369 return "$relativeScriptsPath/run-safari";
1375 if (isGtk() || isEfl()) {
1376 return "MiniBrowser";
1377 } elsif (isAppleMacWebKit()) {
1379 } elsif (isAppleWinWebKit()) {
1380 return "WinLauncher";
1384 sub checkRequiredSystemConfig
1387 chomp(my $productVersion = `sw_vers -productVersion`);
1388 if (eval "v$productVersion" lt v10.7.5) {
1389 print "*************************************************************\n";
1390 print "Mac OS X Version 10.7.5 or later is required to build WebKit.\n";
1391 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
1392 print "*************************************************************\n";
1394 my $xcodebuildVersionOutput = `xcodebuild -version`;
1395 my $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : undef;
1396 if (!$xcodeVersion || $xcodeVersion && eval "v$xcodeVersion" lt v4.6) {
1397 print "*************************************************************\n";
1398 print "Xcode Version 4.6 or later is required to build WebKit.\n";
1399 print "You have an earlier version of Xcode, thus the build will\n";
1400 print "most likely fail. The latest Xcode is available from the App Store.\n";
1401 print "*************************************************************\n";
1403 } elsif (isGtk() or isEfl() or isWindows()) {
1404 my @cmds = qw(bison gperf flex);
1406 my $oldPath = $ENV{PATH};
1407 foreach my $cmd (@cmds) {
1408 push @missing, $cmd if not commandExists($cmd);
1412 my $list = join ", ", @missing;
1413 die "ERROR: $list missing but required to build WebKit.\n";
1416 # Win32 and other platforms may want to check for minimum config
1419 sub determineWindowsSourceDir()
1421 return if $windowsSourceDir;
1422 $windowsSourceDir = sourceDir();
1423 chomp($windowsSourceDir = `cygpath -w '$windowsSourceDir'`) if isCygwin();
1426 sub windowsSourceDir()
1428 determineWindowsSourceDir();
1429 return $windowsSourceDir;
1432 sub windowsSourceSourceDir()
1434 return File::Spec->catdir(windowsSourceDir(), "Source");
1437 sub windowsLibrariesDir()
1439 return File::Spec->catdir(windowsSourceDir(), "WebKitLibraries", "win");
1442 sub windowsOutputDir()
1444 return File::Spec->catdir(windowsSourceDir(), "WebKitBuild");
1450 my $cmd = "reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\" . $font ."\" 2>&1";
1455 sub checkInstalledTools()
1457 # environment variables. Avoid until this is corrected.
1458 my $pythonVer = `python --version 2>&1`;
1459 die "You must have Python installed to build WebKit.\n" if ($?);
1461 # cURL 7.34.0 has a bug that prevents authentication with opensource.apple.com (and other things using SSL3).
1462 my $curlVer = `curl --version 2> NUL`;
1463 if (!$? and $curlVer =~ "(.*curl.*)") {
1465 if ($curlVer =~ /libcurl\/7\.34\.0/) {
1466 print "cURL version 7.34.0 has a bug that prevents authentication with SSL v2 or v3.\n";
1467 print "cURL 7.33.0 is known to work. The cURL projects is preparing an update to\n";
1468 print "correct this problem.\n\n";
1469 die "Please install a working cURL and try again.\n";
1473 # MathML requires fonts that do not ship with Windows (at least through Windows 8). Warn the user if they are missing
1474 my @fonts = qw(STIXGeneral-Regular MathJax_Main-Regular);
1476 foreach my $font (@fonts) {
1477 push @missing, $font if not fontExists($font);
1480 if (scalar @missing > 0) {
1481 print "*************************************************************\n";
1482 print "Mathematical fonts, such as STIX and MathJax, are needed to\n";
1483 print "use the MathML feature. You do not appear to have these fonts\n";
1484 print "on your system.\n\n";
1485 print "You can download a suitable set of fonts from the following URL:\n";
1486 print "https://developer.mozilla.org/Mozilla/MathML_Projects/Fonts\n";
1487 print "*************************************************************\n";
1490 print "Installed tools are correct for the WebKit build.\n";
1493 sub setupAppleWinEnv()
1495 return unless isAppleWinWebKit();
1497 checkInstalledTools();
1499 if (isWindowsNT()) {
1500 my $restartNeeded = 0;
1501 my %variablesToSet = ();
1503 # FIXME: We should remove this explicit version check for cygwin once we stop supporting Cygwin 1.7.9 or older versions.
1504 # https://bugs.webkit.org/show_bug.cgi?id=85791
1505 my $uname_version = (POSIX::uname())[2];
1506 $uname_version =~ s/\(.*\)//; # Remove the trailing cygwin version, if any.
1507 $uname_version =~ s/\-.*$//; # Remove trailing dash-version content, if any
1508 if (version->parse($uname_version) < version->parse("1.7.10")) {
1509 # Setting the environment variable 'CYGWIN' to 'tty' makes cygwin enable extra support (i.e., termios)
1510 # for UNIX-like ttys in the Windows console
1511 $variablesToSet{CYGWIN} = "tty" unless $ENV{CYGWIN};
1514 # Those environment variables must be set to be able to build inside Visual Studio.
1515 $variablesToSet{WEBKIT_LIBRARIES} = windowsLibrariesDir() unless $ENV{WEBKIT_LIBRARIES};
1516 $variablesToSet{WEBKIT_OUTPUTDIR} = windowsOutputDir() unless $ENV{WEBKIT_OUTPUTDIR};
1517 $variablesToSet{MSBUILDDISABLENODEREUSE} = "1" unless $ENV{MSBUILDDISABLENODEREUSE};
1519 foreach my $variable (keys %variablesToSet) {
1520 print "Setting the Environment Variable '" . $variable . "' to '" . $variablesToSet{$variable} . "'\n\n";
1521 my $ret = system "setx", $variable, $variablesToSet{$variable};
1523 system qw(regtool -s set), '\\HKEY_CURRENT_USER\\Environment\\' . $variable, $variablesToSet{$variable};
1525 $restartNeeded ||= $variable eq "WEBKIT_LIBRARIES" || $variable eq "WEBKIT_OUTPUTDIR";
1528 if ($restartNeeded) {
1529 print "Please restart your computer before attempting to build inside Visual Studio.\n\n";
1532 if (!defined $ENV{'WEBKIT_LIBRARIES'} || !$ENV{'WEBKIT_LIBRARIES'}) {
1533 print "Warning: You must set the 'WebKit_Libraries' environment variable\n";
1534 print " to be able build WebKit from within Visual Studio 2013 and newer.\n";
1535 print " Make sure that 'WebKit_Libraries' points to the\n";
1536 print " 'WebKitLibraries/win' directory, not the 'WebKitLibraries/' directory.\n\n";
1538 if (!defined $ENV{'WEBKIT_OUTPUTDIR'} || !$ENV{'WEBKIT_OUTPUTDIR'}) {
1539 print "Warning: You must set the 'WebKit_OutputDir' environment variable\n";
1540 print " to be able build WebKit from within Visual Studio 2013 and newer.\n\n";
1542 if (!defined $ENV{'MSBUILDDISABLENODEREUSE'} || !$ENV{'MSBUILDDISABLENODEREUSE'}) {
1543 print "Warning: You should set the 'MSBUILDDISABLENODEREUSE' environment variable to '1'\n";
1544 print " to avoid periodic locked log files when building.\n\n";
1547 # FIXME (125180): Remove the following temporary 64-bit support once official support is available.
1548 if (isWin64() and !$ENV{'WEBKIT_64_SUPPORT'}) {
1549 print "Warning: You must set the 'WEBKIT_64_SUPPORT' environment variable\n";
1550 print " to be able run WebKit or JavaScriptCore tests.\n\n";
1554 sub setupCygwinEnv()
1556 return if !isCygwin() && !isWindows();
1557 return if $vcBuildPath;
1559 my $programFilesPath = programFilesPath();
1560 my $visualStudioPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE devenv.com));
1561 if (-e $visualStudioPath) {
1562 # Visual Studio is installed;
1563 if (visualStudioVersion() eq "12") {
1564 $visualStudioPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE devenv.exe));
1567 # Visual Studio not found, try VC++ Express
1568 $visualStudioPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE WDExpress.exe));
1569 if (! -e $visualStudioPath) {
1570 print "*************************************************************\n";
1571 print "Cannot find '$visualStudioPath'\n";
1572 print "Please execute the file 'vcvars32.bat' from\n";
1573 print "'$programFilesPath\\Microsoft Visual Studio 14.0\\VC\\bin\\'\n";
1574 print "to setup the necessary environment variables.\n";
1575 print "*************************************************************\n";
1578 $willUseVCExpressWhenBuilding = 1;
1581 print "Building results into: ", baseProductDir(), "\n";
1582 print "WEBKIT_OUTPUTDIR is set to: ", $ENV{"WEBKIT_OUTPUTDIR"}, "\n";
1583 print "WEBKIT_LIBRARIES is set to: ", $ENV{"WEBKIT_LIBRARIES"}, "\n";
1584 # FIXME (125180): Remove the following temporary 64-bit support once official support is available.
1585 print "WEBKIT_64_SUPPORT is set to: ", $ENV{"WEBKIT_64_SUPPORT"}, "\n" if isWin64();
1587 # We will actually use MSBuild to build WebKit, but we need to find the Visual Studio install (above) to make
1588 # sure we use the right options.
1589 $vcBuildPath = File::Spec->catfile(msBuildInstallDir(), qw(MSBuild.exe));
1590 if (! -e $vcBuildPath) {
1591 print "*************************************************************\n";
1592 print "Cannot find '$vcBuildPath'\n";
1593 print "Please make sure execute that the Microsoft .NET Framework SDK\n";
1594 print "is installed on this machine.\n";
1595 print "*************************************************************\n";
1600 sub dieIfWindowsPlatformSDKNotInstalled
1602 my $registry32Path = "/proc/registry/";
1603 my $registry64Path = "/proc/registry64/";
1604 my @windowsPlatformSDKRegistryEntries = (
1605 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v8.0A",
1606 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v8.0",
1607 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.1A",
1608 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.0A",
1609 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1",
1612 # FIXME: It would be better to detect whether we are using 32- or 64-bit Windows
1613 # and only check the appropriate entry. But for now we just blindly check both.
1614 my $recommendedPlatformSDK = $windowsPlatformSDKRegistryEntries[0];
1616 while (@windowsPlatformSDKRegistryEntries) {
1617 my $windowsPlatformSDKRegistryEntry = shift @windowsPlatformSDKRegistryEntries;
1618 return if (-e $registry32Path . $windowsPlatformSDKRegistryEntry) || (-e $registry64Path . $windowsPlatformSDKRegistryEntry);
1621 print "*************************************************************\n";
1622 print "Cannot find registry entry '$recommendedPlatformSDK'.\n";
1623 print "Please download and install the Microsoft Windows SDK\n";
1624 print "from <http://www.microsoft.com/en-us/download/details.aspx?id=8279>.\n\n";
1625 print "Then follow step 2 in the Windows section of the \"Installing Developer\n";
1626 print "Tools\" instructions at <http://www.webkit.org/building/tools.html>.\n";
1627 print "*************************************************************\n";
1631 sub buildXCodeProject($$@)
1633 my ($project, $clean, @extraOptions) = @_;
1636 push(@extraOptions, "-alltargets");
1637 push(@extraOptions, "clean");
1640 push(@extraOptions, ("-sdk", xcodeSDK())) if isIOSWebKit();
1642 chomp($ENV{DSYMUTIL_NUM_THREADS} = `sysctl -n hw.activecpu`);
1643 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
1646 sub usingVisualStudioExpress()
1649 return $willUseVCExpressWhenBuilding;
1652 sub buildVisualStudioProject
1654 my ($project, $clean) = @_;
1657 my $config = configurationForVisualStudio();
1659 dieIfWindowsPlatformSDKNotInstalled() if $willUseVCExpressWhenBuilding;
1661 chomp($project = `cygpath -w "$project"`) if isCygwin();
1663 my $action = "/t:build";
1665 $action = "/t:clean";
1668 my $platform = "/p:Platform=" . (isWin64() ? "x64" : "Win32");
1669 my $logPath = File::Spec->catdir($baseProductDir, $configuration);
1670 make_path($logPath) unless -d $logPath or $logPath eq ".";
1672 my $errorLogFile = File::Spec->catfile($logPath, "webkit_errors.log");
1673 chomp($errorLogFile = `cygpath -w "$errorLogFile"`) if isCygwin();
1674 my $errorLogging = "/flp:LogFile=" . $errorLogFile . ";ErrorsOnly";
1676 my $warningLogFile = File::Spec->catfile($logPath, "webkit_warnings.log");
1677 chomp($warningLogFile = `cygpath -w "$warningLogFile"`) if isCygwin();
1678 my $warningLogging = "/flp1:LogFile=" . $warningLogFile . ";WarningsOnly";
1680 my @command = ($vcBuildPath, "/verbosity:minimal", $project, $action, $config, $platform, "/fl", $errorLogging, "/fl1", $warningLogging);
1682 print join(" ", @command), "\n";
1683 return system @command;
1686 sub getJhbuildPath()
1688 my @jhbuildPath = File::Spec->splitdir(baseProductDir());
1689 if (isGit() && isGitBranchBuild() && gitBranch()) {
1693 push(@jhbuildPath, "DependenciesEFL");
1695 push(@jhbuildPath, "DependenciesGTK");
1697 die "Cannot get JHBuild path for platform that isn't GTK+ or EFL.\n";
1699 return File::Spec->catdir(@jhbuildPath);
1702 sub isCachedArgumentfileOutOfDate($@)
1704 my ($filename, $currentContents) = @_;
1706 if (! -e $filename) {
1710 open(CONTENTS_FILE, $filename);
1711 chomp(my $previousContents = <CONTENTS_FILE>);
1712 close(CONTENTS_FILE);
1714 if ($previousContents ne $currentContents) {
1715 print "Contents for file $filename have changed.\n";
1716 print "Previous contents were: $previousContents\n\n";
1717 print "New contents are: $currentContents\n";
1724 sub jhbuildWrapperPrefixIfNeeded()
1726 if (isWindows() || isCygwin()) {
1729 if (-e getJhbuildPath()) {
1730 my @prefix = (File::Spec->catfile(sourceDir(), "Tools", "jhbuild", "jhbuild-wrapper"));
1732 push(@prefix, "--efl");
1734 push(@prefix, "--gtk");
1736 push(@prefix, "run");
1744 sub cmakeCachePath()
1746 return File::Spec->catdir(baseProductDir(), configuration(), "CMakeCache.txt");
1749 sub shouldRemoveCMakeCache(@)
1751 my ($cacheFilePath, @buildArgs) = @_;
1753 # We check this first, because we always want to create this file for a fresh build.
1754 my $productDir = File::Spec->catdir(baseProductDir(), configuration());
1755 my $optionsCache = File::Spec->catdir($productDir, "build-webkit-options.txt");
1756 my $joinedBuildArgs = join(" ", @buildArgs);
1757 if (isCachedArgumentfileOutOfDate($optionsCache, $joinedBuildArgs)) {
1758 File::Path::mkpath($productDir) unless -d $productDir;
1759 open(CACHED_ARGUMENTS, ">", $optionsCache);
1760 print CACHED_ARGUMENTS $joinedBuildArgs;
1761 close(CACHED_ARGUMENTS);
1766 my $cmakeCache = cmakeCachePath();
1767 unless (-e $cmakeCache) {
1771 my $cacheFileModifiedTime = stat($cmakeCache)->mtime;
1772 my $platformConfiguration = File::Spec->catdir(sourceDir(), "Source", "cmake", "Options" . cmakeBasedPortName() . ".cmake");
1773 if ($cacheFileModifiedTime < stat($platformConfiguration)->mtime) {
1777 my $globalConfiguration = File::Spec->catdir(sourceDir(), "Source", "cmake", "OptionsCommon.cmake");
1778 if ($cacheFileModifiedTime < stat($globalConfiguration)->mtime) {
1782 my $inspectorUserInterfaceDircetory = File::Spec->catdir(sourceDir(), "Source", "WebInspectorUI", "UserInterface");
1783 if ($cacheFileModifiedTime < stat($inspectorUserInterfaceDircetory)->mtime) {
1790 sub removeCMakeCache(@)
1792 my (@buildArgs) = @_;
1793 if (shouldRemoveCMakeCache(@buildArgs)) {
1794 my $cmakeCache = cmakeCachePath();
1795 unlink($cmakeCache) if -e $cmakeCache;
1801 # Test both ninja and ninja-build. Fedora uses ninja-build and has patched CMake to also call ninja-build.
1802 return commandExists("ninja") || commandExists("ninja-build");
1805 sub canUseEclipse(@)
1807 return commandExists("eclipse");
1810 sub cmakeGeneratedBuildfile(@)
1812 my ($willUseNinja) = @_;
1813 if ($willUseNinja) {
1814 return File::Spec->catfile(baseProductDir(), configuration(), "build.ninja")
1816 return File::Spec->catfile(baseProductDir(), configuration(), "Makefile")
1820 sub generateBuildSystemFromCMakeProject
1822 my ($port, $prefixPath, @cmakeArgs, $additionalCMakeArgs) = @_;
1823 my $config = configuration();
1824 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1825 File::Path::mkpath($buildPath) unless -d $buildPath;
1826 my $originalWorkingDirectory = getcwd();
1827 chdir($buildPath) or die;
1829 # We try to be smart about when to rerun cmake, so that we can have faster incremental builds.
1830 my $willUseNinja = canUseNinja();
1831 if (-e cmakeCachePath() && -e cmakeGeneratedBuildfile($willUseNinja)) {
1836 push @args, "-DPORT=\"$port\"";
1837 push @args, "-DCMAKE_INSTALL_PREFIX=\"$prefixPath\"" if $prefixPath;
1838 push @args, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" if isGtk();
1839 if ($config =~ /release/i) {
1840 push @args, "-DCMAKE_BUILD_TYPE=Release";
1841 } elsif ($config =~ /debug/i) {
1842 push @args, "-DCMAKE_BUILD_TYPE=Debug";
1845 if ($willUseNinja) {
1847 if (canUseEclipse()) {
1848 push @args, "'Eclipse CDT4 - Ninja'";
1850 push @args, "Ninja";
1854 # GTK+ has a production mode, but build-webkit should always use developer mode.
1855 push @args, "-DDEVELOPER_MODE=ON" if isEfl() || isGtk();
1857 # Don't warn variables which aren't used by cmake ports.
1858 push @args, "--no-warn-unused-cli";
1859 push @args, @cmakeArgs if @cmakeArgs;
1860 push @args, $additionalCMakeArgs if $additionalCMakeArgs;
1862 my $cmakeSourceDir = isCygwin() ? windowsSourceDir() : sourceDir();
1863 push @args, '"' . $cmakeSourceDir . '"';
1865 # Compiler options to keep floating point values consistent
1866 # between 32-bit and 64-bit architectures.
1867 determineArchitecture();
1868 if ($architecture ne "x86_64" && !isARM() && !isCrossCompilation() && !isWindows()) {
1869 $ENV{'CXXFLAGS'} = "-march=pentium4 -msse2 -mfpmath=sse " . ($ENV{'CXXFLAGS'} || "");
1872 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1873 # parsed for shell metacharacters.
1874 my $wrapper = join(" ", jhbuildWrapperPrefixIfNeeded()) . " ";
1875 my $returnCode = system($wrapper . "cmake @args");
1877 chdir($originalWorkingDirectory);
1881 sub buildCMakeGeneratedProject($)
1883 my ($makeArgs) = @_;
1884 my $config = configuration();
1885 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1886 if (! -d $buildPath) {
1887 die "Must call generateBuildSystemFromCMakeProject() before building CMake project.";
1890 my $command = "cmake";
1891 my @args = ("--build", $buildPath, "--config", $config);
1892 push @args, ("--", $makeArgs) if $makeArgs;
1894 # GTK can use a build script to preserve colors and pretty-printing.
1895 if (isGtk() && -e "$buildPath/build.sh") {
1896 chdir "$buildPath" or die;
1897 $command = "$buildPath/build.sh";
1898 @args = ($makeArgs);
1901 if ($ENV{VERBOSE} && canUseNinja()) {
1903 push @args, "-d keeprsp" if (version->parse(determineNinjaVersion()) >= version->parse("1.4.0"));
1906 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1907 # parsed for shell metacharacters. In particular, $makeArgs may contain such metacharacters.
1908 my $wrapper = join(" ", jhbuildWrapperPrefixIfNeeded()) . " ";
1909 return system($wrapper . "$command @args");
1913 sub cleanCMakeGeneratedProject()
1915 my $config = configuration();
1916 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1917 if (-d $buildPath) {
1918 return system("cmake", "--build", $buildPath, "--config", $config, "--target", "clean");
1923 sub buildCMakeProjectOrExit($$$$@)
1925 my ($clean, $port, $prefixPath, $makeArgs, @cmakeArgs) = @_;
1928 exit(exitStatus(cleanCMakeGeneratedProject())) if $clean;
1930 if (isEfl() && checkForArgumentAndRemoveFromARGV("--update-efl")) {
1931 system("perl", "$sourceDir/Tools/Scripts/update-webkitefl-libs") == 0 or die $!;
1934 if (isGtk() && checkForArgumentAndRemoveFromARGV("--update-gtk")) {
1935 system("perl", "$sourceDir/Tools/Scripts/update-webkitgtk-libs") == 0 or die $!;
1938 $returnCode = exitStatus(generateBuildSystemFromCMakeProject($port, $prefixPath, @cmakeArgs));
1939 exit($returnCode) if $returnCode;
1941 $returnCode = exitStatus(buildCMakeGeneratedProject($makeArgs));
1942 exit($returnCode) if $returnCode;
1946 sub cmakeBasedPortArguments()
1951 sub cmakeBasedPortName()
1953 return "Efl" if isEfl();
1954 return "GTK" if isGtk();
1960 return isEfl() || isGtk();
1965 my ($prompt, $default) = @_;
1966 my $defaultValue = $default ? "[$default]" : "";
1967 print "$prompt $defaultValue: ";
1968 chomp(my $input = <STDIN>);
1969 return $input ? $input : $default;
1972 sub appleApplicationSupportPath
1974 open INSTALL_DIR, "</proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Apple\ Inc./Apple\ Application\ Support/InstallDir";
1975 my $path = <INSTALL_DIR>;
1976 $path =~ s/[\r\n\x00].*//;
1979 my $unixPath = `cygpath -u '$path'`;
1984 sub setPathForRunningWebKitApp
1988 if (isAppleWinWebKit()) {
1989 $env->{PATH} = join(':', productDir(), appleApplicationSupportPath(), $env->{PATH} || "");
1990 } elsif (isWinCairo()) {
1991 my $winCairoBin = sourceDir() . "/WebKitLibraries/win/" . (isWin64() ? "bin64/" : "bin32/");
1992 my $gstreamerBin = isWin64() ? $ENV{"GSTREAMER_1_0_ROOT_X86_64"} . "bin" : $ENV{"GSTREAMER_1_0_ROOT_X86"} . "bin";
1993 $env->{PATH} = join(':', productDir(), $winCairoBin, $gstreamerBin, $env->{PATH} || "");
1997 sub printHelpAndExitForRunAndDebugWebKitAppIfNeeded
1999 return unless checkForArgumentAndRemoveFromARGV("--help");
2001 my ($includeOptionsForDebugging) = @_;
2004 Usage: @{[basename($0)]} [options] [args ...]
2005 --help Show this help message
2006 --no-saved-state Launch the application without state restoration (OS X 10.7 and later)
2007 -g|--guard-malloc Enable Guard Malloc (OS X only)
2008 --use-web-process-xpc-service Launch the Web Process as an XPC Service (OS X only)
2011 if ($includeOptionsForDebugging) {
2013 --target-web-process Debug the web process
2014 --use-gdb Use GDB (this is the default when using Xcode 4.4 or earlier)
2015 --use-lldb Use LLDB (this is the default when using Xcode 4.5 or later)
2022 sub argumentsForRunAndDebugMacWebKitApp()
2025 if (checkForArgumentAndRemoveFromARGV("--no-saved-state")) {
2026 push @args, ("-ApplePersistenceIgnoreStateQuietly", "YES");
2027 # FIXME: Don't set ApplePersistenceIgnoreState once all supported OS versions respect ApplePersistenceIgnoreStateQuietly (rdar://15032886).
2028 push @args, ("-ApplePersistenceIgnoreState", "YES");
2030 push @args, ("-WebKit2UseXPCServiceForWebProcess", "YES") if shouldUseXPCServiceForWebProcess();
2031 unshift @args, @ARGV;
2036 sub setupMacWebKitEnvironment($)
2038 my ($dyldFrameworkPath) = @_;
2040 $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
2042 $ENV{DYLD_FRAMEWORK_PATH} = $ENV{DYLD_FRAMEWORK_PATH} ? join(":", $dyldFrameworkPath, $ENV{DYLD_FRAMEWORK_PATH}) : $dyldFrameworkPath;
2043 $ENV{__XPC_DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
2044 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2046 setUpGuardMallocIfNeeded();
2049 sub setupIOSWebKitEnvironment($)
2051 my ($dyldFrameworkPath) = @_;
2052 $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
2054 $ENV{DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
2055 $ENV{DYLD_LIBRARY_PATH} = $dyldFrameworkPath;
2057 setUpGuardMallocIfNeeded();
2060 sub iosSimulatorApplicationsPath()
2062 return File::Spec->catdir(XcodeSDKPath(), "Applications");
2065 sub installedMobileSafariBundle()
2067 return File::Spec->catfile(iosSimulatorApplicationsPath(), "MobileSafari.app");
2070 sub mobileSafariBundle()
2072 determineConfigurationProductDir();
2074 # Use MobileSafari.app in product directory if present.
2075 if (isAppleMacWebKit() && -d "$configurationProductDir/MobileSafari.app") {
2076 return "$configurationProductDir/MobileSafari.app";
2078 return installedMobileSafariBundle();
2081 sub plistPathFromBundle($)
2083 my ($appBundle) = @_;
2084 return "$appBundle/Info.plist" if -f "$appBundle/Info.plist"; # iOS app bundle
2085 return "$appBundle/Contents/Info.plist" if -f "$appBundle/Contents/Info.plist"; # Mac app bundle
2089 sub appIdentifierFromBundle($)
2091 my ($appBundle) = @_;
2092 my $plistPath = File::Spec->rel2abs(plistPathFromBundle($appBundle)); # defaults(1) will complain if the specified path is not absolute.
2093 chomp(my $bundleIdentifier = `defaults read '$plistPath' CFBundleIdentifier 2> /dev/null`);
2094 return $bundleIdentifier;
2097 sub appDisplayNameFromBundle($)
2099 my ($appBundle) = @_;
2100 my $plistPath = File::Spec->rel2abs(plistPathFromBundle($appBundle)); # defaults(1) will complain if the specified path is not absolute.
2101 chomp(my $bundleDisplayName = `defaults read '$plistPath' CFBundleDisplayName 2> /dev/null`);
2102 return $bundleDisplayName;
2105 sub waitUntilIOSSimulatorDeviceIsInState($$)
2107 my ($deviceUDID, $waitUntilState) = @_;
2108 my $device = iosSimulatorDeviceByUDID($deviceUDID);
2109 while ($device->{state} ne $waitUntilState) {
2110 usleep(500 * 1000); # Waiting 500ms between file system polls does not make script run-safari feel sluggish.
2111 $device = iosSimulatorDeviceByUDID($deviceUDID);
2115 sub relaunchIOSSimulator($)
2117 my ($simulatedDevice) = @_;
2118 quitIOSSimulator($simulatedDevice->{UDID});
2120 # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator
2121 my $iosSimulatorBundleID = "com.apple.iphonesimulator";
2122 system("open", "-b", $iosSimulatorBundleID, "--args", "-CurrentDeviceUDID", $simulatedDevice->{UDID}) == 0 or die "Failed to open $iosSimulatorBundleID: $!";
2124 waitUntilIOSSimulatorDeviceIsInState($simulatedDevice->{UDID}, SIMULATOR_DEVICE_STATE_BOOTED);
2127 sub quitIOSSimulator(;$)
2129 my ($waitForShutdownOfSimulatedDeviceUDID) = @_;
2130 # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator
2131 exitStatus(system {"osascript"} "osascript", "-e", 'tell application id "com.apple.iphonesimulator" to quit') == 0 or die "Failed to quit iOS Simulator: $!";
2132 if (!defined($waitForShutdownOfSimulatedDeviceUDID)) {
2135 # FIXME: We assume that $waitForShutdownOfSimulatedDeviceUDID was not booted using the simctl command line tool.
2136 # Otherwise we will spin indefinitely since quiting the iOS Simulator will not shutdown this device. We
2137 # should add a maximum time limit to wait for a device to shutdown and either return an error or die()
2138 # on expiration of the time limit.
2139 waitUntilIOSSimulatorDeviceIsInState($waitForShutdownOfSimulatedDeviceUDID, SIMULATOR_DEVICE_STATE_SHUTDOWN);
2142 sub iosSimulatorDeviceByName($)
2144 my ($simulatorName) = @_;
2145 my $simulatorRuntime = iosSimulatorRuntime();
2146 my @devices = iOSSimulatorDevices();
2147 for my $device (@devices) {
2148 if ($device->{name} eq $simulatorName && $device->{runtime} eq $simulatorRuntime) {
2155 sub iosSimulatorDeviceByUDID($)
2157 my ($simulatedDeviceUDID) = @_;
2158 my $devicePlistPath = File::Spec->catfile(iOSSimulatorDevicesPath(), $simulatedDeviceUDID, "device.plist");
2159 if (!-f $devicePlistPath) {
2162 # FIXME: We should parse the device.plist file ourself and map the dictionary keys in it to known
2163 # dictionary keys so as to decouple our representation of the plist from the actual structure
2164 # of the plist, which may change.
2165 eval "require Foundation";
2166 return Foundation::perlRefFromObjectRef(NSDictionary->dictionaryWithContentsOfFile_($devicePlistPath));
2169 sub iosSimulatorRuntime()
2171 my $xcodeSDKVersion = xcodeSDKVersion();
2172 $xcodeSDKVersion =~ s/\./-/;
2173 return "com.apple.CoreSimulator.SimRuntime.iOS-$xcodeSDKVersion";
2176 sub findOrCreateSimulatorForIOSDevice($)
2178 my ($simulatorNameSuffix) = @_;
2180 my $simulatorDeviceType;
2181 if (architecture() eq "x86_64") {
2182 $simulatorName = "iPhone 5s " . $simulatorNameSuffix;
2183 $simulatorDeviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5s";
2185 $simulatorName = "iPhone 5 " . $simulatorNameSuffix;
2186 $simulatorDeviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
2188 my $simulatedDevice = iosSimulatorDeviceByName($simulatorName);
2189 return $simulatedDevice if $simulatedDevice;
2190 return createiOSSimulatorDevice($simulatorName, $simulatorDeviceType, iosSimulatorRuntime());
2193 sub isIOSSimulatorSystemInstalledApp($)
2195 my ($appBundle) = @_;
2196 my $simulatorApplicationsPath = realpath(iosSimulatorApplicationsPath());
2197 return substr(realpath($appBundle), 0, length($simulatorApplicationsPath)) eq $simulatorApplicationsPath;
2200 sub hasUserInstalledAppInSimulatorDevice($$)
2202 my ($appIdentifier, $simulatedDeviceUDID) = @_;
2203 my $userInstalledAppPath = File::Spec->catfile($ENV{HOME}, "Library", "Developer", "CoreSimulator", "Devices", $simulatedDeviceUDID, "data", "Containers", "Bundle", "Application");
2204 if (!-d $userInstalledAppPath) {
2205 return 0; # No user installed apps.
2207 local @::userInstalledAppBundles;
2208 my $wantedFunction = sub {
2211 # Ignore hidden files and directories.
2212 if ($file =~ /^\../) {
2213 $File::Find::prune = 1;
2217 return if !-d $file || $file !~ /\.app$/;
2218 push @::userInstalledAppBundles, $File::Find::name;
2219 $File::Find::prune = 1; # Do not traverse contents of app bundle.
2221 find($wantedFunction, $userInstalledAppPath);
2222 for my $userInstalledAppBundle (@::userInstalledAppBundles) {
2223 if (appIdentifierFromBundle($userInstalledAppBundle) eq $appIdentifier) {
2224 return 1; # Has user installed app.
2227 return 0; # Does not have user installed app.
2230 sub isSimulatorDeviceBooted($)
2232 my ($simulatedDeviceUDID) = @_;
2233 my $device = iosSimulatorDeviceByUDID($simulatedDeviceUDID);
2234 return $device && $device->{state} eq SIMULATOR_DEVICE_STATE_BOOTED;
2237 sub runIOSWebKitAppInSimulator($;$)
2239 my ($appBundle, $simulatorOptions) = @_;
2240 my $productDir = productDir();
2241 my $appDisplayName = appDisplayNameFromBundle($appBundle);
2242 my $appIdentifier = appIdentifierFromBundle($appBundle);
2243 my $simulatedDevice = findOrCreateSimulatorForIOSDevice(SIMULATOR_DEVICE_SUFFIX_FOR_WEBKIT_DEVELOPMENT);
2244 my $simulatedDeviceUDID = $simulatedDevice->{UDID};
2246 my $willUseSystemInstalledApp = isIOSSimulatorSystemInstalledApp($appBundle);
2247 if ($willUseSystemInstalledApp) {
2248 if (hasUserInstalledAppInSimulatorDevice($appIdentifier, $simulatedDeviceUDID)) {
2249 # Restore the system-installed app in the simulator device corresponding to $appBundle as it
2250 # was previously overwritten with a custom built version of the app.
2251 # FIXME: Only restore the system-installed version of the app instead of erasing all contents and settings.
2252 print "Quitting iOS Simulator...\n";
2253 quitIOSSimulator($simulatedDeviceUDID);
2254 print "Erasing contents and settings for simulator device \"$simulatedDevice->{name}\".\n";
2255 exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "erase", $simulatedDeviceUDID)) == 0 or die;
2257 # FIXME: We assume that if $simulatedDeviceUDID is not booted then iOS Simulator is not open. However
2258 # $simulatedDeviceUDID may have been booted using the simctl command line tool. If $simulatedDeviceUDID
2259 # was booted using simctl then we should shutdown the device and launch iOS Simulator to boot it again.
2260 if (!isSimulatorDeviceBooted($simulatedDeviceUDID)) {
2261 print "Launching iOS Simulator...\n";
2262 relaunchIOSSimulator($simulatedDevice);
2265 # FIXME: We should killall(1) any running instances of $appBundle before installing it to ensure
2266 # that simctl launch opens the latest installed version of the app. For now we quit and
2267 # launch the iOS Simulator again to ensure there are no running instances of $appBundle.
2268 print "Quitting and launching iOS Simulator...\n";
2269 relaunchIOSSimulator($simulatedDevice);
2271 print "Installing $appBundle.\n";
2272 # Install custom built app, overwriting an app with the same app identifier if one exists.
2273 exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "install", $simulatedDeviceUDID, $appBundle)) == 0 or die;
2277 $simulatorOptions = {} unless $simulatorOptions;
2280 %simulatorENV = %{$simulatorOptions->{applicationEnvironment}} if $simulatorOptions->{applicationEnvironment};
2282 local %ENV; # Shadow global-scope %ENV so that changes to it will not be seen outside of this scope.
2283 setupIOSWebKitEnvironment($productDir);
2284 %simulatorENV = %ENV;
2286 my $applicationArguments = \@ARGV;
2287 $applicationArguments = $simulatorOptions->{applicationArguments} if $simulatorOptions && $simulatorOptions->{applicationArguments};
2289 # Prefix the environment variables with SIMCTL_CHILD_ per `xcrun simctl help launch`.
2290 foreach my $key (keys %simulatorENV) {
2291 $ENV{"SIMCTL_CHILD_$key"} = $simulatorENV{$key};
2294 print "Starting $appDisplayName with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2295 return exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "launch", $simulatedDeviceUDID, $appIdentifier, @$applicationArguments));
2298 sub runIOSWebKitApp($)
2300 my ($appBundle) = @_;
2301 if (willUseIOSDeviceSDKWhenBuilding()) {
2302 die "Only running Safari in iOS Simulator is supported now.";
2304 if (willUseIOSSimulatorSDKWhenBuilding()) {
2305 return runIOSWebKitAppInSimulator($appBundle);
2307 die "Not using an iOS SDK."
2310 sub runMacWebKitApp($;$)
2312 my ($appPath, $useOpenCommand) = @_;
2313 my $productDir = productDir();
2314 print "Starting @{[basename($appPath)]} with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2317 setupMacWebKitEnvironment($productDir);
2319 if (defined($useOpenCommand) && $useOpenCommand == USE_OPEN_COMMAND) {
2320 return system("open", "-W", "-a", $appPath, "--args", argumentsForRunAndDebugMacWebKitApp());
2322 if (architecture()) {
2323 return system "arch", "-" . architecture(), $appPath, argumentsForRunAndDebugMacWebKitApp();
2325 return system { $appPath } $appPath, argumentsForRunAndDebugMacWebKitApp();
2328 sub execMacWebKitAppForDebugging($)
2331 my $architectureSwitch;
2332 my $argumentsSeparator;
2334 if (debugger() eq "lldb") {
2335 $architectureSwitch = "--arch";
2336 $argumentsSeparator = "--";
2337 } elsif (debugger() eq "gdb") {
2338 $architectureSwitch = "-arch";
2339 $argumentsSeparator = "--args";
2341 die "Unknown debugger $debugger.\n";
2344 my $debuggerPath = `xcrun -find $debugger`;
2345 chomp $debuggerPath;
2346 die "Can't find the $debugger executable.\n" unless -x $debuggerPath;
2348 my $productDir = productDir();
2349 setupMacWebKitEnvironment($productDir);
2351 my @architectureFlags = ($architectureSwitch, architecture());
2352 if (!shouldTargetWebProcess()) {
2353 print "Starting @{[basename($appPath)]} under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2354 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $appPath, argumentsForRunAndDebugMacWebKitApp() or die;
2356 if (shouldUseXPCServiceForWebProcess()) {
2357 die "Targeting the Web Process is not compatible with using an XPC Service for the Web Process at this time.";
2360 my $webProcessShimPath = File::Spec->catfile($productDir, "SecItemShim.dylib");
2361 my $webProcessPath = File::Spec->catdir($productDir, "WebProcess.app");
2362 my $webKit2ExecutablePath = File::Spec->catfile($productDir, "WebKit2.framework", "WebKit2");
2364 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", $webProcessShimPath);
2366 print "Starting WebProcess under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2367 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $webProcessPath, $webKit2ExecutablePath, "-type", "webprocess", "-client-executable", $appPath or die;
2373 if (isAppleMacWebKit()) {
2375 execMacWebKitAppForDebugging(safariPath());
2378 return 1; # Unsupported platform; can't debug Safari on this platform.
2383 if (isIOSWebKit()) {
2384 return runIOSWebKitApp(mobileSafariBundle());
2387 if (isAppleMacWebKit()) {
2388 return runMacWebKitApp(safariPath());
2391 if (isAppleWinWebKit()) {
2393 my $productDir = productDir();
2394 my $webKitLauncherPath = File::Spec->catfile(productDir(), "WinLauncher.exe");
2395 return system { $webKitLauncherPath } $webKitLauncherPath, @ARGV;
2398 return 1; # Unsupported platform; can't run Safari on this platform.
2403 if (isAppleMacWebKit()) {
2404 return runMacWebKitApp(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2410 sub debugMiniBrowser
2412 if (isAppleMacWebKit()) {
2413 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2419 sub runWebKitTestRunner
2421 if (isAppleMacWebKit()) {
2422 return runMacWebKitApp(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2428 sub debugWebKitTestRunner
2430 if (isAppleMacWebKit()) {
2431 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2437 sub readRegistryString
2439 my ($valueName) = @_;
2440 chomp(my $string = `regtool --wow32 get "$valueName"`);
2444 sub writeRegistryString
2446 my ($valueName, $string) = @_;
2448 my $error = system "regtool", "--wow32", "set", "-s", $valueName, $string;
2450 # On Windows Vista/7 with UAC enabled, regtool will fail to modify the registry, but will still
2451 # return a successful exit code. So we double-check here that the value we tried to write to the
2452 # registry was really written.
2453 return !$error && readRegistryString($valueName) eq $string;
2456 sub formatBuildTime($)
2458 my ($buildTime) = @_;
2460 my $buildHours = int($buildTime / 3600);
2461 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
2462 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
2465 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
2467 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
2470 sub runSvnUpdateAndResolveChangeLogs(@)
2472 my @svnOptions = @_;
2473 my $openCommand = "svn update " . join(" ", @svnOptions);
2474 open my $update, "$openCommand |" or die "cannot execute command $openCommand";
2475 my @conflictedChangeLogs;
2476 while (my $line = <$update>) {
2478 $line =~ m/^C\s+(.+?)[\r\n]*$/;
2480 my $filename = normalizePath($1);
2481 push @conflictedChangeLogs, $filename if basename($filename) eq "ChangeLog";
2484 close $update or die;
2486 if (@conflictedChangeLogs) {
2487 print "Attempting to merge conflicted ChangeLogs.\n";
2488 my $resolveChangeLogsPath = File::Spec->catfile(sourceDir(), "Tools", "Scripts", "resolve-ChangeLogs");
2489 (system($resolveChangeLogsPath, "--no-warnings", @conflictedChangeLogs) == 0)
2490 or die "Could not open resolve-ChangeLogs script: $!.\n";
2496 # Doing a git fetch first allows setups with svn-remote.svn.fetch = trunk:refs/remotes/origin/master
2497 # to perform the rebase much much faster.
2498 system("git", "fetch");
2499 if (isGitSVNDirectory(".")) {
2500 system("git", "svn", "rebase") == 0 or die;
2502 # This will die if branch.$BRANCHNAME.merge isn't set, which is
2503 # almost certainly what we want.
2504 system("git", "pull") == 0 or die;