Skip to content

Commit

Permalink
Revert "Bundle lit resources."
Browse files Browse the repository at this point in the history
This reverts commit 8e8c6a9.

Reason for revert:
LUCI Bisection identified this CL as the culprit of a build failure. See the analysis: https://luci-bisection.appspot.com/analysis/b/8790476004149770417

Sample failed build: https://ci.chromium.org/b/8790476004149770417

If this is a false positive, please report it at https://bugs.chromium.org/p/chromium/issues/entry?comment=Analysis%3A+https%3A%2F%2Fluci-bisection.appspot.com%2Fanalysis%2Fb%2F8790476004149770417&components=Tools%3ETest%3EFindit&labels=LUCI-Bisection-Wrong%2CPri-3%2CType-Bug&status=Available&summary=Wrongly+blamed+https%3A%2F%2Fchromium-review.googlesource.com%2Fc%2Fchromium%2Fsrc%2F%2B%2F4113089

Original change's description:
> Bundle lit resources.
>
> This cl:
> * Bundles lit into 1 file to export. This allows web ui to get full
>   lit functionality after 1 HTTP request instead of needing to perform
>   a dozen or more HTTP requests to fetch the full dependency tree.
> * Moves all lit files into ui/webui/resources/preprocessed/mwc so that
>   optimize_webui will, by default, handle chrome://resource imports
>   for lit files.
> * Deletes files_webui_bundle as optimize_webui will now correctly
>   handle lit without needing adjustments.
> * Updates rewrite_imports to accept regex so we can remap any
>   directive import with a single line.
>
> We also update our reproduce.sh script to no longer generate the BUILD
> file for third_party/material_web_components. Instead just output all
> discovered type definitions for a engineer to manually update.
>
> Bug: b/229804752
> Change-Id: I3c908244e724f31eb86eba98a444b8bc31156b28
> Cq-Include-Trybots: luci.chromium.try:linux-chromeos-rel;luci.chrome.try:linux-chromeos-chrome
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4113089
> Reviewed-by: Wenbo Jie <wenbojie@chromium.org>
> Commit-Queue: Zain Afzal <zafzal@google.com>
> Reviewed-by: Giovanni Ortuno Urquidi <ortuno@chromium.org>
> Cr-Commit-Position: refs/heads/main@{#1099099}
>

Bug: b/229804752
Change-Id: I0dd32c8be231e54549e85d1534005936201ef61d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4205772
Commit-Queue: luci-bisection@appspot.gserviceaccount.com <luci-bisection@appspot.gserviceaccount.com>
Bot-Commit: luci-bisection@appspot.gserviceaccount.com <luci-bisection@appspot.gserviceaccount.com>
Owners-Override: luci-bisection@appspot.gserviceaccount.com <luci-bisection@appspot.gserviceaccount.com>
Cr-Commit-Position: refs/heads/main@{#1099110}
  • Loading branch information
luci-bisection@appspot.gserviceaccount.com authored and Chromium LUCI CQ committed Jan 31, 2023
1 parent d180b6d commit 866ae15
Show file tree
Hide file tree
Showing 16 changed files with 1,200 additions and 102 deletions.
10 changes: 8 additions & 2 deletions ash/webui/file_manager/resources/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//chrome/browser/resources/tools/optimize_webui.gni")
import("//chrome/common/features.gni")
import("//third_party/closure_compiler/compile_js.gni")
import("//tools/grit/grit_rule.gni")
import("//tools/grit/preprocess_if_expr.gni")
import("//tools/typescript/ts_library.gni")
import("//ui/file_manager/base/gn/files_webui_bundle/files_webui_bundle.gni")
import("//ui/webui/resources/tools/generate_grd.gni")

assert(is_chromeos_ash)
Expand Down Expand Up @@ -127,7 +127,7 @@ if (!optimize_webui) {
}
}

optimize_webui("build") {
files_webui_bundle("build") {
host = "file-manager"
input = rebase_path(preprocess_folder, root_build_dir)

Expand All @@ -136,6 +136,12 @@ optimize_webui("build") {
"runtime_loaded_test_util_swa.js",
]

js_out_files = [
"main.rollup.js",
"runtime_loaded_test_util_swa.rollup.js",
"shared.rollup.js",
]

excludes = [
"chrome://resources/ash/common/load_time_data.m.js",
"chrome://resources/mojo/mojo/public/js/bindings.js",
Expand Down
4 changes: 1 addition & 3 deletions ash/webui/tools/ash_ts_library.gni
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,8 @@ template("ash_ts_library") {
forward_variables_from(invoker, [ "testonly" ])

import_mappings = [
# All lit code is bundled into 1 file, the below mappings simply rewrite
# any import to lit or a lit sub package to point at the bundle.
"lit|//resources/mwc/lit/index.js",
"lit/.*|//resources/mwc/lit/index.js",
"lit/decorators|//resources/mwc/lit/decorators.js",
]

deps = [
Expand Down
147 changes: 109 additions & 38 deletions third_party/material_web_components/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,125 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//chrome/browser/resources/tools/optimize_webui.gni")
import("//tools/typescript/ts_library.gni")
import("//ui/webui/resources/tools/generate_grd.gni")

# Optimize webui assumes that all resources hosted on chrome://resources are
# in this directory and does not provide a way to override this assumption. To
# prevent downstream optimize_webui calls from breaking we output all of our
# files into the same path.
chrome_resources_dir = "${root_gen_dir}/ui/webui/resources/tsc/mwc"

# Compile lit_exports.js into a singular bundle we can host on
# chrome://resources.
optimize_webui("bundle_lit") {
host = "resources"
input = rebase_path("//third_party/material_web_components/", root_build_dir)
js_module_in_files = [ "lit_exports.js" ]

deps = []
}

copy("copy_tslib") {
sources = [ rebase_path(
"//third_party/material_web_components/components-chromium/node_modules/tslib/tslib.js",
root_build_dir) ]
outputs = [ "$chrome_resources_dir/tslib/tslib.js" ]
}

copy("copy_lit_bundle") {
sources = [ "$target_gen_dir/lit_exports.rollup.js" ]
outputs = [ "$chrome_resources_dir/lit/index.js" ]
deps = [ ":bundle_lit" ]
}

generate_grd("build_grdp") {
grd_prefix = "material_web_components"
out_grd = "$target_gen_dir/${grd_prefix}_resources.grdp"
input_files_base_dir = rebase_path(chrome_resources_dir, root_build_dir)
resource_path_prefix = "mwc"
out_grd = "${target_gen_dir}/${grd_prefix}_resources.grdp"

# TODO(b/229804752): Clean up and find the minimal set of necessary resources.
input_files = [
"tslib/tslib.js",
"lit-element/decorators.js",
"lit-element/index.js",
"lit-element/lit-element.js",
"@lit/reactive-element/reactive-controller.js",
"@lit/reactive-element/decorators.js",
"@lit/reactive-element/decorators/state.js",
"@lit/reactive-element/decorators/query-async.js",
"@lit/reactive-element/decorators/event-options.js",
"@lit/reactive-element/decorators/query-assigned-elements.js",
"@lit/reactive-element/decorators/query.js",
"@lit/reactive-element/decorators/custom-element.js",
"@lit/reactive-element/decorators/query-assigned-nodes.js",
"@lit/reactive-element/decorators/base.js",
"@lit/reactive-element/decorators/query-all.js",
"@lit/reactive-element/decorators/property.js",
"@lit/reactive-element/reactive-element.js",
"@lit/reactive-element/css-tag.js",
"lit/directives/template-content.js",
"lit/directives/choose.js",
"lit/directives/when.js",
"lit/directives/live.js",
"lit/directives/if-defined.js",
"lit/directives/unsafe-svg.js",
"lit/directives/async-append.js",
"lit/directives/until.js",
"lit/directives/class-map.js",
"lit/directives/ref.js",
"lit/directives/async-replace.js",
"lit/directives/repeat.js",
"lit/directives/range.js",
"lit/directives/map.js",
"lit/directives/join.js",
"lit/directives/keyed.js",
"lit/directives/guard.js",
"lit/directives/style-map.js",
"lit/directives/unsafe-html.js",
"lit/directives/cache.js",
"lit/directive-helpers.js",
"lit/decorators.js",
"lit/directive.js",
"lit/static-html.js",
"lit/index.js",
"lit/async-directive.js",
"lit/html.js",
"tslib/tslib.js",
"lit-html/lit-html.js",
"lit-html/directives/template-content.js",
"lit-html/directives/choose.js",
"lit-html/directives/when.js",
"lit-html/directives/live.js",
"lit-html/directives/if-defined.js",
"lit-html/directives/unsafe-svg.js",
"lit-html/directives/async-append.js",
"lit-html/directives/until.js",
"lit-html/directives/class-map.js",
"lit-html/directives/ref.js",
"lit-html/directives/async-replace.js",
"lit-html/directives/repeat.js",
"lit-html/directives/range.js",
"lit-html/directives/map.js",
"lit-html/directives/join.js",
"lit-html/directives/keyed.js",
"lit-html/directives/guard.js",
"lit-html/directives/style-map.js",
"lit-html/directives/unsafe-html.js",
"lit-html/directives/cache.js",
"lit-html/directives/private-async-helpers.js",
"lit-html/directive-helpers.js",
"lit-html/static.js",
"lit-html/directive.js",
"lit-html/async-directive.js",
"@material/base/observer-proxy.js",
"@material/base/observer-foundation.js",
"@material/base/observer.js",
"@material/base/index.js",
"@material/base/component.js",
"@material/base/types.js",
"@material/base/foundation.js",
"@material/mwc-base/base-element.js",
"@material/mwc-base/form-element.js",
"@material/mwc-base/utils.js",
"@material/mwc-base/observer.js",
"@material/mwc-base/aria-property.js",
"@material/ripple/constants.js",
"@material/ripple/index.js",
"@material/ripple/adapter.js",
"@material/ripple/util.js",
"@material/ripple/component.js",
"@material/ripple/types.js",
"@material/ripple/foundation.js",
"@material/mwc-button/demo_styles.css.js",
"@material/mwc-button/mwc-button.js",
"@material/mwc-button/styles.css.js",
"@material/mwc-button/mwc-button-base.js",
"@material/dom/focus-trap.js",
"@material/dom/keyboard.js",
"@material/dom/ponyfill.js",
"@material/dom/index.js",
"@material/dom/announce.js",
"@material/dom/events.js",
"@material/mwc-ripple/mwc-ripple.js",
"@material/mwc-ripple/mwc-ripple.css.js",
"@material/mwc-ripple/ripple-handlers.js",
"@material/mwc-ripple/mwc-ripple-base.js",
"@material/mwc-icon/mwc-icon-host.css.js",
"@material/mwc-icon/mwc-icon.js",
]

deps = [
":copy_lit_bundle",
":copy_tslib",
]
input_files_base_dir = rebase_path("components-chromium/node_modules", "//")
resource_path_prefix = "mwc"
}

ts_library("library") {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 0 additions & 24 deletions third_party/material_web_components/lit_exports.js

This file was deleted.

46 changes: 37 additions & 9 deletions third_party/material_web_components/reproduce.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,43 @@ if [[ ! -z "${new}${deleted}" ]]; then
echo
fi

# In our BUILD file we have a ts_library rule which exposes all lit type
# definitions. The following bit of code discovers and outputs all lit type
# definitions so an engineer can manually update the afformentioned rule.
echo 'Please update the ts_library("library") rule in BUILD to contain these'
echo 'definitions:'
echo 'definitions = ['
for x in `find components-chromium/node_modules -type f | grep d.ts$`; do
echo " \"$x\","
cat > BUILD.gn << EOF
# Copyright 2022 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//tools/typescript/ts_library.gni")
import("//ui/webui/resources/tools/generate_grd.gni")
generate_grd("build_grdp") {
grd_prefix = "material_web_components"
out_grd = "\${target_gen_dir}/\${grd_prefix}_resources.grdp"
# TODO(b/229804752): Clean up and find the minimal set of necessary resources.
input_files = [
EOF
for x in `find components-chromium/node_modules | grep js$ | cut -f3- -d/`; do
echo " \"$x\"," >> BUILD.gn
done
echo ']'
cat >> BUILD.gn << EOF
]
input_files_base_dir = rebase_path("components-chromium/node_modules", "//")
resource_path_prefix = "mwc"
}
ts_library("library") {
composite = true
tsconfig_base = "tsconfig_base.json"
# TODO(b/229804752): Clean up and find the minimal set of necessary resources.
definitions = [
EOF
for x in `find components-chromium/node_modules -type f | grep d.ts$`; do
echo " \"$x\"," >> BUILD.gn
done
cat >> BUILD.gn << EOF
]
}
EOF
popd > /dev/null
27 changes: 11 additions & 16 deletions third_party/material_web_components/rewrite_imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
# ts_library.py or replacing the regex if only "tslib" is ever rewritten.
def main(argv):
parser = argparse.ArgumentParser()
# List of imports and what they should be rewritten to. Specified as an
# array of "src|dest" strings. Note that the src will be treated as regex
# matched against the entire import path. I.e. "foo|bar" will translate to
# re.replace("^foo$", "bar", line).
parser.add_argument('--import_mappings', nargs='*')
# The directory to output the rewritten files to.
parser.add_argument('--out_dir', required=True)
Expand All @@ -40,23 +36,22 @@ def main(argv):
(src, dst) = mapping.split('|')
import_mappings[src] = dst

def _map_import(import_path):
for regex in import_mappings.keys():
if re.match(f"^{regex}$", import_path):
return import_mappings[regex]
generated_import_match = re.match(r'^generated:(.*)', import_path)
if generated_import_match:
return generated_import_match.group(1)
return None

for f in args.in_files:
output = []
for line in open(os.path.join(args.base_dir, f), 'r').readlines():
# Investigate JS parsing if this is insufficient.
match = re.match(r'^(import .*["\'])(.*)(["\'];)$', line)
if match and _map_import(match.group(2)):
new_import = _map_import(match.group(2))
line = f"{match.group(1)}{new_import}{match.group(3)};\n"
if match:
import_src = match.group(2)
generated_import_match = re.match(r'^generated:(.*)',
import_src)
if import_src in import_mappings:
line = (match.group(1) + import_mappings[import_src] +
match.group(3) + '\n')
elif generated_import_match:
line = (match.group(1) + generated_import_match.group(1) +
match.group(3) + '\n')

output.append(line)
with open(os.path.join(args.out_dir, f), 'w') as out_file:
out_file.write(''.join(output))
Expand Down
2 changes: 2 additions & 0 deletions ui/file_manager/base/gn/files_webui_bundle/.style.yapf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[style]
based_on_style = chromium
31 changes: 31 additions & 0 deletions ui/file_manager/base/gn/files_webui_bundle/PRESUBMIT.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2022 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

USE_PYTHON3 = True


def _CheckChangeOnUploadOrCommit(input_api, output_api):
results = []
webui_sources = set(['files_webui_bundle.py', 'rollup_plugin.js'])
affected = input_api.AffectedFiles()
affected_files = [input_api.os_path.basename(f.LocalPath()) for f in affected]
if webui_sources.intersection(set(affected_files)):
results += RunFilesWebUiBundleTests(input_api, output_api)
return results


def RunFilesWebUiBundleTests(input_api, output_api):
presubmit_path = input_api.PresubmitLocalPath()
sources = ['files_webui_bundle_test.py']
tests = [input_api.os_path.join(presubmit_path, s) for s in sources]
return input_api.canned_checks.RunUnitTests(
input_api, output_api, tests, run_on_python2=False)


def CheckChangeOnUpload(input_api, output_api):
return _CheckChangeOnUploadOrCommit(input_api, output_api)


def CheckChangeOnCommit(input_api, output_api):
return _CheckChangeOnUploadOrCommit(input_api, output_api)

0 comments on commit 866ae15

Please sign in to comment.