浏览代码

Ladybird: Move helper processes to CMAKE_INSTALL_LIBEXECDIR

It aligns better with the Filesystem Heirarchy Standard[1] to put our
program-specific helper programs that are not intended to be executed by
the user of the application in $prefix/libexec or in whatever the
packager sets as the CMake equivalent. Namely, on Debian systems this
should be /usr/lib/Ladybird or similar.

[1] https://refspecs.linuxfoundation.org/FHS_3.0/fhs-3.0.html#usrlibexec
Andrew Kaster 1 年之前
父节点
当前提交
ea59bfaae7

+ 11 - 5
Ladybird/CMakeLists.txt

@@ -182,10 +182,18 @@ target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/)
 target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Applications/)
 target_include_directories(ladybird PRIVATE ${SERENITY_SOURCE_DIR}/Userland/Services/)
 
-function(set_ladybird_helper_output_directory target_name)
+function(set_helper_process_properties)
+    set(targets ${ARGV})
     if (APPLE)
         # Store helper processes in the same bundle directory as the main application
-        set_target_properties(${target_name} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:ladybird>")
+        set_target_properties(${targets} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$<TARGET_FILE_DIR:ladybird>")
+    else()
+        set_target_properties(${targets} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_LIBEXECDIR}")
+
+        if (NOT CMAKE_INSTALL_LIBEXECDIR STREQUAL "libexec")
+            set_source_files_properties(Utilities.cpp PROPERTIES COMPILE_DEFINITIONS LADYBIRD_LIBEXECDIR="${CMAKE_INSTALL_LIBEXECDIR}")
+            set_source_files_properties(Utilities.cpp TARGET_DIRECTORY ${targets} PROPERTIES COMPILE_DEFINITIONS LADYBIRD_LIBEXECDIR="${CMAKE_INSTALL_LIBEXECDIR}")
+        endif()
     endif()
 endfunction()
 
@@ -246,9 +254,7 @@ function(create_ladybird_bundle target_name)
 endfunction()
 
 create_ladybird_bundle(ladybird)
-foreach(helper_process IN LISTS ladybird_helper_processes)
-    set_ladybird_helper_output_directory(${helper_process})
-endforeach()
+set_helper_process_properties(${ladybird_helper_processes})
 
 include(cmake/ResourceFiles.cmake)
 set(resource_base_dir "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Lagom")

+ 33 - 6
Ladybird/Utilities.cpp

@@ -12,6 +12,16 @@
 #include <LibCore/System.h>
 #include <LibFileSystem/FileSystem.h>
 
+#define TOKENCAT(x, y) x##y
+#define STRINGIFY(x) TOKENCAT(x, sv)
+
+// This is expected to be set from the build scripts, if a packager desires
+#if defined(LADYBIRD_LIBEXECDIR)
+constexpr auto libexec_path = STRINGIFY(LADYBIRD_LIBEXECDIR);
+#else
+constexpr auto libexec_path = "libexec"sv;
+#endif
+
 ByteString s_serenity_resource_root;
 
 ErrorOr<ByteString> application_directory()
@@ -20,22 +30,34 @@ ErrorOr<ByteString> application_directory()
     return LexicalPath::dirname(current_executable_path);
 }
 
+[[gnu::used]] static LexicalPath find_prefix(LexicalPath const& application_directory);
+static LexicalPath find_prefix(LexicalPath const& application_directory)
+{
+    if (application_directory.string().ends_with(libexec_path)) {
+        // Strip libexec_path if it's there
+        return LexicalPath(application_directory.string().substring_view(0, application_directory.string().length() - libexec_path.length()));
+    }
+
+    // Otherwise, we are in $prefix/bin
+    return application_directory.parent();
+}
+
 void platform_init()
 {
     s_serenity_resource_root = [] {
         auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME");
-        VERIFY(home);
-        auto home_lagom = ByteString::formatted("{}/.lagom", home);
-        if (FileSystem::is_directory(home_lagom))
-            return home_lagom;
+        if (home != nullptr) {
+            auto home_lagom = ByteString::formatted("{}/.lagom", home);
+            if (FileSystem::is_directory(home_lagom))
+                return home_lagom;
+        }
         auto app_dir = MUST(application_directory());
 #ifdef AK_OS_MACOS
         return LexicalPath(app_dir).parent().append("Resources"sv).string();
 #else
-        return LexicalPath(app_dir).parent().append("share/Lagom"sv).string();
+        return find_prefix(LexicalPath(app_dir)).append("share/Lagom"sv).string();
 #endif
     }();
-
     Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::from_byte_string(s_serenity_resource_root))));
 }
 
@@ -44,6 +66,11 @@ ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name
     auto application_path = TRY(application_directory());
     Vector<ByteString> paths;
 
+#if !defined(AK_OS_MACOS)
+    auto prefix = find_prefix(LexicalPath(application_path));
+    TRY(paths.try_append(LexicalPath::join(prefix.string(), libexec_path, process_name).string()));
+    TRY(paths.try_append(LexicalPath::join(prefix.string(), "bin"sv, process_name).string()));
+#endif
     TRY(paths.try_append(ByteString::formatted("{}/{}", application_path, process_name)));
     TRY(paths.try_append(ByteString::formatted("./{}", process_name)));
     // NOTE: Add platform-specific paths here

+ 8 - 1
Ladybird/cmake/InstallRules.cmake

@@ -8,7 +8,7 @@ set(ladybird_applications ladybird ${ladybird_helper_processes})
 
 set(app_install_targets ${ladybird_applications})
 
-install(TARGETS ${app_install_targets}
+install(TARGETS ladybird
   EXPORT ladybirdTargets
   RUNTIME
     COMPONENT ladybird_Runtime
@@ -26,6 +26,13 @@ install(TARGETS ${app_install_targets}
     DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
 )
 
+install(TARGETS ${ladybird_helper_processes}
+  EXPORT ladybirdTargets
+  RUNTIME
+    COMPONENT ladybird_Runtime
+    DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}
+)
+
 include("${SERENITY_SOURCE_DIR}/Meta/Lagom/get_linked_lagom_libraries.cmake")
 foreach (application IN LISTS ladybird_applications)
   get_linked_lagom_libraries("${application}" "${application}_lagom_libraries")

+ 1 - 0
Meta/gn/secondary/Ladybird/BUILD.gn

@@ -181,6 +181,7 @@ executable("headless-browser") {
     "HelperProcess.cpp",
     "Utilities.cpp",
   ]
+  output_dir = "$root_out_dir/libexec"
 }
 
 fonts = [

+ 1 - 0
Meta/gn/secondary/Ladybird/ImageDecoder/BUILD.gn

@@ -16,4 +16,5 @@ executable("ImageDecoder") {
     "//Userland/Services/ImageDecoder/ConnectionFromClient.cpp",
     "main.cpp",
   ]
+  output_dir = "$root_out_dir/libexec"
 }

+ 1 - 0
Meta/gn/secondary/Ladybird/RequestServer/BUILD.gn

@@ -29,4 +29,5 @@ executable("RequestServer") {
     "//Userland/Services/RequestServer/Request.cpp",
     "main.cpp",
   ]
+  output_dir = "$root_out_dir/libexec"
 }

+ 1 - 0
Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn

@@ -17,4 +17,5 @@ executable("SQLServer") {
     "//Userland/Services/SQLServer/SQLStatement.cpp",
     "main.cpp",
   ]
+  output_dir = "$root_out_dir/libexec"
 }

+ 1 - 0
Meta/gn/secondary/Ladybird/WebContent/BUILD.gn

@@ -81,4 +81,5 @@ executable("WebContent") {
     cflags_cc = [ "-DHAS_ACCELERATED_GRAPHICS" ]
     deps += [ "//Userland/Libraries/LibAccelGfx" ]
   }
+  output_dir = "$root_out_dir/libexec"
 }

+ 1 - 0
Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn

@@ -27,4 +27,5 @@ executable("WebDriver") {
     "//Userland/Services/WebDriver/WebContentConnection.cpp",
     "main.cpp",
   ]
+  output_dir = "$root_out_dir/libexec"
 }

+ 1 - 0
Meta/gn/secondary/Ladybird/WebSocket/BUILD.gn

@@ -18,4 +18,5 @@ executable("WebSocket") {
     "//Userland/Services/WebSocket/ConnectionFromClient.cpp",
     "main.cpp",
   ]
+  output_dir = "$root_out_dir/libexec"
 }

+ 1 - 0
Meta/gn/secondary/Ladybird/WebWorker/BUILD.gn

@@ -28,4 +28,5 @@ executable("WebWorker") {
     "//Userland/Services/WebWorker/PageHost.cpp",
     "main.cpp",
   ]
+  output_dir = "$root_out_dir/libexec"
 }

+ 1 - 1
Tests/LibWeb/WPT/run.sh

@@ -11,7 +11,7 @@ then
 fi
 
 
-: "${WEBDRIVER_BINARY:=$(env PATH="${SERENITY_SOURCE_DIR}/Build/lagom/bin/Ladybird.app/Contents/MacOS:${SERENITY_SOURCE_DIR}/Build/lagom/bin:${SERENITY_SOURCE_DIR}/Meta/Lagom/Build/bin:${PATH}" \
+: "${WEBDRIVER_BINARY:=$(env PATH="${SERENITY_SOURCE_DIR}/Build/lagom/bin/Ladybird.app/Contents/MacOS:${SERENITY_SOURCE_DIR}/Build/lagom/libexec:${SERENITY_SOURCE_DIR}/Meta/Lagom/Build/libexec:${PATH}" \
                          which WebDriver)}"
 update_expectations_metadata=false