Skip to content

Commit

Permalink
Feedback WebUI: Use build_webui() GN rule.
Browse files Browse the repository at this point in the history
In order to support this case, modifying build_webui() to pass some
|static_files| through preprocess_if_expr().

Bug: 1340376
Change-Id: I763527c5d3e0ed2ad454f9bbea357a4fe3b088fb
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3803588
Auto-Submit: Demetrios Papadopoulos <dpapad@chromium.org>
Reviewed-by: Rebekah Potter <rbpotter@chromium.org>
Commit-Queue: Rebekah Potter <rbpotter@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1030877}
  • Loading branch information
freshp86 authored and Chromium LUCI CQ committed Aug 3, 2022
1 parent 04483eb commit 57fa789
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 145 deletions.
88 changes: 37 additions & 51 deletions chrome/browser/resources/feedback_webui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,50 @@
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//chrome/browser/resources/tools/build_webui.gni")
import("//chrome/common/features.gni")
import("//tools/grit/grit_rule.gni")
import("//ui/webui/resources/tools/generate_grd.gni")

assert(!is_android)

# Note: No need to pass these CSS files to preprocess_if_expr() for now.
css_files = [
"css/common.css",
"css/feedback.css",
"css/feedback_shared_styles.css",
"css/feedback_shared_vars.css",
"css/sys_info.css",
]

if (is_chromeos_ash) {
css_files += [ "css/assistant_logs_info.css" ]
}

icon_files = [
"images/button_butter_bar_close.png",
"images/button_butter_bar_close_hover.png",
"images/button_butter_bar_close_pressed.png",
"images/2x/button_butter_bar_close.png",
"images/2x/button_butter_bar_close_hover.png",
"images/2x/button_butter_bar_close_pressed.png",
]

grit("resources") {
defines = chrome_grit_defines

# These arguments are needed since the grd is generated at build time.
enable_input_discovery_for_gn_analyze = false
source = "$target_gen_dir/resources.grd"
deps = [ ":build_grd" ]

outputs = [
"grit/feedback_webui_resources.h",
"grit/feedback_webui_resources_map.cc",
"grit/feedback_webui_resources_map.h",
"feedback_webui_resources.pak",
]
output_dir = "$root_gen_dir/chrome"
}

generate_grd("build_grd") {
build_webui("build") {
grd_prefix = "feedback_webui"
out_grd = "$target_gen_dir/resources.grd"

input_files = css_files + icon_files
input_files_base_dir = rebase_path(".", "//")
static_files = [
"css/common.css",
"css/feedback.css",
"css/feedback_shared_styles.css",
"css/feedback_shared_vars.css",
"css/sys_info.css",
"html/default.html",
"html/sys_info.html",
"images/2x/button_butter_bar_close_hover.png",
"images/2x/button_butter_bar_close.png",
"images/2x/button_butter_bar_close_pressed.png",
"images/button_butter_bar_close_hover.png",
"images/button_butter_bar_close.png",
"images/button_butter_bar_close_pressed.png",
]

deps = [
"html:build_grdp",
"js:build_grdp",
if (is_chromeos_ash) {
static_files += [
"css/assistant_logs_info.css",
"html/assistant_logs_info.html",
"html/bluetooth_logs_info.html",
]
}

non_web_component_files = [
"js/feedback.ts",
"js/feedback_util.ts",
"js/questionnaire.ts",
"js/sys_info.ts",
"js/take_screenshot.ts",
]
grdp_files = [
"$target_gen_dir/js/resources.grdp",
"$target_gen_dir/html/resources.grdp",

ts_definitions = [
"//tools/typescript/definitions/feedback_private.d.ts",
"//tools/typescript/definitions/chrome_send.d.ts",
]
ts_deps = [ "//ui/webui/resources:library" ]
ts_use_local_config = false
}
37 changes: 0 additions & 37 deletions chrome/browser/resources/feedback_webui/html/BUILD.gn

This file was deleted.

48 changes: 0 additions & 48 deletions chrome/browser/resources/feedback_webui/js/BUILD.gn

This file was deleted.

42 changes: 36 additions & 6 deletions chrome/browser/resources/tools/build_webui.gni
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,16 @@ import("//tools/typescript/ts_library.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
import("../tools/optimize_webui.gni")

# See documentation at https://chromium.googlesource.com/chromium/src/+/HEAD/docs/webui_build_configuration.md#build_webui

template("build_webui") {
not_needed([ "target_name" ])

forward_variables_from(invoker, [ "grd_prefix" ])
forward_variables_from(invoker,
[
"grd_prefix",
"static_files",
])

preprocess_dir = "${target_gen_dir}/preprocessed"
tsc_dir = "${target_gen_dir}/tsc"
Expand Down Expand Up @@ -76,6 +82,17 @@ template("build_webui") {
}
}

# Compute which static_files should be preprocessed.
non_preprocessed_files_filter = [
"*.jpg",
"*.png",
"*.svg",
]
static_non_preprocessed_files =
filter_include(static_files, non_preprocessed_files_filter)
static_preprocessed_files =
filter_exclude(static_files, non_preprocessed_files_filter)

### Define the various targets that are required by the build pipeline.

# Specifically the order in which these targets are executed is:
Expand All @@ -87,6 +104,15 @@ template("build_webui") {
# 5) generate_grd()
# 6) grit()

preprocess_if_expr("preprocess_static_files") {
visibility = [ ":build_grd" ]
defines = chrome_grit_defines
in_folder = "."
out_folder = preprocess_dir
in_files = static_preprocessed_files
out_manifest = "${target_gen_dir}/preprocess_static_files_manifest.json"
}

preprocess_if_expr("preprocess") {
visibility = [
":build_ts",
Expand Down Expand Up @@ -230,16 +256,20 @@ template("build_webui") {
grd_prefix = grd_prefix
out_grd = "$target_gen_dir/resources.grd"

input_files = invoker.static_files
input_files = static_non_preprocessed_files
input_files_base_dir = rebase_path(".", "//")

deps = [ ":preprocess_static_files" ]
manifest_files =
[ "${target_gen_dir}/preprocess_static_files_manifest.json" ]

if (optimize) {
deps = [ ":build_bundle" ]
manifest_files = [ "$target_gen_dir/$bundle_manifest" ]
deps += [ ":build_bundle" ]
manifest_files += [ "$target_gen_dir/$bundle_manifest" ]
resource_path_rewrites = invoker.optimize_webui_resource_paths_rewrites
} else {
deps = [ ":build_ts" ]
manifest_files =
deps += [ ":build_ts" ]
manifest_files +=
filter_include(get_target_outputs(":build_ts"), [ "*.manifest" ])
}

Expand Down
Binary file modified docs/images/webui_build_pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 5 additions & 3 deletions docs/webui_build_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,11 @@ from other parts of the build.
```
List of files params:
static_files: List of HTML/CSS files that don't need any processing and will be
included in the build verbatim. Don't confuse with |css_files|
below. Required parameter.
static_files: Required parameter. List of
1) non Web Component HTML/CSS files (don't confuse with
|css_files| below). These are passed to preprocess_if_expr()
2) JPG/PNG/SVG files. These are included in the build verbatim
without any preprocessing.
web_component_files: List of TS files that hold Web Component definitions with
equivalent HTML template files. These can be either native
Expand Down

0 comments on commit 57fa789

Please sign in to comment.