Simplify shim path computation
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 May 2015 22:31:33 +0000 (22:31 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 11 May 2015 22:31:33 +0000 (22:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144884
Part of rdar://problem/19708579.

Reviewed by Sam Weinig.

Factor the code that computes the shim path out into a separate function. Also make this mac only
since we don't have any shims on iOS.

* UIProcess/Launcher/mac/ProcessLauncherMac.mm:
(WebKit::computeProcessShimPath):
(WebKit::addDYLDEnvironmentAdditions):

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Launcher/mac/ProcessLauncherMac.mm

index f4da2d5d20c1269bd3bf0158353dfc3fad200640..f8a3f73e48839178cebd787aa3e0e36ac69cf6a0 100644 (file)
@@ -1,3 +1,18 @@
+2015-05-11  Anders Carlsson  <andersca@apple.com>
+
+        Simplify shim path computation
+        https://bugs.webkit.org/show_bug.cgi?id=144884
+        Part of rdar://problem/19708579.
+
+        Reviewed by Sam Weinig.
+
+        Factor the code that computes the shim path out into a separate function. Also make this mac only
+        since we don't have any shims on iOS.
+
+        * UIProcess/Launcher/mac/ProcessLauncherMac.mm:
+        (WebKit::computeProcessShimPath):
+        (WebKit::addDYLDEnvironmentAdditions):
+
 2015-05-11  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Unreviewed build fix
index d8e05664f3e81f1c46b2741e6068c20e7820d419..ace95c5337d20b2787ff60942c460dbc1e99a99b 100644 (file)
@@ -93,44 +93,52 @@ static const char* copyASanDynamicLibraryPath()
 }
 #endif
 
-static void addDYLDEnvironmentAdditions(const ProcessLauncher::LaunchOptions& launchOptions, bool isWebKitDevelopmentBuild, EnvironmentVariables& environmentVariables)
+#if PLATFORM(MAC)
+static RetainPtr<NSString> computeProcessShimPath(const ProcessLauncher::LaunchOptions& launchOptions, NSBundle *webKitBundle)
 {
-    DynamicLinkerEnvironmentExtractor environmentExtractor([[NSBundle mainBundle] executablePath], _NSGetMachExecuteHeader()->cputype);
-    environmentExtractor.getExtractedEnvironmentVariables(environmentVariables);
-
-    NSBundle *webKitBundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"];
-    NSString *frameworksPath = [[webKitBundle bundlePath] stringByDeletingLastPathComponent];
-
-    // To make engineering builds work, if the path is outside of /System set up
-    // DYLD_FRAMEWORK_PATH to pick up other frameworks, but don't do it for the
-    // production configuration because it involves extra file system access.
-    if (isWebKitDevelopmentBuild)
-        environmentVariables.appendValue("DYLD_FRAMEWORK_PATH", [frameworksPath fileSystemRepresentation], ':');
-
-    NSString *processShimPathNSString = nil;
 #if ENABLE(NETSCAPE_PLUGIN_API)
     if (launchOptions.processType == ProcessLauncher::PluginProcess) {
         NSString *processPath = [webKitBundle pathForAuxiliaryExecutable:@"PluginProcess.app"];
         NSString *processAppExecutablePath = [[NSBundle bundleWithPath:processPath] executablePath];
 
-        processShimPathNSString = [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"PluginProcessShim.dylib"];
-    } else
-#endif // ENABLE(NETSCAPE_PLUGIN_API)
+        return [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"PluginProcessShim.dylib"];
+    }
+#endif
+
 #if ENABLE(NETWORK_PROCESS)
     if (launchOptions.processType == ProcessLauncher::NetworkProcess) {
         NSString *processPath = [webKitBundle pathForAuxiliaryExecutable:@"NetworkProcess.app"];
         NSString *processAppExecutablePath = [[NSBundle bundleWithPath:processPath] executablePath];
 
-        processShimPathNSString = [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"SecItemShim.dylib"];
-    } else
-#endif // ENABLE(NETWORK_PROCESS)
+        return [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"SecItemShim.dylib"];
+    }
+#endif
+
     if (launchOptions.processType == ProcessLauncher::WebProcess) {
         NSString *processPath = [webKitBundle pathForAuxiliaryExecutable:@"WebProcess.app"];
         NSString *processAppExecutablePath = [[NSBundle bundleWithPath:processPath] executablePath];
 
-        processShimPathNSString = [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"WebProcessShim.dylib"];
+        return [[processAppExecutablePath stringByDeletingLastPathComponent] stringByAppendingPathComponent:@"WebProcessShim.dylib"];
     }
 
+    return nil;
+}
+#endif
+
+static void addDYLDEnvironmentAdditions(const ProcessLauncher::LaunchOptions& launchOptions, bool isWebKitDevelopmentBuild, EnvironmentVariables& environmentVariables)
+{
+    DynamicLinkerEnvironmentExtractor environmentExtractor([[NSBundle mainBundle] executablePath], _NSGetMachExecuteHeader()->cputype);
+    environmentExtractor.getExtractedEnvironmentVariables(environmentVariables);
+
+    NSBundle *webKitBundle = [NSBundle bundleWithIdentifier:@"com.apple.WebKit"];
+    NSString *frameworksPath = [[webKitBundle bundlePath] stringByDeletingLastPathComponent];
+
+    // To make engineering builds work, if the path is outside of /System set up
+    // DYLD_FRAMEWORK_PATH to pick up other frameworks, but don't do it for the
+    // production configuration because it involves extra file system access.
+    if (isWebKitDevelopmentBuild)
+        environmentVariables.appendValue("DYLD_FRAMEWORK_PATH", [frameworksPath fileSystemRepresentation], ':');
+
 #if ASAN_ENABLED
     static const char* asanLibraryPath = copyASanDynamicLibraryPath();
     ASSERT(asanLibraryPath); // ASan runtime library was not found in the current process. This code may need to be updated if the library name has changed.
@@ -139,14 +147,15 @@ static void addDYLDEnvironmentAdditions(const ProcessLauncher::LaunchOptions& la
         environmentVariables.appendValue("DYLD_INSERT_LIBRARIES", asanLibraryPath, ':');
 #endif
 
-    // Make sure that the shim library file exists and insert it.
-    if (processShimPathNSString) {
-        const char* processShimPath = [processShimPathNSString fileSystemRepresentation];
+#if PLATFORM(MAC)
+    if (auto shimPath = computeProcessShimPath(launchOptions, webKitBundle)) {
+        // Make sure that the shim library file exists and insert it.
+        const char* processShimPath = [shimPath fileSystemRepresentation];
         struct stat statBuf;
         if (stat(processShimPath, &statBuf) == 0 && (statBuf.st_mode & S_IFMT) == S_IFREG)
             environmentVariables.appendValue("DYLD_INSERT_LIBRARIES", processShimPath, ':');
     }
-
+#endif
 }
 
 typedef void (ProcessLauncher::*DidFinishLaunchingProcessFunction)(PlatformProcessIdentifier, IPC::Connection::Identifier);