Extract prependToEnvironmentVariableList
authorddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Nov 2015 16:43:22 +0000 (16:43 +0000)
committerddkilzer@apple.com <ddkilzer@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Nov 2015 16:43:22 +0000 (16:43 +0000)
<http://webkit.org/b/151536>

Reviewed by Daniel Bates.

Tests: webkitdirs_unittest/appendToEnvironmentVariableList.pl
       webkitdirs_unittest/prependToEnvironmentVariableList.pl

* Scripts/webkitdirs.pm: Export appendToEnvironmentVariableList
and prependToEnvironmentVariableList.
(appendToEnvironmentVariableList): Simplify variable name.
Switch to use $Config{path_sep}.
(prependToEnvironmentVariableList): Add new method.
(setupMacWebKitEnvironment): Switch to use
prependToEnvironmentVariableList().
(setupIOSWebKitEnvironment): Ditto.

* Scripts/webkitperl/webkitdirs_unittest/appendToEnvironmentVariableList.pl: Added.
* Scripts/webkitperl/webkitdirs_unittest/prependToEnvironmentVariableList.pl: Added.

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

Tools/ChangeLog
Tools/Scripts/webkitdirs.pm
Tools/Scripts/webkitperl/webkitdirs_unittest/appendToEnvironmentVariableList.pl [new file with mode: 0644]
Tools/Scripts/webkitperl/webkitdirs_unittest/prependToEnvironmentVariableList.pl [new file with mode: 0644]

index 8d95397..c920f0a 100644 (file)
@@ -1,3 +1,25 @@
+2015-11-26  David Kilzer  <ddkilzer@apple.com>
+
+        Extract prependToEnvironmentVariableList
+        <http://webkit.org/b/151536>
+
+        Reviewed by Daniel Bates.
+
+        Tests: webkitdirs_unittest/appendToEnvironmentVariableList.pl
+               webkitdirs_unittest/prependToEnvironmentVariableList.pl
+
+        * Scripts/webkitdirs.pm: Export appendToEnvironmentVariableList
+        and prependToEnvironmentVariableList.
+        (appendToEnvironmentVariableList): Simplify variable name.
+        Switch to use $Config{path_sep}.
+        (prependToEnvironmentVariableList): Add new method.
+        (setupMacWebKitEnvironment): Switch to use
+        prependToEnvironmentVariableList().
+        (setupIOSWebKitEnvironment): Ditto.
+
+        * Scripts/webkitperl/webkitdirs_unittest/appendToEnvironmentVariableList.pl: Added.
+        * Scripts/webkitperl/webkitdirs_unittest/prependToEnvironmentVariableList.pl: Added.
+
 2015-11-22  Andy Estes  <aestes@apple.com>
 
         Teach MiniBrowser how to enable the mock content filter
index 7e43ba3..706980c 100755 (executable)
@@ -58,6 +58,7 @@ BEGIN {
        &XcodeOptions
        &XcodeStaticAnalyzerOption
        &appDisplayNameFromBundle
+       &appendToEnvironmentVariableList
        &baseProductDir
        &chdirWebKit
        &checkFrameworks
@@ -70,6 +71,7 @@ BEGIN {
        &iosSimulatorDeviceByName
        &nmPath
        &passedConfiguration
+       &prependToEnvironmentVariableList
        &printHelpAndExitForRunAndDebugWebKitAppIfNeeded
        &productDir
        &quitIOSSimulator
@@ -1377,14 +1379,25 @@ sub determineDebugger
     }
 }
 
-sub appendToEnvironmentVariableList
+sub appendToEnvironmentVariableList($$)
 {
-    my ($environmentVariableName, $value) = @_;
+    my ($name, $value) = @_;
 
-    if (defined($ENV{$environmentVariableName})) {
-        $ENV{$environmentVariableName} .= ":" . $value;
+    if (defined($ENV{$name})) {
+        $ENV{$name} .= $Config{path_sep} . $value;
     } else {
-        $ENV{$environmentVariableName} = $value;
+        $ENV{$name} = $value;
+    }
+}
+
+sub prependToEnvironmentVariableList($$)
+{
+    my ($name, $value) = @_;
+
+    if (defined($ENV{$name})) {
+        $ENV{$name} = $value . $Config{path_sep} . $ENV{$name};
+    } else {
+        $ENV{$name} = $value;
     }
 }
 
@@ -2150,8 +2163,8 @@ sub setupMacWebKitEnvironment($)
 
     $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
 
-    $ENV{DYLD_FRAMEWORK_PATH} = $ENV{DYLD_FRAMEWORK_PATH} ? join(":", $dyldFrameworkPath, $ENV{DYLD_FRAMEWORK_PATH}) : $dyldFrameworkPath;
-    $ENV{__XPC_DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
+    prependToEnvironmentVariableList("DYLD_FRAMEWORK_PATH", $dyldFrameworkPath);
+    prependToEnvironmentVariableList("__XPC_DYLD_FRAMEWORK_PATH", $dyldFrameworkPath);
     $ENV{WEBKIT_UNSET_DYLD_FRAMEWORK_PATH} = "YES";
 
     setUpGuardMallocIfNeeded();
@@ -2162,8 +2175,8 @@ sub setupIOSWebKitEnvironment($)
     my ($dyldFrameworkPath) = @_;
     $dyldFrameworkPath = File::Spec->rel2abs($dyldFrameworkPath);
 
-    $ENV{DYLD_FRAMEWORK_PATH} = $dyldFrameworkPath;
-    $ENV{DYLD_LIBRARY_PATH} = $dyldFrameworkPath;
+    prependToEnvironmentVariableList("DYLD_FRAMEWORK_PATH", $dyldFrameworkPath);
+    prependToEnvironmentVariableList("DYLD_LIBRARY_PATH", $dyldFrameworkPath);
 
     setUpGuardMallocIfNeeded();
 }
diff --git a/Tools/Scripts/webkitperl/webkitdirs_unittest/appendToEnvironmentVariableList.pl b/Tools/Scripts/webkitperl/webkitdirs_unittest/appendToEnvironmentVariableList.pl
new file mode 100644 (file)
index 0000000..bbb412b
--- /dev/null
@@ -0,0 +1,102 @@
+#!/usr/bin/perl -w
+
+# Copyright (C) 2015 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Unit tests for webkitdirs::appendToEnvironmentVariableList($$).
+
+use strict;
+use warnings;
+
+use Config;
+use Test::More;
+use webkitdirs;
+
+my @testCases = (
+{
+    setup => sub { delete $ENV{DYLD_FRAMEWORK_PATH}; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => "/System/Library/PrivateFrameworks",
+    description => "Append to nonexistent variable",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = undef; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => "/System/Library/PrivateFrameworks",
+    description => "Append to undefined variable",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = ""; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "", "/System/Library/PrivateFrameworks"),
+    description => "Append to empty path",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = $Config{path_sep}; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "", "", "/System/Library/PrivateFrameworks"),
+    description => "Append to empty path with separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = "/System/Library/Frameworks"; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/Frameworks", "/System/Library/PrivateFrameworks"),
+    description => "Append to single path with no separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = "/System/Library/Frameworks" . $Config{path_sep}; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/Frameworks", "", "/System/Library/PrivateFrameworks"),
+    description => "Append to single path with separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = "/System/Library/Frameworks" . $Config{path_sep} . "/System/Library/PrivateFrameworks"; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/Frameworks", "/System/Library/PrivateFrameworks", "/System/Library/PrivateFrameworks"),
+    description => "Append to multiple, duplicate path with no separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = "/System/Library/Frameworks" . $Config{path_sep} . "/System/Library/PrivateFrameworks" . $Config{path_sep}; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/Frameworks", "/System/Library/PrivateFrameworks", "", "/System/Library/PrivateFrameworks"),
+    description => "Append to multiple, duplicate path with separator",
+},
+);
+
+plan(tests => 2 * @testCases);
+
+foreach my $testCase (@testCases) {
+    local %ENV;
+    $testCase->{setup}->();
+    my $result = appendToEnvironmentVariableList($testCase->{argName}, $testCase->{argValue});
+    is_deeply($result, $testCase->{expectedValue}, "appendToEnvironmentVariableList: $testCase->{description} - return result");
+    is_deeply($testCase->{expectedValue}, $ENV{$testCase->{argName}}, "appendToEnvironmentVariableList: $testCase->{description} - environment variable value");
+}
+
diff --git a/Tools/Scripts/webkitperl/webkitdirs_unittest/prependToEnvironmentVariableList.pl b/Tools/Scripts/webkitperl/webkitdirs_unittest/prependToEnvironmentVariableList.pl
new file mode 100644 (file)
index 0000000..d1cfa73
--- /dev/null
@@ -0,0 +1,102 @@
+#!/usr/bin/perl -w
+
+# Copyright (C) 2015 Apple Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1.  Redistributions of source code must retain the above copyright
+#     notice, this list of conditions and the following disclaimer.
+# 2.  Redistributions in binary form must reproduce the above copyright
+#     notice, this list of conditions and the following disclaimer in the
+#     documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
+# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+# DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+# Unit tests for webkitdirs::prependToEnvironmentVariableList($$).
+
+use strict;
+use warnings;
+
+use Config;
+use Test::More;
+use webkitdirs;
+
+my @testCases = (
+{
+    setup => sub { delete $ENV{DYLD_FRAMEWORK_PATH}; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => "/System/Library/PrivateFrameworks",
+    description => "Prepend to nonexistent variable",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = undef; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => "/System/Library/PrivateFrameworks",
+    description => "Prepend to undefined variable",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = ""; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/PrivateFrameworks", ""),
+    description => "Prepend to empty path",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = $Config{path_sep}; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/PrivateFrameworks", "", ""),
+    description => "Prepend to empty path with separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = "/System/Library/Frameworks"; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/PrivateFrameworks", "/System/Library/Frameworks"),
+    description => "Prepend to single path with no separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = $Config{path_sep} . "/System/Library/Frameworks"; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/PrivateFrameworks", "", "/System/Library/Frameworks"),
+    description => "Prepend to single path with separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = "/System/Library/Frameworks" . $Config{path_sep} . "/System/Library/PrivateFrameworks"; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/PrivateFrameworks", "/System/Library/Frameworks", "/System/Library/PrivateFrameworks"),
+    description => "Prepend to multiple, duplicate path with no separator",
+},
+{
+    setup => sub { $ENV{DYLD_FRAMEWORK_PATH} = $Config{path_sep} . "/System/Library/Frameworks" . $Config{path_sep} . "/System/Library/PrivateFrameworks"; },
+    argName => "DYLD_FRAMEWORK_PATH",
+    argValue => "/System/Library/PrivateFrameworks",
+    expectedValue => join($Config{path_sep}, "/System/Library/PrivateFrameworks", "", "/System/Library/Frameworks", "/System/Library/PrivateFrameworks"),
+    description => "Prepend to multiple, duplicate path with separator",
+},
+);
+
+plan(tests => 2 * @testCases);
+
+foreach my $testCase (@testCases) {
+    local %ENV;
+    $testCase->{setup}->();
+    my $result = prependToEnvironmentVariableList($testCase->{argName}, $testCase->{argValue});
+    is_deeply($result, $testCase->{expectedValue}, "prependToEnvironmentVariableList: $testCase->{description} - return result");
+    is_deeply($testCase->{expectedValue}, $ENV{$testCase->{argName}}, "prependToEnvironmentVariableList: $testCase->{description} - environment variable value");
+}
+