1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 23:17:45 +00:00

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
This commit is contained in:
Andrew Kaster 2024-02-23 17:02:17 -07:00 committed by Andrew Kaster
parent c83e50af0b
commit ea59bfaae7
12 changed files with 61 additions and 13 deletions

View file

@ -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