From ea59bfaae7d3a307e0ba371518e7f36a33ae407d Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Fri, 23 Feb 2024 17:02:17 -0700 Subject: [PATCH] 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 --- Ladybird/CMakeLists.txt | 16 +++++--- Ladybird/Utilities.cpp | 39 ++++++++++++++++--- Ladybird/cmake/InstallRules.cmake | 9 ++++- Meta/gn/secondary/Ladybird/BUILD.gn | 1 + .../secondary/Ladybird/ImageDecoder/BUILD.gn | 1 + .../secondary/Ladybird/RequestServer/BUILD.gn | 1 + Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn | 1 + .../gn/secondary/Ladybird/WebContent/BUILD.gn | 1 + Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn | 1 + Meta/gn/secondary/Ladybird/WebSocket/BUILD.gn | 1 + Meta/gn/secondary/Ladybird/WebWorker/BUILD.gn | 1 + Tests/LibWeb/WPT/run.sh | 2 +- 12 files changed, 61 insertions(+), 13 deletions(-) diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt index 004fc04edea..d8df3f2331b 100644 --- a/Ladybird/CMakeLists.txt +++ b/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 "$") + set_target_properties(${targets} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "$") + 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") diff --git a/Ladybird/Utilities.cpp b/Ladybird/Utilities.cpp index eb78a414dd6..0b163d89905 100644 --- a/Ladybird/Utilities.cpp +++ b/Ladybird/Utilities.cpp @@ -12,6 +12,16 @@ #include #include +#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 application_directory() @@ -20,22 +30,34 @@ ErrorOr 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(MUST(String::from_byte_string(s_serenity_resource_root)))); } @@ -44,6 +66,11 @@ ErrorOr> get_paths_for_helper_process(StringView process_name auto application_path = TRY(application_directory()); Vector 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 diff --git a/Ladybird/cmake/InstallRules.cmake b/Ladybird/cmake/InstallRules.cmake index 35017f7071c..ab9614947c6 100644 --- a/Ladybird/cmake/InstallRules.cmake +++ b/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") diff --git a/Meta/gn/secondary/Ladybird/BUILD.gn b/Meta/gn/secondary/Ladybird/BUILD.gn index 17a0e88bd97..ac7a725d4cf 100644 --- a/Meta/gn/secondary/Ladybird/BUILD.gn +++ b/Meta/gn/secondary/Ladybird/BUILD.gn @@ -181,6 +181,7 @@ executable("headless-browser") { "HelperProcess.cpp", "Utilities.cpp", ] + output_dir = "$root_out_dir/libexec" } fonts = [ diff --git a/Meta/gn/secondary/Ladybird/ImageDecoder/BUILD.gn b/Meta/gn/secondary/Ladybird/ImageDecoder/BUILD.gn index efe9ea440c6..d3950261d3b 100644 --- a/Meta/gn/secondary/Ladybird/ImageDecoder/BUILD.gn +++ b/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" } diff --git a/Meta/gn/secondary/Ladybird/RequestServer/BUILD.gn b/Meta/gn/secondary/Ladybird/RequestServer/BUILD.gn index 86a0eac8f87..20b51bc9f19 100644 --- a/Meta/gn/secondary/Ladybird/RequestServer/BUILD.gn +++ b/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" } diff --git a/Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn b/Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn index 2c464bbaea5..05ab555508f 100644 --- a/Meta/gn/secondary/Ladybird/SQLServer/BUILD.gn +++ b/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" } diff --git a/Meta/gn/secondary/Ladybird/WebContent/BUILD.gn b/Meta/gn/secondary/Ladybird/WebContent/BUILD.gn index 810a3e31718..a42f5abaa6a 100644 --- a/Meta/gn/secondary/Ladybird/WebContent/BUILD.gn +++ b/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" } diff --git a/Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn b/Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn index 708d2b4551a..2b0ab853fe9 100644 --- a/Meta/gn/secondary/Ladybird/WebDriver/BUILD.gn +++ b/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" } diff --git a/Meta/gn/secondary/Ladybird/WebSocket/BUILD.gn b/Meta/gn/secondary/Ladybird/WebSocket/BUILD.gn index da599caf6c3..d2df881fb23 100644 --- a/Meta/gn/secondary/Ladybird/WebSocket/BUILD.gn +++ b/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" } diff --git a/Meta/gn/secondary/Ladybird/WebWorker/BUILD.gn b/Meta/gn/secondary/Ladybird/WebWorker/BUILD.gn index 2a97b94f622..bae40bb3fc4 100644 --- a/Meta/gn/secondary/Ladybird/WebWorker/BUILD.gn +++ b/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" } diff --git a/Tests/LibWeb/WPT/run.sh b/Tests/LibWeb/WPT/run.sh index ddcad99936e..6254da72ca4 100755 --- a/Tests/LibWeb/WPT/run.sh +++ b/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