From 1e0dd9aa8c1652218eef2de4f6ed410fc792bae4 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Wed, 21 Feb 2024 18:11:45 -0700 Subject: [PATCH] Ladybird: Copy resources into the build directory This will let us remove the dependence on SERENITY_SOURCE_DIR --- Ladybird/CMakeLists.txt | 12 +- Ladybird/cmake/ResourceFiles.cmake | 165 ++++++++++++++++++++++ Meta/gn/secondary/Ladybird/BUILD.gn | 206 ++++++++++++++++++++++++---- 3 files changed, 352 insertions(+), 31 deletions(-) create mode 100644 Ladybird/cmake/ResourceFiles.cmake diff --git a/Ladybird/CMakeLists.txt b/Ladybird/CMakeLists.txt index d53c8b6895..004fc04ede 100644 --- a/Ladybird/CMakeLists.txt +++ b/Ladybird/CMakeLists.txt @@ -239,9 +239,8 @@ function(create_ladybird_bundle target_name) if (APPLE) set(bundle_dir "$") add_custom_command(TARGET ${target_name} POST_BUILD - COMMAND "mkdir" -p "${bundle_dir}/Contents/Resources" + COMMAND "${CMAKE_COMMAND}" -E make_directory "${bundle_dir}/Contents/Resources" COMMAND "iconutil" --convert icns "${SERENITY_SOURCE_DIR}/Ladybird/Icons/macos/app_icon.iconset" --output "${bundle_dir}/Contents/Resources/app_icon.icns" - COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${Lagom_BINARY_DIR}/cacert.pem" "${bundle_dir}/Contents" ) endif() endfunction() @@ -251,6 +250,13 @@ foreach(helper_process IN LISTS ladybird_helper_processes) set_ladybird_helper_output_directory(${helper_process}) endforeach() +include(cmake/ResourceFiles.cmake) +set(resource_base_dir "${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Lagom") +if (APPLE) + set(resource_base_dir "$/Contents/Resources") +endif() +copy_resources_to_build(${resource_base_dir} ladybird) + if(NOT CMAKE_SKIP_INSTALL_RULES) include(cmake/InstallRules.cmake) endif() @@ -259,7 +265,7 @@ include(CTest) if (BUILD_TESTING) add_test( NAME LibWeb - COMMAND ${CMAKE_CURRENT_BINARY_DIR}/../bin/headless-browser --resources "${SERENITY_SOURCE_DIR}/Base/res" --run-tests ${SERENITY_SOURCE_DIR}/Tests/LibWeb --dump-failed-ref-tests + COMMAND $ --resources "${resource_base_dir}" --run-tests ${SERENITY_SOURCE_DIR}/Tests/LibWeb --dump-failed-ref-tests ) add_test( NAME WPT diff --git a/Ladybird/cmake/ResourceFiles.cmake b/Ladybird/cmake/ResourceFiles.cmake new file mode 100644 index 0000000000..a13fff7edd --- /dev/null +++ b/Ladybird/cmake/ResourceFiles.cmake @@ -0,0 +1,165 @@ +set(FONTS + CsillaBold10.font + CsillaBold12.font + CsillaRegular10.font + CsillaRegular12.font + KaticaBold10.font + KaticaBold12.font + KaticaBoldOblique10.font + KaticaItalic10.font + KaticaRegular10.font + KaticaRegular12.font + SerenitySans-Regular.ttf +) +list(TRANSFORM FONTS PREPEND "${SERENITY_SOURCE_DIR}/Base/res/fonts/") + +set(16x16_ICONS + app-browser.png + audio-volume-high.png + audio-volume-muted.png + close-tab.png + edit-copy.png + filetype-css.png + filetype-folder-open.png + filetype-html.png + filetype-image.png + filetype-sound.png + filetype-video.png + find.png + go-forward.png + history.png + layers.png + layout.png + new-tab.png + open-parent-directory.png + pause.png + play.png + select-all.png + settings.png + spoof.png + trash-can.png + zoom-in.png + zoom-out.png + zoom-reset.png +) +set(32x32_ICONS + app-browser.png + filetype-folder.png + filetype-unknown.png + msgbox-warning.png +) +set(BROWSER_ICONS + clear-cache.png + cookie.png + dom-tree.png + local-storage.png +) +list(TRANSFORM 16x16_ICONS PREPEND "${SERENITY_SOURCE_DIR}/Base/res/icons/16x16/") +list(TRANSFORM 32x32_ICONS PREPEND "${SERENITY_SOURCE_DIR}/Base/res/icons/32x32/") +list(TRANSFORM BROWSER_ICONS PREPEND "${SERENITY_SOURCE_DIR}/Base/res/icons/browser/") + +set(WEB_RESOURCES + about.html + inspector.css + inspector.js + newtab.html +) +set(WEB_TEMPLATES + directory.html + error.html + version.html +) +list(TRANSFORM WEB_RESOURCES PREPEND "${SERENITY_SOURCE_DIR}/Base/res/ladybird/") +list(TRANSFORM WEB_TEMPLATES PREPEND "${SERENITY_SOURCE_DIR}/Base/res/ladybird/templates/") + +set(THEMES + Default.ini + Dark.ini +) +list(TRANSFORM THEMES PREPEND "${SERENITY_SOURCE_DIR}/Base/res/themes/") + +set(CONFIG_RESOURCES + BrowserAutoplayAllowlist.txt + BrowserContentFilters.txt +) +list(TRANSFORM CONFIG_RESOURCES PREPEND "${SERENITY_SOURCE_DIR}/Base/home/anon/.config/") + +set(DOWNLOADED_RESOURCES + cacert.pem +) +list(TRANSFORM DOWNLOADED_RESOURCES PREPEND "${Lagom_BINARY_DIR}/") + +function(copy_resource_set subdir) + cmake_parse_arguments(PARSE_ARGV 1 "COPY" "" "TARGET;DESTINATION" "RESOURCES") + set(inputs ${COPY_RESOURCES}) + + if (APPLE) + target_sources(${COPY_TARGET} PRIVATE ${inputs}) + set_source_files_properties(${inputs} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${subdir}") + else() + set(outputs "") + foreach (input IN LISTS inputs) + get_filename_component(input_name "${input}" NAME) + list(APPEND outputs "${COPY_DESTINATION}/${subdir}/${input_name}") + endforeach() + + add_custom_command( + OUTPUT ${outputs} + COMMAND "${CMAKE_COMMAND}" -E make_directory "${COPY_DESTINATION}/${subdir}" + COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${inputs}" "${COPY_DESTINATION}/${subdir}" + COMMAND_EXPAND_LISTS + VERBATIM + ) + string(REPLACE "/" "_" subdir_underscores "${subdir}") + set(target_name "copy_${subdir_underscores}_resources_to_build") + while (TARGET ${target_name}) + set(target_name "${target_name}_") + endwhile() + add_custom_target(${target_name} DEPENDS ${outputs}) + add_dependencies(all_generated ${target_name}) + add_dependencies("${COPY_TARGET}_build_resource_files" ${target_name}) + endif() +endfunction() + +function(copy_resources_to_build base_directory bundle_target) + + add_custom_target("${bundle_target}_build_resource_files") + + copy_resource_set(fonts RESOURCES ${FONTS} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(icons/16x16 RESOURCES ${16x16_ICONS} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(icons/32x32 RESOURCES ${32x32_ICONS} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(icons/browser RESOURCES ${BROWSER_ICONS} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(themes RESOURCES ${THEMES} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(ladybird RESOURCES ${WEB_RESOURCES} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(ladybird/templates RESOURCES ${WEB_TEMPLATES} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(ladybird RESOURCES ${CONFIG_RESOURCES} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + copy_resource_set(ladybird RESOURCES ${DOWNLOADED_RESOURCES} + DESTINATION ${base_directory} TARGET ${bundle_target} + ) + + add_dependencies(${bundle_target} "${bundle_target}_build_resource_files") +endfunction() diff --git a/Meta/gn/secondary/Ladybird/BUILD.gn b/Meta/gn/secondary/Ladybird/BUILD.gn index ddb465f113..17a0e88bd9 100644 --- a/Meta/gn/secondary/Ladybird/BUILD.gn +++ b/Meta/gn/secondary/Ladybird/BUILD.gn @@ -137,6 +137,19 @@ executable("ladybird_executable") { frameworks = [ "Cocoa.framework" ] } + if (current_os != "mac") { + data_deps += [ + ":ladybird_copy_config_resources", + ":ladybird_copy_fonts", + ":ladybird_copy_icons_16x16", + ":ladybird_copy_icons_32x32", + ":ladybird_copy_icons_browser", + ":ladybird_copy_themes", + ":ladybird_copy_web_resources", + ":ladybird_copy_web_templates", + ] + } + output_name = "Ladybird" } @@ -170,7 +183,132 @@ executable("headless-browser") { ] } -if (current_os == "mac") { +fonts = [ + "//Base/res/fonts/CsillaBold10.font", + "//Base/res/fonts/CsillaBold12.font", + "//Base/res/fonts/CsillaRegular10.font", + "//Base/res/fonts/CsillaRegular12.font", + "//Base/res/fonts/KaticaBold10.font", + "//Base/res/fonts/KaticaBold12.font", + "//Base/res/fonts/KaticaBoldOblique10.font", + "//Base/res/fonts/KaticaItalic10.font", + "//Base/res/fonts/KaticaRegular10.font", + "//Base/res/fonts/KaticaRegular12.font", + "//Base/res/fonts/SerenitySans-Regular.ttf", +] + +icons_16x16 = [ + "//Base/res/icons/16x16/app-browser.png", + "//Base/res/icons/16x16/audio-volume-high.png", + "//Base/res/icons/16x16/audio-volume-muted.png", + "//Base/res/icons/16x16/close-tab.png", + "//Base/res/icons/16x16/edit-copy.png", + "//Base/res/icons/16x16/filetype-css.png", + "//Base/res/icons/16x16/filetype-folder-open.png", + "//Base/res/icons/16x16/filetype-html.png", + "//Base/res/icons/16x16/filetype-image.png", + "//Base/res/icons/16x16/filetype-sound.png", + "//Base/res/icons/16x16/filetype-video.png", + "//Base/res/icons/16x16/find.png", + "//Base/res/icons/16x16/go-forward.png", + "//Base/res/icons/16x16/history.png", + "//Base/res/icons/16x16/layers.png", + "//Base/res/icons/16x16/layout.png", + "//Base/res/icons/16x16/new-tab.png", + "//Base/res/icons/16x16/open-parent-directory.png", + "//Base/res/icons/16x16/pause.png", + "//Base/res/icons/16x16/play.png", + "//Base/res/icons/16x16/select-all.png", + "//Base/res/icons/16x16/settings.png", + "//Base/res/icons/16x16/spoof.png", + "//Base/res/icons/16x16/trash-can.png", + "//Base/res/icons/16x16/zoom-in.png", + "//Base/res/icons/16x16/zoom-out.png", + "//Base/res/icons/16x16/zoom-reset.png", +] + +icons_32x32 = [ + "//Base/res/icons/32x32/app-browser.png", + "//Base/res/icons/32x32/filetype-folder.png", + "//Base/res/icons/32x32/filetype-unknown.png", + "//Base/res/icons/32x32/msgbox-warning.png", +] + +icons_browser = [ + "//Base/res/icons/browser/clear-cache.png", + "//Base/res/icons/browser/cookie.png", + "//Base/res/icons/browser/dom-tree.png", + "//Base/res/icons/browser/local-storage.png", +] + +themes = [ + "//Base/res/themes/Default.ini", + "//Base/res/themes/Dark.ini", +] + +web_resources = [ + "//Base/res/ladybird/about.html", + "//Base/res/ladybird/inspector.css", + "//Base/res/ladybird/inspector.js", + "//Base/res/ladybird/newtab.html", +] + +web_templates = [ + "//Base/res/ladybird/templates/directory.html", + "//Base/res/ladybird/templates/error.html", + "//Base/res/ladybird/templates/version.html", +] + +config_resources = [ + "$root_build_dir/cacert.pem", + "//Base/home/anon/.config/BrowserAutoplayAllowlist.txt", + "//Base/home/anon/.config/BrowserContentFilters.txt", +] + +if (current_os != "mac") { + copy("ladybird_copy_fonts") { + sources = fonts + outputs = [ "$root_out_dir/share/Lagom/fonts/{{source_file_part}}" ] + } + + copy("ladybird_copy_icons_16x16") { + sources = icons_16x16 + outputs = [ "$root_out_dir/share/Lagom/icons/16x16/{{source_file_part}}" ] + } + + copy("ladybird_copy_icons_32x32") { + sources = icons_32x32 + outputs = [ "$root_out_dir/share/Lagom/icons/32x32/{{source_file_part}}" ] + } + + copy("ladybird_copy_icons_browser") { + sources = icons_browser + outputs = [ "$root_out_dir/share/Lagom/icons/browser/{{source_file_part}}" ] + } + + copy("ladybird_copy_themes") { + sources = themes + outputs = [ "$root_out_dir/share/Lagom/themes/{{source_file_part}}" ] + } + + copy("ladybird_copy_web_resources") { + sources = web_resources + outputs = [ "$root_out_dir/share/Lagom/ladybird/{{source_file_part}}" ] + } + + copy("ladybird_copy_web_templates") { + sources = web_templates + outputs = + [ "$root_out_dir/share/Lagom/ladybird/templates/{{source_file_part}}" ] + } + + copy("ladybird_copy_config_resources") { + public_deps = [ "//Userland/Libraries/LibTLS:ca_certificates_download" ] + sources = config_resources + outputs = [ "$root_out_dir/share/Lagom/ladybird/{{source_file_part}}" ] + } +} else { + # macOS bundle steps bundle_data("ladybird_bundle_info_plist") { sources = [ "Info.plist" ] outputs = [ "{{bundle_contents_dir}}/Info.plist" ] @@ -284,39 +422,46 @@ if (current_os == "mac") { outputs = [ "{{bundle_contents_dir}}/lib/{{source_file_part}}" ] } - bundle_data("ladybird_resources") { - # FIXME: We should not be listing directories here because a change to a file inside any of these directories - # will not cause this action to be invoked. - sources = [ - "//Base/res/color-palettes", - "//Base/res/cursor-themes", - "//Base/res/fonts", - "//Base/res/icons", - "//Base/res/themes", - ] - outputs = [ "{{bundle_resources_dir}}/res/" + "{{source_file_part}}" ] + bundle_data("ladybird_fonts") { + sources = fonts + outputs = [ "{{bundle_resources_dir}}/fonts/{{source_file_part}}" ] + } + + bundle_data("ladybird_icons_16x16") { + sources = icons_16x16 + outputs = [ "{{bundle_resources_dir}}/icons/16x16/{{source_file_part}}" ] + } + + bundle_data("ladybird_icons_32x32") { + sources = icons_32x32 + outputs = [ "{{bundle_resources_dir}}/icons/32x32/{{source_file_part}}" ] + } + + bundle_data("ladybird_icons_browser") { + sources = icons_browser + outputs = [ "{{bundle_resources_dir}}/icons/browser/{{source_file_part}}" ] + } + + bundle_data("ladybird_themes") { + sources = themes + outputs = [ "{{bundle_resources_dir}}/themes/{{source_file_part}}" ] } bundle_data("ladybird_web_resources") { - sources = [ - "//Base/res/ladybird/about.html", - "//Base/res/ladybird/inspector.css", - "//Base/res/ladybird/inspector.js", - "//Base/res/ladybird/newtab.html", - "//Base/res/ladybird/templates/directory.html", - "//Base/res/ladybird/templates/error.html", - ] - outputs = [ "{{bundle_resources_dir}}/res/ladybird/{{source_file_part}}" ] + sources = web_resources + outputs = [ "{{bundle_resources_dir}}/ladybird/{{source_file_part}}" ] + } + + bundle_data("ladybird_web_templates") { + sources = web_templates + outputs = + [ "{{bundle_resources_dir}}/ladybird/templates/{{source_file_part}}" ] } bundle_data("ladybird_config_resources") { public_deps = [ "//Userland/Libraries/LibTLS:ca_certificates_download" ] - sources = [ - "$root_build_dir/cacert.pem", - "//Base/home/anon/.config/BrowserAutoplayAllowlist.txt", - "//Base/home/anon/.config/BrowserContentFilters.txt", - ] - outputs = [ "{{bundle_resources_dir}}/res/ladybird/{{source_file_part}}" ] + sources = config_resources + outputs = [ "{{bundle_resources_dir}}/ladybird/{{source_file_part}}" ] } action("ladybird_create_icon") { @@ -364,9 +509,14 @@ if (current_os == "mac") { ":ladybird_bundle_info_plist", ":ladybird_bundle_libs", ":ladybird_config_resources", + ":ladybird_fonts", ":ladybird_icon", - ":ladybird_resources", + ":ladybird_icons_16x16", + ":ladybird_icons_32x32", + ":ladybird_icons_browser", + ":ladybird_themes", ":ladybird_web_resources", + ":ladybird_web_templates", ] } }