Cleanup: Extract code to launch a Mac WebKit application into a common function
authordbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Oct 2011 01:40:31 +0000 (01:40 +0000)
committerdbates@webkit.org <dbates@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 1 Oct 2011 01:40:31 +0000 (01:40 +0000)
https://bugs.webkit.org/show_bug.cgi?id=68662

Reviewed by Adam Roben.

Extracts common code to launch a WebKit application on Mac OS X into a function
so that we can remove duplicate code.

* Scripts/run-webkit-app: Modified to use webkitdirs::runMacWebKitApp().
* Scripts/webkitdirs.pm: Sorted @EXPORT list and added constant USE_OPEN_COMMAND.
(runMacWebKitApp): Added.
(runSafari): Modified to use webkitdirs::runMacWebKitApp().
(runMiniBrowser): Ditto.
(runWebKitTestRunner): Ditto.
(runTestWebKitAPI): Ditto.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96448 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/run-webkit-app
Tools/Scripts/webkitdirs.pm

index a926771..004c22c 100644 (file)
@@ -1,3 +1,21 @@
+2011-09-30  Daniel Bates  <dbates@rim.com>
+
+        Cleanup: Extract code to launch a Mac WebKit application into a common function
+        https://bugs.webkit.org/show_bug.cgi?id=68662
+
+        Reviewed by Adam Roben.
+
+        Extracts common code to launch a WebKit application on Mac OS X into a function
+        so that we can remove duplicate code.
+
+        * Scripts/run-webkit-app: Modified to use webkitdirs::runMacWebKitApp().
+        * Scripts/webkitdirs.pm: Sorted @EXPORT list and added constant USE_OPEN_COMMAND.
+        (runMacWebKitApp): Added.
+        (runSafari): Modified to use webkitdirs::runMacWebKitApp().
+        (runMiniBrowser): Ditto.
+        (runWebKitTestRunner): Ditto.
+        (runTestWebKitAPI): Ditto.
+
 2011-09-29  David Levin  <levin@chromium.org>
 
         watchlist: Add webkit-patch command to run watchlist.
index 452c44c..17a624b 100755 (executable)
@@ -34,17 +34,11 @@ use lib $FindBin::Bin;
 use webkitdirs;
 
 setConfiguration();
-my $productDir = productDir();
 
 die "Did not specify an application to open (e.g. run-webkit-app AppName).\n" unless length($ARGV[0]) > 0;
 
 # Check to see that all the frameworks are built.
 checkFrameworks();
 
-# Set up DYLD_FRAMEWORK_PATH to point to the product directory.
-print "Start $ARGV[0] with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
-$ENV{DYLD_FRAMEWORK_PATH} = $productDir;
-$ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
-
-unshift(@ARGV, "-a");
-exec "open", @ARGV;
+my $appPath = shift(@ARGV);
+exit exitStatus(runMacWebKitApp($appPath, USE_OPEN_COMMAND));
index 955addc..bf0c20b 100644 (file)
@@ -43,11 +43,27 @@ BEGIN {
    our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
    $VERSION     = 1.00;
    @ISA         = qw(Exporter);
-   @EXPORT      = qw(&chdirWebKit &baseProductDir &productDir &XcodeOptions &XcodeOptionString &XcodeOptionStringNoConfig &passedConfiguration &setConfiguration &safariPath &checkFrameworks &currentSVNRevision);
+   @EXPORT      = qw(
+       &XcodeOptionString
+       &XcodeOptionStringNoConfig
+       &XcodeOptions
+       &baseProductDir
+       &chdirWebKit
+       &checkFrameworks
+       &currentSVNRevision
+       &passedConfiguration
+       &productDir
+       &runMacWebKitApp
+       &safariPath
+       &setConfiguration
+       USE_OPEN_COMMAND
+   );
    %EXPORT_TAGS = ( );
    @EXPORT_OK   = ();
 }
 
+use constant USE_OPEN_COMMAND => 1; # Used in runMacWebKitApp().
+
 our @EXPORT_OK;
 
 my $architecture;
@@ -2000,22 +2016,31 @@ sub setPathForRunningWebKitApp
     }
 }
 
+sub runMacWebKitApp($;$)
+{
+    my ($appPath, $useOpenCommand) = @_;
+    my $productDir = productDir();
+    print "Starting @{[basename($appPath)]} with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
+    $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
+    $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
+    if ($useOpenCommand == USE_OPEN_COMMAND) {
+        return system("open", "-W", "-a", $appPath, "--args", @ARGV);
+    }
+    if (architecture()) {
+        return system "arch", "-" . architecture(), $appPath, @ARGV;
+    }
+    return system { $appPath } $appPath, @ARGV;
+}
+
 sub runSafari
 {
     my ($debugger) = @_;
 
     if (isAppleMacWebKit()) {
-        return system "$FindBin::Bin/gdb-safari", argumentsForConfiguration() if $debugger;
-
-        my $productDir = productDir();
-        print "Starting Safari with DYLD_FRAMEWORK_PATH set to point to built WebKit in $productDir.\n";
-        $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
-        $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
-        if (architecture()) {
-            return system "arch", "-" . architecture(), safariPath(), @ARGV;
-        } else {
-            return system safariPath(), @ARGV;
+        if ($debugger) {
+            return system "$FindBin::Bin/gdb-safari", argumentsForConfiguration();
         }
+        return runMacWebKitApp(safariPath());
     }
 
     if (isAppleWinWebKit()) {
@@ -2040,16 +2065,7 @@ sub runSafari
 sub runMiniBrowser
 {
     if (isAppleMacWebKit()) {
-        my $productDir = productDir();
-        print "Starting MiniBrowser with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
-        $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
-        $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
-        my $miniBrowserPath = "$productDir/MiniBrowser.app/Contents/MacOS/MiniBrowser";
-        if (architecture()) {
-            return system "arch", "-" . architecture(), $miniBrowserPath, @ARGV;
-        } else {
-            return system $miniBrowserPath, @ARGV;
-        }
+        return runMacWebKitApp(File::Spec->catfile(productDir(), "MiniBrowser.app", "Contents", "MacOS", "MiniBrowser"));
     }
 
     return 1;
@@ -2080,16 +2096,7 @@ sub debugMiniBrowser
 sub runWebKitTestRunner
 {
     if (isAppleMacWebKit()) {
-        my $productDir = productDir();
-        print "Starting WebKitTestRunner with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
-        $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
-        $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
-        my $webKitTestRunnerPath = "$productDir/WebKitTestRunner";
-        if (architecture()) {
-            return system "arch", "-" . architecture(), $webKitTestRunnerPath, @ARGV;
-        } else {
-            return system $webKitTestRunnerPath, @ARGV;
-        }
+        return runMacWebKitApp(File::Spec->catfile(productDir(), "WebKitTestRunner"));
     } elsif (isGtk()) {
         my $productDir = productDir();
         my $injectedBundlePath = "$productDir/Libraries/.libs/libTestRunnerInjectedBundle";
@@ -2126,16 +2133,7 @@ sub debugWebKitTestRunner
 sub runTestWebKitAPI
 {
     if (isAppleMacWebKit()) {
-        my $productDir = productDir();
-        print "Starting TestWebKitAPI with DYLD_FRAMEWORK_PATH set to point to $productDir.\n";
-        $ENV{DYLD_FRAMEWORK_PATH} = $productDir;
-        $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
-        my $testWebKitAPIPath = "$productDir/TestWebKitAPI";
-        if (architecture()) {
-            return system "arch", "-" . architecture(), $testWebKitAPIPath, @ARGV;
-        } else {
-            return system $testWebKitAPIPath, @ARGV;
-        }
+        return runMacWebKitApp(File::Spec->catfile(productDir(), "TestWebKitAPI"));
     }
 
     return 1;