[webui] Integrate generate_code_cache into build_webui
This CL integrates the generate_code_cache() webui build rule into build_webui to simplify integration of existing webui resources. The generate_code_cache optimize param is introduced to build_webui and will enable the generate_code_cache step provided optimize and minify configurations are specified. Further this will only apply in cases where the enable_webui_generate_code_cache webui_feature is true. If enabled and configured correctly a grdp rule is introduced by the build_webui template that can be used to aggregate the code cache resources into a single grd for integration into the resource bundle. This CL also demonstrates use of the build rule by integrating cr_elements into the //ui/webui/resources:code_cache_resources target. Bug: 378504039 Change-Id: Iab1a044201d45ac93d66478dbff39d0195894948 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6332418 Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org> Commit-Queue: Tom Lukaszewicz <tluk@chromium.org> Cr-Commit-Position: refs/heads/main@{#1430546}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
c6c712a9fd
commit
1dacb40969
docs/webui
tools/gritsettings
ui/webui
@ -594,9 +594,10 @@ Under the cover, build_webui() defines the following targets
|
||||
10. `merge_js_source_maps("merge_source_maps")`
|
||||
11. `bundle_js("build_bundle")`
|
||||
12. `minify_js("build_min_js")`
|
||||
13. `generate_grd("build_grd")`
|
||||
14. `generate_grd("build_grdp")`
|
||||
15. `grit("resources")`
|
||||
13. `generate_code_cache("build_code_cache")`
|
||||
14. `generate_grd("build_grd")`
|
||||
15. `generate_grd("build_grdp")`
|
||||
16. `grit("resources")`
|
||||
|
||||
Some targets are only conditionally defined based on `build_webui()` input
|
||||
parameters.
|
||||
@ -681,6 +682,10 @@ optimize_webui_excludes: See |excludes| in bundle_js(). Optional.
|
||||
optimize_webui_external_paths: See |external_paths| in optimize_webui().
|
||||
Optional.
|
||||
optimize_webui_in_files: See |in_files| in bundle_js().
|
||||
generate_code_cache: Specifies whether code cache resources should be generated
|
||||
for the minified files. Use
|
||||
`generate_code_cache = enable_webui_generate_code_cache` to
|
||||
opt-in.
|
||||
|
||||
Other params:
|
||||
webui_context_type: See |webui_context_type| in webui_path_mappings(). Optional,
|
||||
|
@ -1447,7 +1447,7 @@
|
||||
"includes": [9980],
|
||||
},
|
||||
"<(SHARED_INTERMEDIATE_DIR)/ui/webui/resources/webui_code_cache_resources.grd": {
|
||||
"META": {"sizes": {"includes": [10]}},
|
||||
"META": {"sizes": {"includes": [200]}},
|
||||
"includes": [9990],
|
||||
},
|
||||
"<(SHARED_INTERMEDIATE_DIR)/ui/webui/resources/webui_resources.grd": {
|
||||
|
@ -174,10 +174,15 @@ if (enable_webui_generate_code_cache) {
|
||||
generate_grd("build_code_cache_grd") {
|
||||
grd_prefix = "webui_code_cache"
|
||||
out_grd = "$target_gen_dir/${grd_prefix}_resources.grd"
|
||||
grdp_files =
|
||||
[ "$root_gen_dir/third_party/lit/v3_0/code_cache_resources.grdp" ]
|
||||
grdp_files = [
|
||||
"$root_gen_dir/third_party/lit/v3_0/code_cache_resources.grdp",
|
||||
"$target_gen_dir/cr_elements/code_cache_resources.grdp",
|
||||
]
|
||||
|
||||
public_deps = [ "//third_party/lit/v3_0:build_code_cache_grdp" ]
|
||||
public_deps = [
|
||||
"cr_elements:build_code_cache_grdp",
|
||||
"//third_party/lit/v3_0:build_code_cache_grdp",
|
||||
]
|
||||
}
|
||||
|
||||
grit("code_cache_resources") {
|
||||
|
@ -3,6 +3,7 @@
|
||||
# found in the LICENSE file.
|
||||
|
||||
import("//ui/webui/resources/tools/build_webui.gni")
|
||||
import("//ui/webui/webui_features.gni")
|
||||
|
||||
build_webui("build") {
|
||||
grd_prefix = "webui_cr_elements"
|
||||
@ -251,4 +252,5 @@ build_webui("build") {
|
||||
webui_context_type = "relative"
|
||||
generate_grdp = true
|
||||
grd_resource_path_prefix = rebase_path(".", "//ui/webui/resources")
|
||||
generate_code_cache = enable_webui_generate_code_cache
|
||||
}
|
||||
|
@ -16,6 +16,7 @@ import("//tools/typescript/webui_path_mappings.gni")
|
||||
import("//ui/webui/resources/tools/bundle_js.gni")
|
||||
import("//ui/webui/resources/tools/bundle_js_excludes.gni")
|
||||
import("//ui/webui/resources/tools/eslint_ts.gni")
|
||||
import("//ui/webui/resources/tools/generate_code_cache.gni")
|
||||
import("//ui/webui/resources/tools/generate_grd.gni")
|
||||
import("//ui/webui/resources/tools/minify_js.gni")
|
||||
import("//ui/webui/webui_features.gni")
|
||||
@ -80,6 +81,11 @@ template("build_webui") {
|
||||
generate_grd_target_name = "build_grdp"
|
||||
}
|
||||
|
||||
generate_code_cache = false
|
||||
if (defined(invoker.generate_code_cache)) {
|
||||
generate_code_cache = invoker.generate_code_cache
|
||||
}
|
||||
|
||||
### Compute the lists of files that are used across multiple targets.
|
||||
|
||||
# At least one of `web_component_files`, `css_files`, `mojo_files`, or
|
||||
@ -507,7 +513,10 @@ template("build_webui") {
|
||||
|
||||
if (minify) {
|
||||
minify_js("build_min_js") {
|
||||
visibility = [ ":$generate_grd_target_name" ]
|
||||
visibility = [
|
||||
":$generate_grd_target_name",
|
||||
":build_code_cache",
|
||||
]
|
||||
in_folder = ts_out_dir
|
||||
in_target = ":build_ts"
|
||||
if (bundle) {
|
||||
@ -526,6 +535,36 @@ template("build_webui") {
|
||||
}
|
||||
}
|
||||
|
||||
if (generate_code_cache) {
|
||||
generate_code_cache("build_code_cache") {
|
||||
visibility = [ ":build_code_cache_grdp" ]
|
||||
|
||||
# Rebase the minified file paths under the minified directory.
|
||||
minified_outputs =
|
||||
filter_include(get_target_outputs(":build_min_js"), [ "*.js" ])
|
||||
in_files = []
|
||||
foreach(minified_output, minified_outputs) {
|
||||
in_files += [ rebase_path(minified_output, "$target_gen_dir/minified") ]
|
||||
}
|
||||
|
||||
in_folder = "$target_gen_dir/minified"
|
||||
out_folder = "$target_gen_dir/code_cache"
|
||||
out_manifest = "$target_gen_dir/build_code_cache_manifest.json"
|
||||
|
||||
deps = [ ":build_min_js" ]
|
||||
}
|
||||
|
||||
generate_grd("build_code_cache_grdp") {
|
||||
if (defined(invoker.grd_resource_path_prefix)) {
|
||||
resource_path_prefix = invoker.grd_resource_path_prefix
|
||||
}
|
||||
grd_prefix = grd_prefix + "_code_cache"
|
||||
out_grd = "$target_gen_dir/code_cache_resources.grdp"
|
||||
manifest_files = [ "$target_gen_dir/build_code_cache_manifest.json" ]
|
||||
deps = [ ":build_code_cache" ]
|
||||
}
|
||||
}
|
||||
|
||||
generate_grd(generate_grd_target_name) {
|
||||
if (!generate_grdp) {
|
||||
visibility = [ ":resources_grit" ]
|
||||
|
@ -9,6 +9,7 @@ template("generate_code_cache") {
|
||||
forward_variables_from(invoker,
|
||||
[
|
||||
"deps",
|
||||
"visibility",
|
||||
"in_folder",
|
||||
"in_files",
|
||||
"out_folder",
|
||||
|
@ -27,14 +27,22 @@ declare_args() {
|
||||
# and build) with the runtime --load-webui-from-disk command line switch.
|
||||
load_webui_from_disk = false
|
||||
|
||||
# Enable generation of compiled JS bytecode for opted-in WebUI scripts. When
|
||||
# the host and current toolchains are the same there are issues instrumenting
|
||||
# the code_cache_generator msan binaries, see crbug.com/40055221#comment17.
|
||||
# TODO(crbug.com/399764218): Enable this build-step on cross-compiled builds.
|
||||
# This is necessary for universalized mac builds that produce x64 / arm64
|
||||
# chrome builds in the same package.
|
||||
# Enable generation of compiled JS bytecode for opted-in WebUI scripts for
|
||||
# compatible build configurations (see comment for the
|
||||
# `enable_webui_generate_code_cache` update below).
|
||||
enable_webui_generate_code_cache = false
|
||||
}
|
||||
|
||||
# Build-time WebUI code caching is only used in optimize_webui builds. When the
|
||||
# host and current toolchains are the same there are issues instrumenting the
|
||||
# code_cache_generator msan binaries, see crbug.com/40055221#comment17.
|
||||
# TODO(crbug.com/399764218): Enable this build-step on cross-compiled builds.
|
||||
# This is necessary for universalized mac builds that produce x64 / arm64 chrome
|
||||
# builds in the same package.
|
||||
if (enable_webui_generate_code_cache) {
|
||||
enable_webui_generate_code_cache =
|
||||
host_toolchain == current_toolchain && !is_msan && (is_linux || is_win)
|
||||
optimize_webui && host_toolchain == current_toolchain && !is_msan &&
|
||||
(is_linux || is_win)
|
||||
}
|
||||
|
||||
if (load_webui_from_disk) {
|
||||
|
Reference in New Issue
Block a user