[GTK] Add a helper function to find the current executable's path
authormrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Dec 2011 22:31:26 +0000 (22:31 +0000)
committermrobinson@webkit.org <mrobinson@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Dec 2011 22:31:26 +0000 (22:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=73473

Reviewed by Gustavo Noronha Silva.

Source/JavaScriptCore:

Add a WTF helper which gets the binary path. This is currently only used
in WebKit2.

* GNUmakefile.list.am: Add the new file to the source list.
* wtf/gobject/GlibUtilities.cpp: Added.
(getCurrentExecutablePath):
* wtf/gobject/GlibUtilities.h: Added.

Source/WebCore:

No new tests. This should not change behavior.

* platform/gtk/FileSystemGtk.cpp:
(WebCore::applicationDirectoryPath): Now use the new WTF function to get the
current executable's path.

Source/WebKit2:

Do a series of tests when looking for processes. First search the directory
specified by the environment variable, then the directory of the binary and
then the LIBEXECDIR.

* UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
(WebKit::findWebKitProcess): Added.
(WebKit::ProcessLauncher::launchProcess): Call the new helper to get the
binary location.

Tools:

Update MiniBrowser to not pass the binary directory as an environment variable.
This means that you can move the binaries around without it breaking.

* MiniBrowser/gtk/main.c:
(main): No longer set the environment variable.
* WebKitTestRunner/GNUmakefile.am: No longer add the directory path define.
* WebKitTestRunner/gtk/main.cpp:  Ditto.

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

12 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/GNUmakefile.list.am
Source/JavaScriptCore/wtf/gobject/GlibUtilities.cpp [new file with mode: 0644]
Source/JavaScriptCore/wtf/gobject/GlibUtilities.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/gtk/FileSystemGtk.cpp
Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp
Tools/ChangeLog
Tools/MiniBrowser/gtk/main.c
Tools/WebKitTestRunner/GNUmakefile.am
Tools/WebKitTestRunner/gtk/main.cpp

index 171a920..e0302f0 100644 (file)
@@ -1,3 +1,18 @@
+2011-12-01  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] Add a helper function to find the current executable's path
+        https://bugs.webkit.org/show_bug.cgi?id=73473
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Add a WTF helper which gets the binary path. This is currently only used
+        in WebKit2.
+
+        * GNUmakefile.list.am: Add the new file to the source list.
+        * wtf/gobject/GlibUtilities.cpp: Added.
+        (getCurrentExecutablePath):
+        * wtf/gobject/GlibUtilities.h: Added.
+
 2011-12-01  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r101691.
index a34c200..37e1778 100644 (file)
@@ -564,6 +564,8 @@ javascriptcore_sources += \
        Source/JavaScriptCore/wtf/gobject/GRefPtr.cpp \
        Source/JavaScriptCore/wtf/gobject/GRefPtr.h \
        Source/JavaScriptCore/wtf/gobject/GTypedefs.h \
+       Source/JavaScriptCore/wtf/gobject/GlibUtilities.cpp \
+       Source/JavaScriptCore/wtf/gobject/GlibUtilities.h \
        Source/JavaScriptCore/wtf/gtk/MainThreadGtk.cpp \
        Source/JavaScriptCore/wtf/HashCountedSet.h \
        Source/JavaScriptCore/wtf/HashFunctions.h \
diff --git a/Source/JavaScriptCore/wtf/gobject/GlibUtilities.cpp b/Source/JavaScriptCore/wtf/gobject/GlibUtilities.cpp
new file mode 100644 (file)
index 0000000..6fcd806
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 Igalia, S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "GlibUtilities.h"
+
+#include <limits.h>
+#include <unistd.h>
+
+#if OS(LINUX)
+CString getCurrentExecutablePath()
+{
+    static char readLinkBuffer[PATH_MAX];
+    ssize_t result = readlink("/proc/self/exe", readLinkBuffer, PATH_MAX);
+    if (result == -1)
+        return CString();
+    return CString(readLinkBuffer, result);
+}
+#elif OS(UNIX)
+CString getCurrentExecutablePath()
+{
+    static char readLinkBuffer[PATH_MAX];
+    ssize_t result = readlink("/proc/curproc/file", readLinkBuffer, PATH_MAX);
+    if (result == -1)
+        return CString();
+    return CString(readLinkBuffer, result);
+}
+#endif
diff --git a/Source/JavaScriptCore/wtf/gobject/GlibUtilities.h b/Source/JavaScriptCore/wtf/gobject/GlibUtilities.h
new file mode 100644 (file)
index 0000000..6f3ba6c
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright (C) 2010 Igalia, S.L.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Library General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Library General Public License
+ *  along with this library; see the file COPYING.LIB.  If not, write to
+ *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301, USA.
+ */
+
+#ifndef GlibUtilities_h
+#define GlibUtilities_h
+
+#include "CString.h"
+
+CString getCurrentExecutablePath();
+
+#endif
index b19c2d8..8e0bd61 100644 (file)
@@ -1,3 +1,16 @@
+2011-12-01  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] Add a helper function to find the current executable's path
+        https://bugs.webkit.org/show_bug.cgi?id=73473
+
+        Reviewed by Gustavo Noronha Silva.
+
+        No new tests. This should not change behavior.
+
+        * platform/gtk/FileSystemGtk.cpp:
+        (WebCore::applicationDirectoryPath): Now use the new WTF function to get the
+        current executable's path.
+
 2011-12-01  Andreas Kling  <kling@webkit.org>
 
         StyledElement: Clean up inline style accessors.
index ee709d4..fc9d4bf 100644 (file)
@@ -29,6 +29,7 @@
 #include <gio/gio.h>
 #include <glib.h>
 #include <glib/gstdio.h>
+#include <wtf/gobject/GlibUtilities.h>
 #include <wtf/gobject/GRefPtr.h>
 #include <wtf/text/CString.h>
 
@@ -176,15 +177,10 @@ String pathGetFileName(const String& pathName)
 
 CString applicationDirectoryPath()
 {
-#if OS(LINUX)
-    // Handle the /proc filesystem case.
-    char pathFromProc[PATH_MAX] = {0};
-    if (readlink("/proc/self/exe", pathFromProc, sizeof(pathFromProc) - 1) == -1)
-        return CString();
+    CString path = getCurrentExecutablePath();
+    if (!path.isNull())
+        return path;
 
-    GOwnPtr<char> dirname(g_path_get_dirname(pathFromProc));
-    return dirname.get();
-#elif OS(UNIX)
     // If the above fails, check the PATH env variable.
     GOwnPtr<char> currentExePath(g_find_program_in_path(g_get_prgname()));
     if (!currentExePath.get())
@@ -192,9 +188,6 @@ CString applicationDirectoryPath()
 
     GOwnPtr<char> dirname(g_path_get_dirname(currentExePath.get()));
     return dirname.get();
-#else
-    return CString();
-#endif
 }
 
 uint64_t getVolumeFreeSizeForPath(const char* path)
index 11a41de..5af9a14 100644 (file)
@@ -1,3 +1,19 @@
+2011-12-01  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] Add a helper function to find the current executable's path
+        https://bugs.webkit.org/show_bug.cgi?id=73473
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Do a series of tests when looking for processes. First search the directory
+        specified by the environment variable, then the directory of the binary and
+        then the LIBEXECDIR.
+
+        * UIProcess/Launcher/gtk/ProcessLauncherGtk.cpp:
+        (WebKit::findWebKitProcess): Added.
+        (WebKit::ProcessLauncher::launchProcess): Call the new helper to get the
+        binary location.
+
 2011-12-01  Viatcheslav Ostapenko  <ostapenko.viatcheslav@nokia.com>
 
         [Qt] [WK2] QQuickWebView covers QML elements that should be rendered on top.
index 1ffcba2..bbbae2e 100644 (file)
@@ -38,6 +38,7 @@
 #include <wtf/text/CString.h>
 #include <wtf/text/WTFString.h>
 #include <wtf/gobject/GOwnPtr.h>
+#include <wtf/gobject/GlibUtilities.h>
 
 #ifdef SOCK_SEQPACKET
 #define SOCKET_TYPE SOCK_SEQPACKET
@@ -71,6 +72,34 @@ static void childFinishedFunction(GPid, gint status, gpointer userData)
     close(GPOINTER_TO_INT(userData));
 }
 
+static CString findWebKitProcess(const char* processName)
+{
+    const char* execDirectory = g_getenv("WEBKIT_EXEC_PATH");
+    if (execDirectory) {
+        String processPath = pathByAppendingComponent(filenameToString(execDirectory), processName);
+        if (fileExists(processPath))
+            return fileSystemRepresentation(processPath);
+    }
+
+    static bool gotExecutablePath = false;
+    static String executablePath;
+    if (!gotExecutablePath) {
+        gotExecutablePath = true;
+
+        CString executableFile = getCurrentExecutablePath();
+        if (!executableFile.isNull())
+            executablePath = directoryName(filenameToString(executableFile.data()));
+    }
+
+    if (!executablePath.isNull()) {
+        String processPath = pathByAppendingComponent(executablePath, processName);
+        if (fileExists(processPath))
+            return fileSystemRepresentation(processPath);
+    }
+
+    return fileSystemRepresentation(pathByAppendingComponent(filenameToString(LIBEXECDIR), processName));
+}
+
 void ProcessLauncher::launchProcess()
 {
     GPid pid = 0;
@@ -82,12 +111,10 @@ void ProcessLauncher::launchProcess()
         return;
     }
 
-    const gchar* execDirectory = g_getenv("WEBKIT_EXEC_PATH");
-    GOwnPtr<gchar> binaryPath(g_build_filename(execDirectory ? execDirectory : LIBEXECDIR,
-                                               m_launchOptions.processType == ProcessLauncher::WebProcess ? gWebKitWebProcessName : gWebKitPluginProcessName, NULL));
+    CString binaryPath = findWebKitProcess(m_launchOptions.processType == ProcessLauncher::WebProcess ? gWebKitWebProcessName : gWebKitPluginProcessName);
     GOwnPtr<gchar> socket(g_strdup_printf("%d", sockets[0]));
     char* argv[3];
-    argv[0] = binaryPath.get();
+    argv[0] = const_cast<char*>(binaryPath.data());
     argv[1] = socket.get();
     argv[2] = 0;
 
index e05d98c..46fff6f 100644 (file)
@@ -1,3 +1,18 @@
+2011-12-01  Martin Robinson  <mrobinson@igalia.com>
+
+        [GTK] Add a helper function to find the current executable's path
+        https://bugs.webkit.org/show_bug.cgi?id=73473
+
+        Reviewed by Gustavo Noronha Silva.
+
+        Update MiniBrowser to not pass the binary directory as an environment variable.
+        This means that you can move the binaries around without it breaking.
+
+        * MiniBrowser/gtk/main.c:
+        (main): No longer set the environment variable.
+        * WebKitTestRunner/GNUmakefile.am: No longer add the directory path define.
+        * WebKitTestRunner/gtk/main.cpp:  Ditto.
+
 2011-12-01  Gustavo Noronha Silva  <gns@gnome.org>
 
         [GTK] Add freetype to our jhbuild setup
index 0c3f3f2..92dd1b0 100644 (file)
@@ -76,9 +76,6 @@ int main(int argc, char *argv[])
     }
     g_option_context_free (context);
 
-    // Prefer the not installed web and plugin processes.
-    g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
-
     if (uriArguments) {
         int i;
 
index 8ddce12..16ff328 100644 (file)
@@ -33,7 +33,6 @@ Programs_WebKitTestRunner_CPPFLAGS = \
        -I$(srcdir)/Tools/WebKitTestRunner \
        -I$(srcdir)/Source/WebCore/platform/gtk \
        -I$(top_builddir)/DerivedSources/WebKit2/include \
-       -DWEBKIT_EXEC_PATH=\"${shell pwd}/$(top_builddir)/Programs/\" \
        $(global_cppflags) \
        $(javascriptcore_cppflags) \
        $(GLOBALDEPS_CFLAGS) \
index 4ed8ffb..d53c624 100644 (file)
@@ -32,7 +32,6 @@ int main(int argc, char** argv)
 {
     gtk_init(&argc, &argv);
     // Prefer the not installed web and plugin processes.
-    g_setenv("WEBKIT_EXEC_PATH", WEBKIT_EXEC_PATH, FALSE);
     WTR::TestController controller(argc, const_cast<const char**>(argv));
     return 0;
 }