Ladybird: Remove $SERENITY_SOURCE_DIR from resource root candidates

Now we will only load resources from $build/share/Lagom. On macOS, we
load from the bundle directory Contents/Resources instead. This
simplifies the commands and environment variables needed to execute
Ladybird from the build directory, and makes our install setup less
awkward for distributions and packagers.
This commit is contained in:
Andrew Kaster 2024-02-23 13:40:16 -07:00 committed by Andrew Kaster
parent 21ac431fac
commit 68402bec12
Notes: sideshowbarker 2024-07-17 03:59:29 +09:00
8 changed files with 38 additions and 80 deletions

View file

@ -23,14 +23,9 @@
// FIXME: Share b/w RequestServer and WebSocket
ErrorOr<ByteString> find_certificates(StringView serenity_resource_root)
{
auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent());
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
}
auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
return cert_path;
}

View file

@ -19,14 +19,9 @@
// FIXME: Share b/w RequestServer and WebSocket
ErrorOr<ByteString> find_certificates(StringView serenity_resource_root)
{
auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent());
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
}
auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
return cert_path;
}

View file

@ -23,14 +23,9 @@
// FIXME: Share b/w RequestServer and WebSocket
ErrorOr<ByteString> find_certificates(StringView serenity_resource_root)
{
auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent());
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
}
auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
return cert_path;
}

View file

@ -23,10 +23,6 @@ ErrorOr<ByteString> application_directory()
void platform_init()
{
s_serenity_resource_root = [] {
auto const* source_dir = getenv("SERENITY_SOURCE_DIR");
if (source_dir) {
return ByteString::formatted("{}/Base", source_dir);
}
auto* home = getenv("XDG_CONFIG_HOME") ?: getenv("HOME");
VERIFY(home);
auto home_lagom = ByteString::formatted("{}/.lagom", home);
@ -36,11 +32,11 @@ void platform_init()
#ifdef AK_OS_MACOS
return LexicalPath(app_dir).parent().append("Resources"sv).string();
#else
return LexicalPath(app_dir).parent().append("share"sv).string();
return LexicalPath(app_dir).parent().append("share/Lagom"sv).string();
#endif
}();
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::formatted("{}/res", s_serenity_resource_root))));
Core::ResourceImplementation::install(make<Core::ResourceImplementationFile>(MUST(String::from_byte_string(s_serenity_resource_root))));
}
ErrorOr<Vector<ByteString>> get_paths_for_helper_process(StringView process_name)

View file

@ -14,6 +14,7 @@
#include <LibCore/EventLoop.h>
#include <LibCore/LocalServer.h>
#include <LibCore/Process.h>
#include <LibCore/Resource.h>
#include <LibCore/System.h>
#include <LibCore/SystemServerTakeover.h>
#include <LibIPC/ConnectionFromClient.h>
@ -142,16 +143,11 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
static ErrorOr<void> load_content_filters()
{
auto file_or_error = Core::File::open(ByteString::formatted("{}/home/anon/.config/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
if (file_or_error.is_error())
file_or_error = Core::File::open(ByteString::formatted("{}/res/ladybird/BrowserContentFilters.txt", s_serenity_resource_root), Core::File::OpenMode::Read);
if (file_or_error.is_error())
return file_or_error.release_error();
auto file = file_or_error.release_value();
auto ad_filter_list = TRY(Core::InputBufferedFile::create(move(file)));
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/BrowserContentFilters.txt"sv));
auto ad_filter_list = TRY(InputBufferedSeekable<FixedMemoryStream>::create(make<FixedMemoryStream>(resource->data())));
Vector<String> patterns;
while (TRY(ad_filter_list->can_read_line())) {
@ -171,16 +167,11 @@ static ErrorOr<void> load_content_filters()
static ErrorOr<void> load_autoplay_allowlist()
{
auto file_or_error = Core::File::open(TRY(String::formatted("{}/home/anon/.config/BrowserAutoplayAllowlist.txt", s_serenity_resource_root)), Core::File::OpenMode::Read);
if (file_or_error.is_error())
file_or_error = Core::File::open(TRY(String::formatted("{}/res/ladybird/BrowserAutoplayAllowlist.txt", s_serenity_resource_root)), Core::File::OpenMode::Read);
if (file_or_error.is_error())
return file_or_error.release_error();
auto file = file_or_error.release_value();
auto allowlist = TRY(Core::InputBufferedFile::create(move(file)));
auto buffer = TRY(ByteBuffer::create_uninitialized(4096));
auto resource = TRY(Core::Resource::load_from_uri("resource://ladybird/BrowserAutoplayAllowlist.txt"sv));
auto allowlist = TRY(InputBufferedSeekable<FixedMemoryStream>::create(make<FixedMemoryStream>(resource->data())));
Vector<String> origins;
while (TRY(allowlist->can_read_line())) {

View file

@ -19,14 +19,9 @@
// FIXME: Share b/w RequestServer and WebSocket
ErrorOr<ByteString> find_certificates(StringView serenity_resource_root)
{
auto cert_path = ByteString::formatted("{}/res/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path)) {
auto app_dir = LexicalPath::dirname(TRY(Core::System::current_executable_path()));
cert_path = ByteString::formatted("{}/cacert.pem", LexicalPath(app_dir).parent());
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
}
auto cert_path = ByteString::formatted("{}/ladybird/cacert.pem", serenity_resource_root);
if (!FileSystem::exists(cert_path))
return Error::from_string_view("Don't know how to load certs!"sv);
return cert_path;
}

View file

@ -2,7 +2,7 @@
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
set(package ladybird)
set(package Ladybird)
set(ladybird_applications ladybird ${ladybird_helper_processes})
@ -94,42 +94,21 @@ install(
COMPONENT ladybird_Development
)
install(DIRECTORY
"${SERENITY_SOURCE_DIR}/Base/res/fonts"
"${SERENITY_SOURCE_DIR}/Base/res/icons"
"${SERENITY_SOURCE_DIR}/Base/res/ladybird"
"${SERENITY_SOURCE_DIR}/Base/res/themes"
"${SERENITY_SOURCE_DIR}/Base/res/color-palettes"
"${SERENITY_SOURCE_DIR}/Base/res/cursor-themes"
DESTINATION "${CMAKE_INSTALL_DATADIR}/res"
USE_SOURCE_PERMISSIONS MESSAGE_NEVER
COMPONENT ladybird_Runtime
)
install(FILES
"${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserAutoplayAllowlist.txt"
"${SERENITY_SOURCE_DIR}/Base/home/anon/.config/BrowserContentFilters.txt"
"${Lagom_BINARY_DIR}/cacert.pem"
DESTINATION "${CMAKE_INSTALL_DATADIR}/res/ladybird"
COMPONENT ladybird_Runtime
)
if (NOT APPLE)
# On macOS the resources are handled via the MACOSX_PACKAGE_LOCATION property on each resource file
install_ladybird_resources("${CMAKE_INSTALL_DATADIR}/Lagom" ladybird_Runtime)
endif()
if (APPLE)
# Fixup the app bundle and copy:
# - Libraries from lib/ to Ladybird.app/Contents/lib
# - Resources from share/res/ to Ladybird.app/Contents/Resources/res
install(CODE "
set(res_dir \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATADIR}/res)
if (IS_ABSOLUTE ${CMAKE_INSTALL_DATADIR})
set(res_dir ${CMAKE_INSTALL_DATADIR}/res)
endif()
set(lib_dir \${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
if (IS_ABSOLUTE ${CMAKE_INSTALL_LIBDIR})
set(lib_dir ${CMAKE_INSTALL_LIBDIR})
endif()
set(contents_dir \${CMAKE_INSTALL_PREFIX}/bundle/Ladybird.app/Contents)
file(COPY \${res_dir} DESTINATION \${contents_dir}/Resources)
file(COPY \${lib_dir} DESTINATION \${contents_dir})
"
COMPONENT ladybird_Runtime)

View file

@ -163,3 +163,15 @@ function(copy_resources_to_build base_directory bundle_target)
add_dependencies(${bundle_target} "${bundle_target}_build_resource_files")
endfunction()
function(install_ladybird_resources destination component)
install(FILES ${FONTS} DESTINATION "${destination}/fonts" COMPONENT ${component})
install(FILES ${16x16_ICONS} DESTINATION "${destination}/icons/16x16" COMPONENT ${component})
install(FILES ${32x32_ICONS} DESTINATION "${destination}/icons/32x32" COMPONENT ${component})
install(FILES ${BROWSER_ICONS} DESTINATION "${destination}/icons/browser" COMPONENT ${component})
install(FILES ${THEMES} DESTINATION "${destination}/themes" COMPONENT ${component})
install(FILES ${WEB_RESOURCES} DESTINATION "${destination}/ladybird" COMPONENT ${component})
install(FILES ${WEB_TEMPLATES} DESTINATION "${destination}/ladybird/templates" COMPONENT ${component})
install(FILES ${CONFIG_RESOURCES} DESTINATION "${destination}/ladybird" COMPONENT ${component})
install(FILES ${DOWNLOADED_RESOURCES} DESTINATION "${destination}/ladybird" COMPONENT ${component})
endfunction()