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
89 use constant USE_OPEN_COMMAND => 1; # Used in runMacWebKitApp().
90 use constant INCLUDE_OPTIONS_FOR_DEBUGGING => 1;
91 use constant SIMULATOR_DEVICE_STATE_SHUTDOWN => "1";
92 use constant SIMULATOR_DEVICE_STATE_BOOTED => "3";
101 my @baseProductDirOption;
104 my $configurationForVisualStudio;
105 my $configurationProductDir;
107 my $currentSVNRevision;
109 my $didLoadIPhoneSimulatorNotification;
117 my $isInspectorFrontend;
118 my $shouldTargetWebProcess;
119 my $shouldUseXPCServiceForWebProcess;
120 my $shouldUseGuardMalloc;
123 # Variables for Win32 support
124 my $programFilesPath;
127 my $msBuildInstallDir;
129 my $windowsSourceDir;
131 my $willUseVCExpressWhenBuilding = 0;
133 # Defined in VCSUtils.
136 sub findMatchingArguments($$);
139 sub determineSourceDir
141 return if $sourceDir;
142 $sourceDir = $FindBin::Bin;
143 $sourceDir =~ s|/+$||; # Remove trailing '/' as we would die later
145 # walks up path checking each directory to see if it is the main WebKit project dir,
146 # defined by containing Sources, WebCore, and WebKit
147 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")))
149 if ($sourceDir !~ s|/[^/]+$||) {
150 die "Could not find top level webkit directory above source directory using FindBin.\n";
154 $sourceDir = File::Spec->catdir($sourceDir, "OpenSource") if -d File::Spec->catdir($sourceDir, "OpenSource");
157 sub currentPerlPath()
161 $thisPerl .= $Config{_exe} unless $thisPerl =~ m/$Config{_exe}$/i;
166 # used for scripts which are stored in a non-standard location
172 sub determineNinjaVersion
174 chomp(my $ninjaVersion = `ninja --version`);
175 return $ninjaVersion;
178 sub determineXcodeVersion
180 return if defined $xcodeVersion;
181 my $xcodebuildVersionOutput = `xcodebuild -version`;
182 $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : "3.0";
185 sub readXcodeUserDefault($)
187 my ($unprefixedKey) = @_;
189 determineXcodeVersion();
191 my $xcodeDefaultsDomain = (eval "v$xcodeVersion" lt v4) ? "com.apple.Xcode" : "com.apple.dt.Xcode";
192 my $xcodeDefaultsPrefix = (eval "v$xcodeVersion" lt v4) ? "PBX" : "IDE";
193 my $devnull = File::Spec->devnull();
195 my $value = `defaults read $xcodeDefaultsDomain ${xcodeDefaultsPrefix}${unprefixedKey} 2> ${devnull}`;
202 sub determineBaseProductDir
204 return if defined $baseProductDir;
205 determineSourceDir();
207 my $setSharedPrecompsDir;
208 $baseProductDir = $ENV{"WEBKIT_OUTPUTDIR"};
210 if (!defined($baseProductDir) and isAppleMacWebKit()) {
211 # Silently remove ~/Library/Preferences/xcodebuild.plist which can
212 # cause build failure. The presence of
213 # ~/Library/Preferences/xcodebuild.plist can prevent xcodebuild from
214 # respecting global settings such as a custom build products directory
215 # (<rdar://problem/5585899>).
216 my $personalPlistFile = $ENV{HOME} . "/Library/Preferences/xcodebuild.plist";
217 if (-e $personalPlistFile) {
218 unlink($personalPlistFile) || die "Could not delete $personalPlistFile: $!";
221 determineXcodeVersion();
223 if (eval "v$xcodeVersion" ge v4) {
224 my $buildLocationStyle = join '', readXcodeUserDefault("BuildLocationStyle");
225 if ($buildLocationStyle eq "Custom") {
226 my $buildLocationType = join '', readXcodeUserDefault("CustomBuildLocationType");
227 # FIXME: Read CustomBuildIntermediatesPath and set OBJROOT accordingly.
228 $baseProductDir = readXcodeUserDefault("CustomBuildProductsPath") if $buildLocationType eq "Absolute";
231 # DeterminedByTargets corresponds to a setting of "Legacy" in Xcode.
232 # It is the only build location style for which SHARED_PRECOMPS_DIR is not
233 # overridden when building from within Xcode.
234 $setSharedPrecompsDir = 1 if $buildLocationStyle ne "DeterminedByTargets";
237 if (!defined($baseProductDir)) {
238 $baseProductDir = join '', readXcodeUserDefault("ApplicationwideBuildSettings");
239 $baseProductDir = $1 if $baseProductDir =~ /SYMROOT\s*=\s*\"(.*?)\";/s;
242 undef $baseProductDir unless $baseProductDir =~ /^\//;
245 if (!defined($baseProductDir)) { # Port-specific checks failed, use default
246 $baseProductDir = "$sourceDir/WebKitBuild";
249 if (isGit() && isGitBranchBuild()) {
250 my $branch = gitBranch();
251 $baseProductDir = "$baseProductDir/$branch";
254 if (isAppleMacWebKit()) {
255 $baseProductDir =~ s|^\Q$(SRCROOT)/..\E$|$sourceDir|;
256 $baseProductDir =~ s|^\Q$(SRCROOT)/../|$sourceDir/|;
257 $baseProductDir =~ s|^~/|$ENV{HOME}/|;
258 die "Can't handle Xcode product directory with a ~ in it.\n" if $baseProductDir =~ /~/;
259 die "Can't handle Xcode product directory with a variable in it.\n" if $baseProductDir =~ /\$/;
260 @baseProductDirOption = ("SYMROOT=$baseProductDir", "OBJROOT=$baseProductDir");
261 push(@baseProductDirOption, "SHARED_PRECOMPS_DIR=${baseProductDir}/PrecompiledHeaders") if $setSharedPrecompsDir;
265 my $dosBuildPath = `cygpath --windows \"$baseProductDir\"`;
267 $ENV{"WEBKIT_OUTPUTDIR"} = $dosBuildPath;
268 my $unixBuildPath = `cygpath --unix \"$baseProductDir\"`;
269 chomp $unixBuildPath;
270 $baseProductDir = $unixBuildPath;
274 sub setBaseProductDir($)
276 ($baseProductDir) = @_;
279 sub determineConfiguration
281 return if defined $configuration;
282 determineBaseProductDir();
283 if (open CONFIGURATION, "$baseProductDir/Configuration") {
284 $configuration = <CONFIGURATION>;
287 if ($configuration) {
288 chomp $configuration;
289 # compatibility for people who have old Configuration files
290 $configuration = "Release" if $configuration eq "Deployment";
291 $configuration = "Debug" if $configuration eq "Development";
293 $configuration = "Release";
296 if ($configuration && isWinCairo()) {
297 unless ($configuration =~ /_WinCairo$/) {
298 $configuration .= "_WinCairo";
303 sub determineArchitecture
305 return if defined $architecture;
306 # make sure $architecture is defined in all cases
309 determineBaseProductDir();
312 if (isAppleMacWebKit()) {
313 if (open ARCHITECTURE, "$baseProductDir/Architecture") {
314 $architecture = <ARCHITECTURE>;
320 if (not defined $xcodeSDK or $xcodeSDK =~ /^(\/$|macosx)/) {
321 my $supports64Bit = `sysctl -n hw.optional.x86_64`;
322 chomp $supports64Bit;
323 $architecture = 'x86_64' if $supports64Bit;
324 } elsif ($xcodeSDK =~ /^iphonesimulator/) {
325 $architecture = 'x86_64';
326 } elsif ($xcodeSDK =~ /^iphoneos/) {
327 $architecture = 'armv7';
330 } elsif (isEfl() || isGtk()) {
331 my $host_processor = "";
332 $host_processor = `cmake --system-information | grep CMAKE_SYSTEM_PROCESSOR`;
333 if ($host_processor =~ m/^CMAKE_SYSTEM_PROCESSOR \"([^"]+)\"/) {
334 # We have a configured build tree; use it.
336 $architecture = 'x86_64' if $architecture eq 'amd64';
340 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
341 # Fall back to output of `arch', if it is present.
342 $architecture = `arch`;
346 if (!$architecture && (isGtk() || isAppleMacWebKit() || isEfl())) {
347 # Fall back to output of `uname -m', if it is present.
348 $architecture = `uname -m`;
352 $architecture = 'x86_64' if ($architecture =~ /amd64/ && isBSD());
355 sub determineASanIsEnabled
357 return if defined $asanIsEnabled;
358 determineBaseProductDir();
361 my $asanConfigurationValue;
363 if (open ASAN, "$baseProductDir/ASan") {
364 $asanConfigurationValue = <ASAN>;
366 chomp $asanConfigurationValue;
367 $asanIsEnabled = 1 if $asanConfigurationValue eq "YES";
371 sub determineNumberOfCPUs
373 return if defined $numberOfCPUs;
374 if (defined($ENV{NUMBER_OF_PROCESSORS})) {
375 $numberOfCPUs = $ENV{NUMBER_OF_PROCESSORS};
376 } elsif (isLinux()) {
377 # First try the nproc utility, if it exists. If we get no
378 # results fall back to just interpretting /proc directly.
379 chomp($numberOfCPUs = `nproc --all 2> /dev/null`);
380 if ($numberOfCPUs eq "") {
381 $numberOfCPUs = (grep /processor/, `cat /proc/cpuinfo`);
383 } elsif (isWindows() || isCygwin()) {
385 $numberOfCPUs = `ls /proc/registry/HKEY_LOCAL_MACHINE/HARDWARE/DESCRIPTION/System/CentralProcessor | wc -w`;
386 } elsif (isDarwin() || isBSD()) {
387 chomp($numberOfCPUs = `sysctl -n hw.ncpu`);
391 sub determineMaxCPULoad
393 return if defined $maxCPULoad;
394 if (defined($ENV{MAX_CPU_LOAD})) {
395 $maxCPULoad = $ENV{MAX_CPU_LOAD};
401 my ($productDir) = @_;
403 $jscName .= "_debug" if configuration() eq "Debug_All";
404 $jscName .= ".exe" if (isWindows() || isCygwin());
405 return "$productDir/$jscName" if -e "$productDir/$jscName";
406 return "$productDir/JavaScriptCore.framework/Resources/$jscName";
409 sub argumentsForConfiguration()
411 determineConfiguration();
412 determineArchitecture();
416 # FIXME: Is it necessary to pass --debug, --release, --32-bit or --64-bit?
417 # These are determined automatically from stored configuration.
418 push(@args, '--debug') if ($configuration =~ "^Debug");
419 push(@args, '--release') if ($configuration =~ "^Release");
420 push(@args, '--device') if (defined $xcodeSDK && $xcodeSDK =~ /^iphoneos/);
421 push(@args, '--ios-simulator') if (defined $xcodeSDK && $xcodeSDK =~ /^iphonesimulator/);
422 push(@args, '--32-bit') if ($architecture ne "x86_64" and !isWin64());
423 push(@args, '--64-bit') if (isWin64());
424 push(@args, '--gtk') if isGtk();
425 push(@args, '--efl') if isEfl();
426 push(@args, '--wincairo') if isWinCairo();
427 push(@args, '--inspector-frontend') if isInspectorFrontend();
431 sub determineXcodeSDK
433 return if defined $xcodeSDK;
435 if (checkForArgumentAndRemoveFromARGVGettingValue("--sdk", \$sdk)) {
438 if (checkForArgumentAndRemoveFromARGV("--device")) {
439 my $hasInternalSDK = exitStatus(system("xcrun --sdk iphoneos.internal --show-sdk-version > /dev/null 2>&1")) == 0;
440 $xcodeSDK ||= $hasInternalSDK ? "iphoneos.internal" : "iphoneos";
442 if (checkForArgumentAndRemoveFromARGV("--ios-simulator")) {
443 $xcodeSDK ||= 'iphonesimulator';
459 sub xcodeSDKPlatformName()
462 return "" if !defined $xcodeSDK;
463 return "iphoneos" if $xcodeSDK =~ /iphoneos/i;
464 return "iphonesimulator" if $xcodeSDK =~ /iphonesimulator/i;
465 return "macosx" if $xcodeSDK =~ /macosx/i;
466 die "Couldn't determine platform name from Xcode SDK";
473 die "Can't find the SDK path because no Xcode SDK was specified" if not $xcodeSDK;
475 my $sdkPath = `xcrun --sdk $xcodeSDK --show-sdk-path` if $xcodeSDK;
476 die 'Failed to get SDK path from xcrun' if $?;
486 die "Can't find the SDK version because no Xcode SDK was specified" if !$xcodeSDK;
488 chomp(my $sdkVersion = `xcrun --sdk $xcodeSDK --show-sdk-version`);
489 die "Failed to get SDK version from xcrun" if exitStatus($?);
496 return $programFilesPath if defined $programFilesPath;
498 $programFilesPath = $ENV{'PROGRAMFILES(X86)'} || $ENV{'PROGRAMFILES'} || "C:\\Program Files";
500 return $programFilesPath;
503 sub visualStudioInstallDir
505 return $vsInstallDir if defined $vsInstallDir;
507 if ($ENV{'VSINSTALLDIR'}) {
508 $vsInstallDir = $ENV{'VSINSTALLDIR'};
509 $vsInstallDir =~ s|[\\/]$||;
511 $vsInstallDir = File::Spec->catdir(programFilesPath(), "Microsoft Visual Studio 12.0");
513 chomp($vsInstallDir = `cygpath "$vsInstallDir"`) if isCygwin();
515 return $vsInstallDir;
518 sub msBuildInstallDir
520 return $msBuildInstallDir if defined $msBuildInstallDir;
522 $msBuildInstallDir = File::Spec->catdir(programFilesPath(), "MSBuild", "12.0", "Bin");
523 chomp($msBuildInstallDir = `cygpath "$msBuildInstallDir"`) if isCygwin();
525 return $msBuildInstallDir;
528 sub visualStudioVersion
530 return $vsVersion if defined $vsVersion;
532 my $installDir = visualStudioInstallDir();
534 $vsVersion = ($installDir =~ /Microsoft Visual Studio ([0-9]+\.[0-9]*)/) ? $1 : "12";
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 (@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";
719 $passedConfiguration .= "_WinCairo" if (defined($passedConfiguration) && isWinCairo());
722 sub passedConfiguration
724 determinePassedConfiguration();
725 return $passedConfiguration;
732 if (my $config = shift @_) {
733 $configuration = $config;
737 determinePassedConfiguration();
738 $configuration = $passedConfiguration if $passedConfiguration;
742 my $passedArchitecture;
743 my $searchedForPassedArchitecture;
744 sub determinePassedArchitecture
746 return if $searchedForPassedArchitecture;
747 $searchedForPassedArchitecture = 1;
749 $passedArchitecture = undef;
750 if (checkForArgumentAndRemoveFromARGV("--32-bit")) {
751 if (isAppleMacWebKit()) {
752 # PLATFORM_IOS: Don't run `arch` command inside Simulator environment
754 delete $ENV{DYLD_ROOT_PATH};
755 delete $ENV{DYLD_FRAMEWORK_PATH};
757 $passedArchitecture = `arch`;
758 chomp $passedArchitecture;
763 sub passedArchitecture
765 determinePassedArchitecture();
766 return $passedArchitecture;
771 determineArchitecture();
772 return $architecture;
777 determineNumberOfCPUs();
778 return $numberOfCPUs;
783 determineMaxCPULoad();
789 if (my $arch = shift @_) {
790 $architecture = $arch;
794 determinePassedArchitecture();
795 $architecture = $passedArchitecture if $passedArchitecture;
798 sub skipSafariExecutableEntitlementChecks
800 return `defaults read /Library/Preferences/org.webkit.BuildConfiguration SkipSafariExecutableEntitlementChecks 2>/dev/null` eq "1\n";
803 sub executableHasEntitlements
805 my $executablePath = shift;
806 return (`codesign -d --entitlements - $executablePath 2>&1` =~ /<key>/);
809 sub safariPathFromSafariBundle
811 my ($safariBundle) = @_;
813 die "Safari path is only relevant on Apple Mac platform\n" unless isAppleMacWebKit();
815 my $safariPath = "$safariBundle/Contents/MacOS/Safari";
816 return $safariPath if skipSafariExecutableEntitlementChecks();
818 my $safariForWebKitDevelopmentPath = "$safariBundle/Contents/MacOS/SafariForWebKitDevelopment";
819 return $safariForWebKitDevelopmentPath if -f $safariForWebKitDevelopmentPath && executableHasEntitlements($safariPath);
824 sub installedSafariPath
826 return safariPathFromSafariBundle("/Applications/Safari.app");
832 die "Safari path is only relevant on Apple Mac platform\n" unless isAppleMacWebKit();
834 # Use WEBKIT_SAFARI environment variable if present.
835 my $safariBundle = $ENV{WEBKIT_SAFARI};
836 if (!$safariBundle) {
837 determineConfigurationProductDir();
838 # Use Safari.app in product directory if present (good for Safari development team).
839 if (-d "$configurationProductDir/Safari.app") {
840 $safariBundle = "$configurationProductDir/Safari.app";
842 if (!$safariBundle) {
843 return installedSafariPath();
846 my $safariPath = safariPathFromSafariBundle($safariBundle);
847 die "Can't find executable at $safariPath.\n" if !-x $safariPath;
851 sub builtDylibPathForName
853 my $libraryName = shift;
854 determineConfigurationProductDir();
857 my $extension = isDarwin() ? ".dylib" : ".so";
858 return "$configurationProductDir/lib/libwebkit2gtk-4.0" . $extension;
861 return "$configurationProductDir/lib/libewebkit2.so";
864 return "$configurationProductDir/$libraryName.framework/$libraryName";
866 if (isAppleMacWebKit()) {
867 return "$configurationProductDir/$libraryName.framework/Versions/A/$libraryName";
869 if (isAppleWinWebKit()) {
870 if ($libraryName eq "JavaScriptCore") {
871 return "$baseProductDir/lib/$libraryName.lib";
873 return "$baseProductDir/$libraryName.intermediate/$configuration/$libraryName.intermediate/$libraryName.lib";
877 die "Unsupported platform, can't determine built library locations.\nTry `build-webkit --help` for more information.\n";
880 # Check to see that all the frameworks are built.
881 sub checkFrameworks # FIXME: This is a poor name since only the Mac calls built WebCore a Framework.
883 return if isCygwin() || isWindows();
884 my @frameworks = ("JavaScriptCore", "WebCore");
885 push(@frameworks, "WebKit") if isAppleMacWebKit(); # FIXME: This seems wrong, all ports should have a WebKit these days.
886 for my $framework (@frameworks) {
887 my $path = builtDylibPathForName($framework);
888 die "Can't find built framework at \"$path\".\n" unless -e $path;
892 sub isInspectorFrontend()
894 determineIsInspectorFrontend();
895 return $isInspectorFrontend;
898 sub determineIsInspectorFrontend()
900 return if defined($isInspectorFrontend);
901 $isInspectorFrontend = checkForArgumentAndRemoveFromARGV("--inspector-frontend");
907 my $devnull = File::Spec->devnull();
909 if (isAnyWindows()) {
910 return exitStatus(system("where /q $command >$devnull 2>&1")) == 0;
912 return exitStatus(system("which $command >$devnull 2>&1")) == 0;
915 sub checkForArgumentAndRemoveFromARGV($)
917 my $argToCheck = shift;
918 return checkForArgumentAndRemoveFromArrayRef($argToCheck, \@ARGV);
921 sub checkForArgumentAndRemoveFromArrayRefGettingValue($$$)
923 my ($argToCheck, $valueRef, $arrayRef) = @_;
924 my $argumentStartRegEx = qr#^$argToCheck(?:=\S|$)#;
926 for (; $i < @$arrayRef; ++$i) {
927 last if $arrayRef->[$i] =~ $argumentStartRegEx;
929 if ($i >= @$arrayRef) {
930 return $$valueRef = undef;
932 my ($key, $value) = split("=", $arrayRef->[$i]);
933 splice(@$arrayRef, $i, 1);
934 if (defined($value)) {
935 # e.g. --sdk=iphonesimulator
936 return $$valueRef = $value;
938 return $$valueRef = splice(@$arrayRef, $i, 1); # e.g. --sdk iphonesimulator
941 sub checkForArgumentAndRemoveFromARGVGettingValue($$)
943 my ($argToCheck, $valueRef) = @_;
944 return checkForArgumentAndRemoveFromArrayRefGettingValue($argToCheck, $valueRef, \@ARGV);
947 sub findMatchingArguments($$)
949 my ($argToCheck, $arrayRef) = @_;
951 foreach my $index (0 .. $#$arrayRef) {
952 my $opt = $$arrayRef[$index];
953 if ($opt =~ /^$argToCheck$/i ) {
954 push(@matchingIndices, $index);
957 return @matchingIndices;
962 my ($argToCheck, $arrayRef) = @_;
963 my @matchingIndices = findMatchingArguments($argToCheck, $arrayRef);
964 return scalar @matchingIndices > 0;
967 sub checkForArgumentAndRemoveFromArrayRef
969 my ($argToCheck, $arrayRef) = @_;
970 my @indicesToRemove = findMatchingArguments($argToCheck, $arrayRef);
971 my $removeOffset = 0;
972 foreach my $index (@indicesToRemove) {
973 splice(@$arrayRef, $index - $removeOffset++, 1);
975 return scalar @indicesToRemove > 0;
980 return if defined($isEfl);
981 $isEfl = checkForArgumentAndRemoveFromARGV("--efl");
992 return if defined($isGtk);
993 $isGtk = checkForArgumentAndRemoveFromARGV("--gtk");
1002 # Determine if this is debian, ubuntu, linspire, or something similar.
1005 return -e "/etc/debian_version";
1010 return -e "/etc/fedora-release";
1015 determineIsWinCairo();
1019 sub determineIsWinCairo()
1021 return if defined($isWinCairo);
1022 $isWinCairo = checkForArgumentAndRemoveFromARGV("--wincairo");
1031 sub determineIsWin64()
1033 return if defined($isWin64);
1034 $isWin64 = checkForArgumentAndRemoveFromARGV("--64-bit");
1039 return ($^O eq "cygwin") || 0;
1044 return isWindows() || isCygwin();
1047 sub determineWinVersion()
1049 return if $winVersion;
1051 if (!isAnyWindows()) {
1056 my $versionString = `cmd /c ver`;
1057 $versionString =~ /(\d)\.(\d)\.(\d+)/;
1068 determineWinVersion();
1074 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 1 && winVersion()->{build} == 7600;
1077 sub isWindowsVista()
1079 return isAnyWindows() && winVersion()->{major} == 6 && winVersion()->{minor} == 0;
1084 return isAnyWindows() && winVersion()->{major} == 5 && winVersion()->{minor} == 1;
1089 return ($^O eq "darwin") || 0;
1094 return ($^O eq "MSWin32") || 0;
1099 return ($^O eq "linux") || 0;
1104 return ($^O eq "freebsd") || ($^O eq "openbsd") || ($^O eq "netbsd") || 0;
1109 return ($Config{archname} =~ /^arm[v\-]/) || ($Config{archname} =~ /^aarch64[v\-]/);
1112 sub isCrossCompilation()
1115 $compiler = $ENV{'CC'} if (defined($ENV{'CC'}));
1116 if ($compiler =~ /gcc/) {
1117 my $compiler_options = `$compiler -v 2>&1`;
1118 my @host = $compiler_options =~ m/--host=(.*?)\s/;
1119 my @target = $compiler_options =~ m/--target=(.*?)\s/;
1121 return ($host[0] ne "" && $target[0] ne "" && $host[0] ne $target[0]);
1128 return isAppleMacWebKit() || isAppleWinWebKit();
1131 sub isAppleMacWebKit()
1133 return isDarwin() && !isGtk();
1136 sub isAppleWinWebKit()
1138 return (isCygwin() || isWindows()) && !isWinCairo() && !isGtk();
1141 sub iOSSimulatorDevicesPath
1143 return "$ENV{HOME}/Library/Developer/CoreSimulator/Devices";
1146 sub iOSSimulatorDevices
1148 eval "require Foundation";
1149 my $devicesPath = iOSSimulatorDevicesPath();
1150 opendir(DEVICES, $devicesPath);
1152 $_ =~ m/[0-9A-F]{8}-([0-9A-F]{4}-){3}[0-9A-F]{12}/;
1156 # FIXME: We should parse the device.plist file ourself and map the dictionary keys in it to known
1157 # dictionary keys so as to decouple our representation of the plist from the actual structure
1158 # of the plist, which may change.
1160 Foundation::perlRefFromObjectRef(NSDictionary->dictionaryWithContentsOfFile_("$devicesPath/$_/device.plist"));
1166 sub createiOSSimulatorDevice
1169 my $deviceTypeId = shift;
1170 my $runtimeId = shift;
1172 my $created = system("xcrun", "--sdk", "iphonesimulator", "simctl", "create", $name, $deviceTypeId, $runtimeId) == 0;
1173 die "Couldn't create simulator device: $name $deviceTypeId $runtimeId" if not $created;
1175 system("xcrun", "--sdk", "iphonesimulator", "simctl", "list");
1177 print "Waiting for device to be created ...\n";
1179 for (my $tries = 0; $tries < 5; $tries++){
1180 my @devices = iOSSimulatorDevices();
1181 foreach my $device (@devices) {
1182 return $device if $device->{name} eq $name and $device->{deviceType} eq $deviceTypeId and $device->{runtime} eq $runtimeId;
1186 die "Device $name $deviceTypeId $runtimeId wasn't found in " . iOSSimulatorDevicesPath();
1189 sub willUseIOSDeviceSDKWhenBuilding()
1191 return xcodeSDKPlatformName() eq "iphoneos";
1194 sub willUseIOSSimulatorSDKWhenBuilding()
1196 return xcodeSDKPlatformName() eq "iphonesimulator";
1201 determineXcodeSDK();
1202 return isAppleMacWebKit() && (willUseIOSDeviceSDKWhenBuilding() || willUseIOSSimulatorSDKWhenBuilding());
1205 sub determineNmPath()
1209 if (isAppleMacWebKit()) {
1210 $nmPath = `xcrun -find nm`;
1213 $nmPath = "nm" if !$nmPath;
1222 sub determineOSXVersion()
1224 return if $osXVersion;
1231 my $version = `sw_vers -productVersion`;
1232 my @splitVersion = split(/\./, $version);
1233 @splitVersion >= 2 or die "Invalid version $version";
1235 "major" => $splitVersion[0],
1236 "minor" => $splitVersion[1],
1237 "subminor" => (defined($splitVersion[2]) ? $splitVersion[2] : 0),
1243 determineOSXVersion();
1249 return $ENV{'OS'} eq 'Windows_NT';
1252 sub shouldTargetWebProcess
1254 determineShouldTargetWebProcess();
1255 return $shouldTargetWebProcess;
1258 sub determineShouldTargetWebProcess
1260 return if defined($shouldTargetWebProcess);
1261 $shouldTargetWebProcess = checkForArgumentAndRemoveFromARGV("--target-web-process");
1264 sub shouldUseXPCServiceForWebProcess
1266 determineShouldUseXPCServiceForWebProcess();
1267 return $shouldUseXPCServiceForWebProcess;
1270 sub determineShouldUseXPCServiceForWebProcess
1272 return if defined($shouldUseXPCServiceForWebProcess);
1273 $shouldUseXPCServiceForWebProcess = checkForArgumentAndRemoveFromARGV("--use-web-process-xpc-service");
1278 determineDebugger();
1282 sub determineDebugger
1284 return if defined($debugger);
1286 determineXcodeVersion();
1287 if (eval "v$xcodeVersion" ge v4.5) {
1293 if (checkForArgumentAndRemoveFromARGV("--use-lldb")) {
1297 if (checkForArgumentAndRemoveFromARGV("--use-gdb")) {
1302 sub appendToEnvironmentVariableList
1304 my ($environmentVariableName, $value) = @_;
1306 if (defined($ENV{$environmentVariableName})) {
1307 $ENV{$environmentVariableName} .= ":" . $value;
1309 $ENV{$environmentVariableName} = $value;
1313 sub sharedCommandLineOptions()
1316 "g|guard-malloc" => \$shouldUseGuardMalloc,
1320 sub sharedCommandLineOptionsUsage
1325 '-g|--guard-malloc' => 'Use guardmalloc when running executable',
1328 my $indent = " " x ($opts{indent} || 2);
1329 my $switchWidth = List::Util::max(int($opts{switchWidth}), List::Util::max(map { length($_) } keys %switches) + ($opts{brackets} ? 2 : 0));
1331 my $result = "Common switches:\n";
1333 for my $switch (keys %switches) {
1334 my $switchName = $opts{brackets} ? "[" . $switch . "]" : $switch;
1335 $result .= sprintf("%s%-" . $switchWidth . "s %s\n", $indent, $switchName, $switches{$switch});
1341 sub setUpGuardMallocIfNeeded
1347 if (!defined($shouldUseGuardMalloc)) {
1348 $shouldUseGuardMalloc = checkForArgumentAndRemoveFromARGV("-g") || checkForArgumentAndRemoveFromARGV("--guard-malloc");
1351 if ($shouldUseGuardMalloc) {
1352 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", "/usr/lib/libgmalloc.dylib");
1356 sub relativeScriptsDir()
1358 my $scriptDir = File::Spec->catpath("", File::Spec->abs2rel($FindBin::Bin, getcwd()), "");
1359 if ($scriptDir eq "") {
1367 my $relativeScriptsPath = relativeScriptsDir();
1368 if (isGtk() || isEfl()) {
1369 return "$relativeScriptsPath/run-minibrowser";
1370 } elsif (isAppleWebKit()) {
1371 return "$relativeScriptsPath/run-safari";
1377 if (isGtk() || isEfl()) {
1378 return "MiniBrowser";
1379 } elsif (isAppleMacWebKit()) {
1381 } elsif (isAppleWinWebKit()) {
1382 return "WinLauncher";
1386 sub checkRequiredSystemConfig
1389 chomp(my $productVersion = `sw_vers -productVersion`);
1390 if (eval "v$productVersion" lt v10.7.5) {
1391 print "*************************************************************\n";
1392 print "Mac OS X Version 10.7.5 or later is required to build WebKit.\n";
1393 print "You have " . $productVersion . ", thus the build will most likely fail.\n";
1394 print "*************************************************************\n";
1396 my $xcodebuildVersionOutput = `xcodebuild -version`;
1397 my $xcodeVersion = ($xcodebuildVersionOutput =~ /Xcode ([0-9](\.[0-9]+)*)/) ? $1 : undef;
1398 if (!$xcodeVersion || $xcodeVersion && eval "v$xcodeVersion" lt v4.6) {
1399 print "*************************************************************\n";
1400 print "Xcode Version 4.6 or later is required to build WebKit.\n";
1401 print "You have an earlier version of Xcode, thus the build will\n";
1402 print "most likely fail. The latest Xcode is available from the App Store.\n";
1403 print "*************************************************************\n";
1405 } elsif (isGtk() or isEfl() or isWindows()) {
1406 my @cmds = qw(bison gperf flex);
1408 my $oldPath = $ENV{PATH};
1409 foreach my $cmd (@cmds) {
1410 push @missing, $cmd if not commandExists($cmd);
1414 my $list = join ", ", @missing;
1415 die "ERROR: $list missing but required to build WebKit.\n";
1418 # Win32 and other platforms may want to check for minimum config
1421 sub determineWindowsSourceDir()
1423 return if $windowsSourceDir;
1424 $windowsSourceDir = sourceDir();
1425 chomp($windowsSourceDir = `cygpath -w '$windowsSourceDir'`) if isCygwin();
1428 sub windowsSourceDir()
1430 determineWindowsSourceDir();
1431 return $windowsSourceDir;
1434 sub windowsSourceSourceDir()
1436 return File::Spec->catdir(windowsSourceDir(), "Source");
1439 sub windowsLibrariesDir()
1441 return File::Spec->catdir(windowsSourceDir(), "WebKitLibraries", "win");
1444 sub windowsOutputDir()
1446 return File::Spec->catdir(windowsSourceDir(), "WebKitBuild");
1452 my $cmd = "reg query \"HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts\\" . $font ."\" 2>&1";
1457 sub checkInstalledTools()
1459 # environment variables. Avoid until this is corrected.
1460 my $pythonVer = `python --version 2>&1`;
1461 die "You must have Python installed to build WebKit.\n" if ($?);
1463 # cURL 7.34.0 has a bug that prevents authentication with opensource.apple.com (and other things using SSL3).
1464 my $curlVer = `curl --version 2> NUL`;
1465 if (!$? and $curlVer =~ "(.*curl.*)") {
1467 if ($curlVer =~ /libcurl\/7\.34\.0/) {
1468 print "cURL version 7.34.0 has a bug that prevents authentication with SSL v2 or v3.\n";
1469 print "cURL 7.33.0 is known to work. The cURL projects is preparing an update to\n";
1470 print "correct this problem.\n\n";
1471 die "Please install a working cURL and try again.\n";
1475 # MathML requires fonts that do not ship with Windows (at least through Windows 8). Warn the user if they are missing
1476 my @fonts = qw(STIXGeneral-Regular MathJax_Main-Regular);
1478 foreach my $font (@fonts) {
1479 push @missing, $font if not fontExists($font);
1482 if (scalar @missing > 0) {
1483 print "*************************************************************\n";
1484 print "Mathematical fonts, such as STIX and MathJax, are needed to\n";
1485 print "use the MathML feature. You do not appear to have these fonts\n";
1486 print "on your system.\n\n";
1487 print "You can download a suitable set of fonts from the following URL:\n";
1488 print "https://developer.mozilla.org/Mozilla/MathML_Projects/Fonts\n";
1489 print "*************************************************************\n";
1492 print "Installed tools are correct for the WebKit build.\n";
1495 sub setupAppleWinEnv()
1497 return unless isAppleWinWebKit();
1499 checkInstalledTools();
1501 if (isWindowsNT()) {
1502 my $restartNeeded = 0;
1503 my %variablesToSet = ();
1505 # FIXME: We should remove this explicit version check for cygwin once we stop supporting Cygwin 1.7.9 or older versions.
1506 # https://bugs.webkit.org/show_bug.cgi?id=85791
1507 my $uname_version = (POSIX::uname())[2];
1508 $uname_version =~ s/\(.*\)//; # Remove the trailing cygwin version, if any.
1509 $uname_version =~ s/\-.*$//; # Remove trailing dash-version content, if any
1510 if (version->parse($uname_version) < version->parse("1.7.10")) {
1511 # Setting the environment variable 'CYGWIN' to 'tty' makes cygwin enable extra support (i.e., termios)
1512 # for UNIX-like ttys in the Windows console
1513 $variablesToSet{CYGWIN} = "tty" unless $ENV{CYGWIN};
1516 # Those environment variables must be set to be able to build inside Visual Studio.
1517 $variablesToSet{WEBKIT_LIBRARIES} = windowsLibrariesDir() unless $ENV{WEBKIT_LIBRARIES};
1518 $variablesToSet{WEBKIT_OUTPUTDIR} = windowsOutputDir() unless $ENV{WEBKIT_OUTPUTDIR};
1519 $variablesToSet{MSBUILDDISABLENODEREUSE} = "1" unless $ENV{MSBUILDDISABLENODEREUSE};
1521 foreach my $variable (keys %variablesToSet) {
1522 print "Setting the Environment Variable '" . $variable . "' to '" . $variablesToSet{$variable} . "'\n\n";
1523 my $ret = system "setx", $variable, $variablesToSet{$variable};
1525 system qw(regtool -s set), '\\HKEY_CURRENT_USER\\Environment\\' . $variable, $variablesToSet{$variable};
1527 $restartNeeded ||= $variable eq "WEBKIT_LIBRARIES" || $variable eq "WEBKIT_OUTPUTDIR";
1530 if ($restartNeeded) {
1531 print "Please restart your computer before attempting to build inside Visual Studio.\n\n";
1534 if (!defined $ENV{'WEBKIT_LIBRARIES'} || !$ENV{'WEBKIT_LIBRARIES'}) {
1535 print "Warning: You must set the 'WebKit_Libraries' environment variable\n";
1536 print " to be able build WebKit from within Visual Studio 2013 and newer.\n";
1537 print " Make sure that 'WebKit_Libraries' points to the\n";
1538 print " 'WebKitLibraries/win' directory, not the 'WebKitLibraries/' directory.\n\n";
1540 if (!defined $ENV{'WEBKIT_OUTPUTDIR'} || !$ENV{'WEBKIT_OUTPUTDIR'}) {
1541 print "Warning: You must set the 'WebKit_OutputDir' environment variable\n";
1542 print " to be able build WebKit from within Visual Studio 2013 and newer.\n\n";
1544 if (!defined $ENV{'MSBUILDDISABLENODEREUSE'} || !$ENV{'MSBUILDDISABLENODEREUSE'}) {
1545 print "Warning: You should set the 'MSBUILDDISABLENODEREUSE' environment variable to '1'\n";
1546 print " to avoid periodic locked log files when building.\n\n";
1549 # FIXME (125180): Remove the following temporary 64-bit support once official support is available.
1550 if (isWin64() and !$ENV{'WEBKIT_64_SUPPORT'}) {
1551 print "Warning: You must set the 'WEBKIT_64_SUPPORT' environment variable\n";
1552 print " to be able run WebKit or JavaScriptCore tests.\n\n";
1556 sub setupCygwinEnv()
1558 return if !isCygwin() && !isWindows();
1559 return if $vcBuildPath;
1561 my $programFilesPath = programFilesPath();
1562 my $visualStudioPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE devenv.com));
1563 if (-e $visualStudioPath) {
1564 # Visual Studio is installed;
1565 if (visualStudioVersion() eq "12") {
1566 $visualStudioPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE devenv.exe));
1569 # Visual Studio not found, try VC++ Express
1570 $visualStudioPath = File::Spec->catfile(visualStudioInstallDir(), qw(Common7 IDE WDExpress.exe));
1571 if (! -e $visualStudioPath) {
1572 print "*************************************************************\n";
1573 print "Cannot find '$visualStudioPath'\n";
1574 print "Please execute the file 'vcvars32.bat' from\n";
1575 print "'$programFilesPath\\Microsoft Visual Studio 12.0\\VC\\bin\\'\n";
1576 print "to setup the necessary environment variables.\n";
1577 print "*************************************************************\n";
1580 $willUseVCExpressWhenBuilding = 1;
1583 print "Building results into: ", baseProductDir(), "\n";
1584 print "WEBKIT_OUTPUTDIR is set to: ", $ENV{"WEBKIT_OUTPUTDIR"}, "\n";
1585 print "WEBKIT_LIBRARIES is set to: ", $ENV{"WEBKIT_LIBRARIES"}, "\n";
1586 # FIXME (125180): Remove the following temporary 64-bit support once official support is available.
1587 print "WEBKIT_64_SUPPORT is set to: ", $ENV{"WEBKIT_64_SUPPORT"}, "\n" if isWin64();
1589 # We will actually use MSBuild to build WebKit, but we need to find the Visual Studio install (above) to make
1590 # sure we use the right options.
1591 $vcBuildPath = File::Spec->catfile(msBuildInstallDir(), qw(MSBuild.exe));
1592 if (! -e $vcBuildPath) {
1593 print "*************************************************************\n";
1594 print "Cannot find '$vcBuildPath'\n";
1595 print "Please make sure execute that the Microsoft .NET Framework SDK\n";
1596 print "is installed on this machine.\n";
1597 print "*************************************************************\n";
1602 sub dieIfWindowsPlatformSDKNotInstalled
1604 my $registry32Path = "/proc/registry/";
1605 my $registry64Path = "/proc/registry64/";
1606 my @windowsPlatformSDKRegistryEntries = (
1607 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v8.0A",
1608 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v8.0",
1609 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.1A",
1610 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Microsoft SDKs/Windows/v7.0A",
1611 "HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/MicrosoftSDK/InstalledSDKs/D2FF9F89-8AA2-4373-8A31-C838BF4DBBE1",
1614 # FIXME: It would be better to detect whether we are using 32- or 64-bit Windows
1615 # and only check the appropriate entry. But for now we just blindly check both.
1616 my $recommendedPlatformSDK = $windowsPlatformSDKRegistryEntries[0];
1618 while (@windowsPlatformSDKRegistryEntries) {
1619 my $windowsPlatformSDKRegistryEntry = shift @windowsPlatformSDKRegistryEntries;
1620 return if (-e $registry32Path . $windowsPlatformSDKRegistryEntry) || (-e $registry64Path . $windowsPlatformSDKRegistryEntry);
1623 print "*************************************************************\n";
1624 print "Cannot find registry entry '$recommendedPlatformSDK'.\n";
1625 print "Please download and install the Microsoft Windows SDK\n";
1626 print "from <http://www.microsoft.com/en-us/download/details.aspx?id=8279>.\n\n";
1627 print "Then follow step 2 in the Windows section of the \"Installing Developer\n";
1628 print "Tools\" instructions at <http://www.webkit.org/building/tools.html>.\n";
1629 print "*************************************************************\n";
1633 sub buildXCodeProject($$@)
1635 my ($project, $clean, @extraOptions) = @_;
1638 push(@extraOptions, "-alltargets");
1639 push(@extraOptions, "clean");
1642 push(@extraOptions, ("-sdk", xcodeSDK())) if isIOSWebKit();
1644 chomp($ENV{DSYMUTIL_NUM_THREADS} = `sysctl -n hw.activecpu`);
1645 return system "xcodebuild", "-project", "$project.xcodeproj", @extraOptions;
1648 sub usingVisualStudioExpress()
1651 return $willUseVCExpressWhenBuilding;
1654 sub buildVisualStudioProject
1656 my ($project, $clean) = @_;
1659 my $config = configurationForVisualStudio();
1661 dieIfWindowsPlatformSDKNotInstalled() if $willUseVCExpressWhenBuilding;
1663 chomp($project = `cygpath -w "$project"`) if isCygwin();
1665 my $action = "/t:build";
1667 $action = "/t:clean";
1670 my $platform = "/p:Platform=" . (isWin64() ? "x64" : "Win32");
1671 my $logPath = File::Spec->catdir($baseProductDir, $configuration);
1672 make_path($logPath) unless -d $logPath or $logPath eq ".";
1674 my $errorLogFile = File::Spec->catfile($logPath, "webkit_errors.log");
1675 chomp($errorLogFile = `cygpath -w "$errorLogFile"`) if isCygwin();
1676 my $errorLogging = "/flp:LogFile=" . $errorLogFile . ";ErrorsOnly";
1678 my $warningLogFile = File::Spec->catfile($logPath, "webkit_warnings.log");
1679 chomp($warningLogFile = `cygpath -w "$warningLogFile"`) if isCygwin();
1680 my $warningLogging = "/flp1:LogFile=" . $warningLogFile . ";WarningsOnly";
1682 my @command = ($vcBuildPath, "/verbosity:minimal", $project, $action, $config, $platform, "/fl", $errorLogging, "/fl1", $warningLogging);
1684 print join(" ", @command), "\n";
1685 return system @command;
1688 sub getJhbuildPath()
1690 my @jhbuildPath = File::Spec->splitdir(baseProductDir());
1691 if (isGit() && isGitBranchBuild() && gitBranch()) {
1695 push(@jhbuildPath, "DependenciesEFL");
1697 push(@jhbuildPath, "DependenciesGTK");
1699 die "Cannot get JHBuild path for platform that isn't GTK+ or EFL.\n";
1701 return File::Spec->catdir(@jhbuildPath);
1704 sub isCachedArgumentfileOutOfDate($@)
1706 my ($filename, $currentContents) = @_;
1708 if (! -e $filename) {
1712 open(CONTENTS_FILE, $filename);
1713 chomp(my $previousContents = <CONTENTS_FILE>);
1714 close(CONTENTS_FILE);
1716 if ($previousContents ne $currentContents) {
1717 print "Contents for file $filename have changed.\n";
1718 print "Previous contents were: $previousContents\n\n";
1719 print "New contents are: $currentContents\n";
1726 sub jhbuildWrapperPrefixIfNeeded()
1728 if (-e getJhbuildPath()) {
1729 my @prefix = (File::Spec->catfile(sourceDir(), "Tools", "jhbuild", "jhbuild-wrapper"));
1731 push(@prefix, "--efl");
1733 push(@prefix, "--gtk");
1735 push(@prefix, "run");
1743 sub cmakeCachePath()
1745 return File::Spec->catdir(baseProductDir(), configuration(), "CMakeCache.txt");
1748 sub shouldRemoveCMakeCache(@)
1750 my ($cacheFilePath, @buildArgs) = @_;
1752 # We check this first, because we always want to create this file for a fresh build.
1753 my $productDir = File::Spec->catdir(baseProductDir(), configuration());
1754 my $optionsCache = File::Spec->catdir($productDir, "build-webkit-options.txt");
1755 my $joinedBuildArgs = join(" ", @buildArgs);
1756 if (isCachedArgumentfileOutOfDate($optionsCache, $joinedBuildArgs)) {
1757 File::Path::mkpath($productDir) unless -d $productDir;
1758 open(CACHED_ARGUMENTS, ">", $optionsCache);
1759 print CACHED_ARGUMENTS $joinedBuildArgs;
1760 close(CACHED_ARGUMENTS);
1765 my $cmakeCache = cmakeCachePath();
1766 unless (-e $cmakeCache) {
1770 my $cacheFileModifiedTime = stat($cmakeCache)->mtime;
1771 my $platformConfiguration = File::Spec->catdir(sourceDir(), "Source", "cmake", "Options" . cmakeBasedPortName() . ".cmake");
1772 if ($cacheFileModifiedTime < stat($platformConfiguration)->mtime) {
1776 my $globalConfiguration = File::Spec->catdir(sourceDir(), "Source", "cmake", "OptionsCommon.cmake");
1777 if ($cacheFileModifiedTime < stat($globalConfiguration)->mtime) {
1781 my $inspectorUserInterfaceDircetory = File::Spec->catdir(sourceDir(), "Source", "WebInspectorUI", "UserInterface");
1782 if ($cacheFileModifiedTime < stat($inspectorUserInterfaceDircetory)->mtime) {
1789 sub removeCMakeCache(@)
1791 my (@buildArgs) = @_;
1792 if (shouldRemoveCMakeCache(@buildArgs)) {
1793 my $cmakeCache = cmakeCachePath();
1794 unlink($cmakeCache) if -e $cmakeCache;
1800 # Test both ninja and ninja-build. Fedora uses ninja-build and has patched CMake to also call ninja-build.
1801 return commandExists("ninja") || commandExists("ninja-build");
1804 sub canUseEclipse(@)
1806 return commandExists("eclipse");
1809 sub cmakeGeneratedBuildfile(@)
1811 my ($willUseNinja) = @_;
1812 if ($willUseNinja) {
1813 return File::Spec->catfile(baseProductDir(), configuration(), "build.ninja")
1815 return File::Spec->catfile(baseProductDir(), configuration(), "Makefile")
1819 sub generateBuildSystemFromCMakeProject
1821 my ($port, $prefixPath, @cmakeArgs, $additionalCMakeArgs) = @_;
1822 my $config = configuration();
1823 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1824 File::Path::mkpath($buildPath) unless -d $buildPath;
1825 my $originalWorkingDirectory = getcwd();
1826 chdir($buildPath) or die;
1828 # We try to be smart about when to rerun cmake, so that we can have faster incremental builds.
1829 my $willUseNinja = canUseNinja();
1830 if (-e cmakeCachePath() && -e cmakeGeneratedBuildfile($willUseNinja)) {
1835 push @args, "-DPORT=\"$port\"";
1836 push @args, "-DCMAKE_INSTALL_PREFIX=\"$prefixPath\"" if $prefixPath;
1837 push @args, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" if isGtk();
1838 if ($config =~ /release/i) {
1839 push @args, "-DCMAKE_BUILD_TYPE=Release";
1840 } elsif ($config =~ /debug/i) {
1841 push @args, "-DCMAKE_BUILD_TYPE=Debug";
1844 if ($willUseNinja) {
1846 if (canUseEclipse()) {
1847 push @args, "'Eclipse CDT4 - Ninja'";
1849 push @args, "Ninja";
1853 # GTK+ has a production mode, but build-webkit should always use developer mode.
1854 push @args, "-DDEVELOPER_MODE=ON" if isEfl() || isGtk();
1856 # Don't warn variables which aren't used by cmake ports.
1857 push @args, "--no-warn-unused-cli";
1858 push @args, @cmakeArgs if @cmakeArgs;
1859 push @args, $additionalCMakeArgs if $additionalCMakeArgs;
1861 push @args, '"' . sourceDir() . '"';
1863 # Compiler options to keep floating point values consistent
1864 # between 32-bit and 64-bit architectures.
1865 determineArchitecture();
1866 if ($architecture ne "x86_64" && !isARM() && !isCrossCompilation()) {
1867 $ENV{'CXXFLAGS'} = "-march=pentium4 -msse2 -mfpmath=sse " . ($ENV{'CXXFLAGS'} || "");
1870 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1871 # parsed for shell metacharacters.
1872 my $wrapper = join(" ", jhbuildWrapperPrefixIfNeeded()) . " ";
1873 my $returnCode = system($wrapper . "cmake @args");
1875 chdir($originalWorkingDirectory);
1879 sub buildCMakeGeneratedProject($)
1881 my ($makeArgs) = @_;
1882 my $config = configuration();
1883 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1884 if (! -d $buildPath) {
1885 die "Must call generateBuildSystemFromCMakeProject() before building CMake project.";
1888 my $command = "cmake";
1889 my @args = ("--build", $buildPath, "--config", $config);
1890 push @args, ("--", $makeArgs) if $makeArgs;
1892 # GTK can use a build script to preserve colors and pretty-printing.
1893 if (isGtk() && -e "$buildPath/build.sh") {
1894 chdir "$buildPath" or die;
1895 $command = "$buildPath/build.sh";
1896 @args = ($makeArgs);
1899 if ($ENV{VERBOSE} && canUseNinja()) {
1901 push @args, "-d keeprsp" if (version->parse(determineNinjaVersion()) >= version->parse("1.4.0"));
1904 # We call system("cmake @args") instead of system("cmake", @args) so that @args is
1905 # parsed for shell metacharacters. In particular, $makeArgs may contain such metacharacters.
1906 my $wrapper = join(" ", jhbuildWrapperPrefixIfNeeded()) . " ";
1907 return system($wrapper . "$command @args");
1911 sub cleanCMakeGeneratedProject()
1913 my $config = configuration();
1914 my $buildPath = File::Spec->catdir(baseProductDir(), $config);
1915 if (-d $buildPath) {
1916 return system("cmake", "--build", $buildPath, "--config", $config, "--target", "clean");
1921 sub buildCMakeProjectOrExit($$$$@)
1923 my ($clean, $port, $prefixPath, $makeArgs, @cmakeArgs) = @_;
1926 exit(exitStatus(cleanCMakeGeneratedProject())) if $clean;
1928 if (isEfl() && checkForArgumentAndRemoveFromARGV("--update-efl")) {
1929 system("perl", "$sourceDir/Tools/Scripts/update-webkitefl-libs") == 0 or die $!;
1932 if (isGtk() && checkForArgumentAndRemoveFromARGV("--update-gtk")) {
1933 system("perl", "$sourceDir/Tools/Scripts/update-webkitgtk-libs") == 0 or die $!;
1936 $returnCode = exitStatus(generateBuildSystemFromCMakeProject($port, $prefixPath, @cmakeArgs));
1937 exit($returnCode) if $returnCode;
1939 $returnCode = exitStatus(buildCMakeGeneratedProject($makeArgs));
1940 exit($returnCode) if $returnCode;
1944 sub cmakeBasedPortArguments()
1949 sub cmakeBasedPortName()
1951 return "Efl" if isEfl();
1952 return "GTK" if isGtk();
1958 return isEfl() || isGtk();
1963 my ($prompt, $default) = @_;
1964 my $defaultValue = $default ? "[$default]" : "";
1965 print "$prompt $defaultValue: ";
1966 chomp(my $input = <STDIN>);
1967 return $input ? $input : $default;
1970 sub appleApplicationSupportPath
1972 open INSTALL_DIR, "</proc/registry/HKEY_LOCAL_MACHINE/SOFTWARE/Apple\ Inc./Apple\ Application\ Support/InstallDir";
1973 my $path = <INSTALL_DIR>;
1974 $path =~ s/[\r\n\x00].*//;
1977 my $unixPath = `cygpath -u '$path'`;
1982 sub setPathForRunningWebKitApp
1986 if (isAppleWinWebKit()) {
1987 $env->{PATH} = join(':', productDir(), appleApplicationSupportPath(), $env->{PATH} || "");
1988 } elsif (isWinCairo()) {
1989 my $winCairoBin = sourceDir() . "/WebKitLibraries/win/" . (isWin64() ? "bin64/" : "bin32/");
1990 my $gstreamerBin = isWin64() ? $ENV{"GSTREAMER_1_0_ROOT_X86_64"} . "bin" : $ENV{"GSTREAMER_1_0_ROOT_X86"} . "bin";
1991 $env->{PATH} = join(':', productDir(), $winCairoBin, $gstreamerBin, $env->{PATH} || "");
1995 sub printHelpAndExitForRunAndDebugWebKitAppIfNeeded
1997 return unless checkForArgumentAndRemoveFromARGV("--help");
1999 my ($includeOptionsForDebugging) = @_;
2002 Usage: @{[basename($0)]} [options] [args ...]
2003 --help Show this help message
2004 --no-saved-state Launch the application without state restoration (OS X 10.7 and later)
2005 -g|--guard-malloc Enable Guard Malloc (OS X only)
2006 --use-web-process-xpc-service Launch the Web Process as an XPC Service (OS X only)
2009 if ($includeOptionsForDebugging) {
2011 --target-web-process Debug the web process
2012 --use-gdb Use GDB (this is the default when using Xcode 4.4 or earlier)
2013 --use-lldb Use LLDB (this is the default when using Xcode 4.5 or later)
2020 sub argumentsForRunAndDebugMacWebKitApp()
2023 if (checkForArgumentAndRemoveFromARGV("--no-saved-state")) {
2024 push @args, ("-ApplePersistenceIgnoreStateQuietly", "YES");
2025 # FIXME: Don't set ApplePersistenceIgnoreState once all supported OS versions respect ApplePersistenceIgnoreStateQuietly (rdar://15032886).
2026 push @args, ("-ApplePersistenceIgnoreState", "YES");
2028 push @args, ("-WebKit2UseXPCServiceForWebProcess", "YES") if shouldUseXPCServiceForWebProcess();
2029 unshift @args, @ARGV;
2034 sub setupMacWebKitEnvironment($)
2036 my ($dyldFrameworkPath) = @_;
2038 $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
2040 $ENV{DYLD_FRAMEWORK_PATH} = $ENV{DYLD_FRAMEWORK_PATH} ? join(":", $dyldFrameworkPath, $ENV{DYLD_FRAMEWORK_PATH}) : $dyldFrameworkPath;
2041 $ENV{__XPC_DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
2042 $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
2044 setUpGuardMallocIfNeeded();
2047 sub setupIOSWebKitEnvironment($)
2049 my ($dyldFrameworkPath) = @_;
2050 $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
2052 $ENV{DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
2053 $ENV{DYLD_LIBRARY_PATH} = $dyldFrameworkPath;
2055 setUpGuardMallocIfNeeded();
2058 sub iosSimulatorApplicationsPath()
2060 return File::Spec->catdir(XcodeSDKPath(), "Applications");
2063 sub installedMobileSafariBundle()
2065 return File::Spec->catfile(iosSimulatorApplicationsPath(), "MobileSafari.app");
2068 sub mobileSafariBundle()
2070 determineConfigurationProductDir();
2072 # Use MobileSafari.app in product directory if present.
2073 if (isAppleMacWebKit() && -d "$configurationProductDir/MobileSafari.app") {
2074 return "$configurationProductDir/MobileSafari.app";
2076 return installedMobileSafariBundle();
2079 sub plistPathFromBundle($)
2081 my ($appBundle) = @_;
2082 return "$appBundle/Info.plist" if -f "$appBundle/Info.plist"; # iOS app bundle
2083 return "$appBundle/Contents/Info.plist" if -f "$appBundle/Contents/Info.plist"; # Mac app bundle
2087 sub appIdentifierFromBundle($)
2089 my ($appBundle) = @_;
2090 my $plistPath = File::Spec->rel2abs(plistPathFromBundle($appBundle)); # defaults(1) will complain if the specified path is not absolute.
2091 chomp(my $bundleIdentifier = `defaults read '$plistPath' CFBundleIdentifier 2> /dev/null`);
2092 return $bundleIdentifier;
2095 sub appDisplayNameFromBundle($)
2097 my ($appBundle) = @_;
2098 my $plistPath = File::Spec->rel2abs(plistPathFromBundle($appBundle)); # defaults(1) will complain if the specified path is not absolute.
2099 chomp(my $bundleDisplayName = `defaults read '$plistPath' CFBundleDisplayName 2> /dev/null`);
2100 return $bundleDisplayName;
2103 sub waitUntilIOSSimulatorDeviceIsInState($$)
2105 my ($deviceUDID, $waitUntilState) = @_;
2106 my $device = iosSimulatorDeviceByUDID($deviceUDID);
2107 while ($device->{state} ne $waitUntilState) {
2108 usleep(500 * 1000); # Waiting 500ms between file system polls does not make script run-safari feel sluggish.
2109 $device = iosSimulatorDeviceByUDID($deviceUDID);
2113 sub relaunchIOSSimulator($)
2115 my ($simulatedDevice) = @_;
2116 quitIOSSimulator($simulatedDevice->{UDID});
2118 # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator
2119 my $iosSimulatorBundleID = "com.apple.iphonesimulator";
2120 system("open", "-b", $iosSimulatorBundleID, "--args", "-CurrentDeviceUDID", $simulatedDevice->{UDID}) == 0 or die "Failed to open $iosSimulatorBundleID: $!";
2122 waitUntilIOSSimulatorDeviceIsInState($simulatedDevice->{UDID}, SIMULATOR_DEVICE_STATE_BOOTED);
2125 sub quitIOSSimulator(;$)
2127 my ($waitForShutdownOfSimulatedDeviceUDID) = @_;
2128 # FIXME: <rdar://problem/20916140> Switch to using CoreSimulator.framework for launching and quitting iOS Simulator
2129 exitStatus(system {"osascript"} "osascript", "-e", 'tell application id "com.apple.iphonesimulator" to quit') == 0 or die "Failed to quit iOS Simulator: $!";
2130 if (!defined($waitForShutdownOfSimulatedDeviceUDID)) {
2133 # FIXME: We assume that $waitForShutdownOfSimulatedDeviceUDID was not booted using the simctl command line tool.
2134 # Otherwise we will spin indefinitely since quiting the iOS Simulator will not shutdown this device. We
2135 # should add a maximum time limit to wait for a device to shutdown and either return an error or die()
2136 # on expiration of the time limit.
2137 waitUntilIOSSimulatorDeviceIsInState($waitForShutdownOfSimulatedDeviceUDID, SIMULATOR_DEVICE_STATE_SHUTDOWN);
2140 sub iosSimulatorDeviceByName($)
2142 my ($simulatorName) = @_;
2143 my $simulatorRuntime = iosSimulatorRuntime();
2144 my @devices = iOSSimulatorDevices();
2145 for my $device (@devices) {
2146 if ($device->{name} eq $simulatorName && $device->{runtime} eq $simulatorRuntime) {
2153 sub iosSimulatorDeviceByUDID($)
2155 my ($simulatedDeviceUDID) = @_;
2156 my $devicePlistPath = File::Spec->catfile(iOSSimulatorDevicesPath(), $simulatedDeviceUDID, "device.plist");
2157 if (!-f $devicePlistPath) {
2160 # FIXME: We should parse the device.plist file ourself and map the dictionary keys in it to known
2161 # dictionary keys so as to decouple our representation of the plist from the actual structure
2162 # of the plist, which may change.
2163 eval "require Foundation";
2164 return Foundation::perlRefFromObjectRef(NSDictionary->dictionaryWithContentsOfFile_($devicePlistPath));
2167 sub iosSimulatorRuntime()
2169 my $xcodeSDKVersion = xcodeSDKVersion();
2170 $xcodeSDKVersion =~ s/\./-/;
2171 return "com.apple.CoreSimulator.SimRuntime.iOS-$xcodeSDKVersion";
2174 sub findOrCreateSimulatorForIOSDevice($)
2176 my ($simulatorNameSuffix) = @_;
2178 my $simulatorDeviceType;
2179 if (architecture() eq "x86_64") {
2180 $simulatorName = "iPhone 5s " . $simulatorNameSuffix;
2181 $simulatorDeviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5s";
2183 $simulatorName = "iPhone 5 " . $simulatorNameSuffix;
2184 $simulatorDeviceType = "com.apple.CoreSimulator.SimDeviceType.iPhone-5";
2186 my $simulatedDevice = iosSimulatorDeviceByName($simulatorName);
2187 return $simulatedDevice if $simulatedDevice;
2188 return createiOSSimulatorDevice($simulatorName, $simulatorDeviceType, iosSimulatorRuntime());
2191 sub isIOSSimulatorSystemInstalledApp($)
2193 my ($appBundle) = @_;
2194 my $simulatorApplicationsPath = realpath(iosSimulatorApplicationsPath());
2195 return substr(realpath($appBundle), 0, length($simulatorApplicationsPath)) eq $simulatorApplicationsPath;
2198 sub hasUserInstalledAppInSimulatorDevice($$)
2200 my ($appIdentifier, $simulatedDeviceUDID) = @_;
2201 my $userInstalledAppPath = File::Spec->catfile($ENV{HOME}, "Library", "Developer", "CoreSimulator", "Devices", $simulatedDeviceUDID, "data", "Containers", "Bundle", "Application");
2202 if (!-d $userInstalledAppPath) {
2203 return 0; # No user installed apps.
2205 local @::userInstalledAppBundles;
2206 my $wantedFunction = sub {
2209 # Ignore hidden files and directories.
2210 if ($file =~ /^\../) {
2211 $File::Find::prune = 1;
2215 return if !-d $file || $file !~ /\.app$/;
2216 push @::userInstalledAppBundles, $File::Find::name;
2217 $File::Find::prune = 1; # Do not traverse contents of app bundle.
2219 find($wantedFunction, $userInstalledAppPath);
2220 for my $userInstalledAppBundle (@::userInstalledAppBundles) {
2221 if (appIdentifierFromBundle($userInstalledAppBundle) eq $appIdentifier) {
2222 return 1; # Has user installed app.
2225 return 0; # Does not have user installed app.
2228 sub isSimulatorDeviceBooted($)
2230 my ($simulatedDeviceUDID) = @_;
2231 my $device = iosSimulatorDeviceByUDID($simulatedDeviceUDID);
2232 return $device && $device->{state} eq SIMULATOR_DEVICE_STATE_BOOTED;
2235 sub runIOSWebKitAppInSimulator($;$)
2237 my ($appBundle, $simulatorOptions) = @_;
2238 my $productDir = productDir();
2239 my $appDisplayName = appDisplayNameFromBundle($appBundle);
2240 my $appIdentifier = appIdentifierFromBundle($appBundle);
2241 my $simulatedDevice = findOrCreateSimulatorForIOSDevice("For WebKit Development");
2242 my $simulatedDeviceUDID = $simulatedDevice->{UDID};
2244 my $willUseSystemInstalledApp = isIOSSimulatorSystemInstalledApp($appBundle);
2245 if ($willUseSystemInstalledApp) {
2246 if (hasUserInstalledAppInSimulatorDevice($appIdentifier, $simulatedDeviceUDID)) {
2247 # Restore the system-installed app in the simulator device corresponding to $appBundle as it
2248 # was previously overwritten with a custom built version of the app.
2249 # FIXME: Only restore the system-installed version of the app instead of erasing all contents and settings.
2250 print "Quitting iOS Simulator...\n";
2251 quitIOSSimulator($simulatedDeviceUDID);
2252 print "Erasing contents and settings for simulator device \"$simulatedDevice->{name}\".\n";
2253 exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "erase", $simulatedDeviceUDID)) == 0 or die;
2255 # FIXME: We assume that if $simulatedDeviceUDID is not booted then iOS Simulator is not open. However
2256 # $simulatedDeviceUDID may have been booted using the simctl command line tool. If $simulatedDeviceUDID
2257 # was booted using simctl then we should shutdown the device and launch iOS Simulator to boot it again.
2258 if (!isSimulatorDeviceBooted($simulatedDeviceUDID)) {
2259 print "Launching iOS Simulator...\n";
2260 relaunchIOSSimulator($simulatedDevice);
2263 # FIXME: We should killall(1) any running instances of $appBundle before installing it to ensure
2264 # that simctl launch opens the latest installed version of the app. For now we quit and
2265 # launch the iOS Simulator again to ensure there are no running instances of $appBundle.
2266 print "Quitting and launching iOS Simulator...\n";
2267 relaunchIOSSimulator($simulatedDevice);
2269 print "Installing $appBundle.\n";
2270 # Install custom built app, overwriting an app with the same app identifier if one exists.
2271 exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "install", $simulatedDeviceUDID, $appBundle)) == 0 or die;
2275 $simulatorOptions = {} unless $simulatorOptions;
2278 %simulatorENV = %{$simulatorOptions->{applicationEnvironment}} if $simulatorOptions->{applicationEnvironment};
2280 local %ENV; # Shadow global-scope %ENV so that changes to it will not be seen outside of this scope.
2281 setupIOSWebKitEnvironment($productDir);
2282 %simulatorENV = %ENV;
2284 my $applicationArguments = \@ARGV;
2285 $applicationArguments = $simulatorOptions->{applicationArguments} if $simulatorOptions && $simulatorOptions->{applicationArguments};
2287 # Prefix the environment variables with SIMCTL_CHILD_ per `xcrun simctl help launch`.
2288 foreach my $key (keys %simulatorENV) {
2289 $ENV{"SIMCTL_CHILD_$key"} = $simulatorENV{$key};
2292 print "Starting $appDisplayName with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2293 return exitStatus(system("xcrun", "--sdk", "iphonesimulator", "simctl", "launch", $simulatedDeviceUDID, $appIdentifier, @$applicationArguments));
2296 sub runIOSWebKitApp($)
2298 my ($appBundle) = @_;
2299 if (willUseIOSDeviceSDKWhenBuilding()) {
2300 die "Only running Safari in iOS Simulator is supported now.";
2302 if (willUseIOSSimulatorSDKWhenBuilding()) {
2303 return runIOSWebKitAppInSimulator($appBundle);
2305 die "Not using an iOS SDK."
2308 sub runMacWebKitApp($;$)
2310 my ($appPath, $useOpenCommand) = @_;
2311 my $productDir = productDir();
2312 print "Starting @{[basename($appPath)]} with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2315 setupMacWebKitEnvironment($productDir);
2317 if (defined($useOpenCommand) && $useOpenCommand == USE_OPEN_COMMAND) {
2318 return system("open", "-W", "-a", $appPath, "--args", argumentsForRunAndDebugMacWebKitApp());
2320 if (architecture()) {
2321 return system "arch", "-" . architecture(), $appPath, argumentsForRunAndDebugMacWebKitApp();
2323 return system { $appPath } $appPath, argumentsForRunAndDebugMacWebKitApp();
2326 sub execMacWebKitAppForDebugging($)
2329 my $architectureSwitch;
2330 my $argumentsSeparator;
2332 if (debugger() eq "lldb") {
2333 $architectureSwitch = "--arch";
2334 $argumentsSeparator = "--";
2335 } elsif (debugger() eq "gdb") {
2336 $architectureSwitch = "-arch";
2337 $argumentsSeparator = "--args";
2339 die "Unknown debugger $debugger.\n";
2342 my $debuggerPath = `xcrun -find $debugger`;
2343 chomp $debuggerPath;
2344 die "Can't find the $debugger executable.\n" unless -x $debuggerPath;
2346 my $productDir = productDir();
2347 setupMacWebKitEnvironment($productDir);
2349 my @architectureFlags = ($architectureSwitch, architecture());
2350 if (!shouldTargetWebProcess()) {
2351 print "Starting @{[basename($appPath)]} under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2352 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $appPath, argumentsForRunAndDebugMacWebKitApp() or die;
2354 if (shouldUseXPCServiceForWebProcess()) {
2355 die "Targeting the Web Process is not compatible with using an XPC Service for the Web Process at this time.";
2358 my $webProcessShimPath = File::Spec->catfile($productDir, "SecItemShim.dylib");
2359 my $webProcessPath = File::Spec->catdir($productDir, "WebProcess.app");
2360 my $webKit2ExecutablePath = File::Spec->catfile($productDir, "WebKit2.framework", "WebKit2");
2362 appendToEnvironmentVariableList("DYLD_INSERT_LIBRARIES", $webProcessShimPath);
2364 print "Starting WebProcess under $debugger with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
2365 exec { $debuggerPath } $debuggerPath, @architectureFlags, $argumentsSeparator, $webProcessPath, $webKit2ExecutablePath, "-type", "webprocess", "-client-executable", $appPath or die;
2371 if (isAppleMacWebKit()) {
2373 execMacWebKitAppForDebugging(safariPath());
2376 return 1; # Unsupported platform; can't debug Safari on this platform.
2381 if (isIOSWebKit()) {
2382 return runIOSWebKitApp(mobileSafariBundle());
2385 if (isAppleMacWebKit()) {
2386 return runMacWebKitApp(safariPath());
2389 if (isAppleWinWebKit()) {
2391 my $productDir = productDir();
2392 my $webKitLauncherPath = File::Spec->catfile(productDir(), "WinLauncher.exe");
2393 return system { $webKitLauncherPath } $webKitLauncherPath, @ARGV;
2396 return 1; # Unsupported platform; can't run Safari on this platform.
2401 if (isAppleMacWebKit()) {
2402 return runMacWebKitApp(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2408 sub debugMiniBrowser
2410 if (isAppleMacWebKit()) {
2411 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
2417 sub runWebKitTestRunner
2419 if (isAppleMacWebKit()) {
2420 return runMacWebKitApp(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2426 sub debugWebKitTestRunner
2428 if (isAppleMacWebKit()) {
2429 execMacWebKitAppForDebugging(File::Spec->catfile(productDir(), "WebKitTestRunner"));
2435 sub readRegistryString
2437 my ($valueName) = @_;
2438 chomp(my $string = `regtool --wow32 get "$valueName"`);
2442 sub writeRegistryString
2444 my ($valueName, $string) = @_;
2446 my $error = system "regtool", "--wow32", "set", "-s", $valueName, $string;
2448 # On Windows Vista/7 with UAC enabled, regtool will fail to modify the registry, but will still
2449 # return a successful exit code. So we double-check here that the value we tried to write to the
2450 # registry was really written.
2451 return !$error && readRegistryString($valueName) eq $string;
2454 sub formatBuildTime($)
2456 my ($buildTime) = @_;
2458 my $buildHours = int($buildTime / 3600);
2459 my $buildMins = int(($buildTime - $buildHours * 3600) / 60);
2460 my $buildSecs = $buildTime - $buildHours * 3600 - $buildMins * 60;
2463 return sprintf("%dh:%02dm:%02ds", $buildHours, $buildMins, $buildSecs);
2465 return sprintf("%02dm:%02ds", $buildMins, $buildSecs);
2468 sub runSvnUpdateAndResolveChangeLogs(@)
2470 my @svnOptions = @_;
2471 my $openCommand = "svn update " . join(" ", @svnOptions);
2472 open my $update, "$openCommand |" or die "cannot execute command $openCommand";
2473 my @conflictedChangeLogs;
2474 while (my $line = <$update>) {
2476 $line =~ m/^C\s+(.+?)[\r\n]*$/;
2478 my $filename = normalizePath($1);
2479 push @conflictedChangeLogs, $filename if basename($filename) eq "ChangeLog";
2482 close $update or die;
2484 if (@conflictedChangeLogs) {
2485 print "Attempting to merge conflicted ChangeLogs.\n";
2486 my $resolveChangeLogsPath = File::Spec->catfile(sourceDir(), "Tools", "Scripts", "resolve-ChangeLogs");
2487 (system($resolveChangeLogsPath, "--no-warnings", @conflictedChangeLogs) == 0)
2488 or die "Could not open resolve-ChangeLogs script: $!.\n";
2494 # Doing a git fetch first allows setups with svn-remote.svn.fetch = trunk:refs/remotes/origin/master
2495 # to perform the rebase much much faster.
2496 system("git", "fetch");
2497 if (isGitSVNDirectory(".")) {
2498 system("git", "svn", "rebase") == 0 or die;
2500 # This will die if branch.$BRANCHNAME.merge isn't set, which is
2501 # almost certainly what we want.
2502 system("git", "pull") == 0 or die;