Use GN metadata to compute GRD files
GN metadata allows to specify and later query metadata from any
action in our build graph. Using GN metadata, we can specify
GRD files on an action and collect these files on the top level.
Then, we can compare the list of collected files to the expected
GRD files in `devtools_grd_files.gni` to ensure they match.
As a follow-up change, we can remove the intermediate lists we have
been specifying in `all_devtools_modules.gni` and
`devtools_module_entrypoints.gni`, which now become obsolete. That's
because both `devtools_module` and `devtools_entrypoint` now specify
the files in their respective metadata and essentially perform the
check that all relevant files are collected.
[email protected]
Also-By: [email protected]
Bug: 1174013
Change-Id: I9dd2e6f7e010b5c25f83556511af12d5d1c2ec7c
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2843322
Commit-Queue: Tim van der Lippe <[email protected]>
Reviewed-by: Alex Rudenko <[email protected]>
Reviewed-by: Paul Lewis <[email protected]>
diff --git a/BUILD.gn b/BUILD.gn
index 7b904ed..bbe2836 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -181,6 +181,56 @@
public_deps = [ "inspector_overlay:build_inspector_overlay" ]
}
+action("assert_grd") {
+ script = "scripts/build/assert_grd.py"
+
+ deps = [
+ ":expected_grd_files",
+ ":input_grd_files",
+ ]
+
+ inputs = [
+ "$target_gen_dir/expected_grd_files.json",
+ "$target_gen_dir/input_grd_files.json",
+ ]
+
+ args = [
+ rebase_path("$target_gen_dir/expected_grd_files.json", root_build_dir),
+ rebase_path("$target_gen_dir/input_grd_files.json", root_build_dir),
+ rebase_path("$target_gen_dir/assert_grd.stamp", root_build_dir),
+ ]
+
+ outputs = [ "$target_gen_dir/assert_grd.stamp" ]
+}
+
+generated_file("expected_grd_files") {
+ outputs = [ "$target_gen_dir/expected_grd_files.json" ]
+
+ _expected_files = []
+ _expected_files += grd_files_release_sources
+ if (is_debug) {
+ _expected_files += grd_files_debug_sources
+ }
+
+ contents = _expected_files
+
+ output_conversion = "json"
+}
+
+generated_file("input_grd_files") {
+ outputs = [ "$target_gen_dir/input_grd_files.json" ]
+
+ data_keys = [ "grd_files" ]
+
+ output_conversion = "json"
+ rebase = root_gen_dir
+
+ deps = [
+ ":build_release_devtools",
+ "front_end",
+ ]
+}
+
action("generate_devtools_grd") {
script = "scripts/build/generate_devtools_grd.py"
@@ -287,4 +337,8 @@
"--output_path_gen",
rebase_path("$target_gen_dir/front_end", root_build_dir),
] + build_release_devtools_args
+
+ metadata = {
+ grd_files = outputs
+ }
}
diff --git a/config/gni/all_devtools_files.gni b/config/gni/all_devtools_files.gni
index 19fcf0e..966fe85 100644
--- a/config/gni/all_devtools_files.gni
+++ b/config/gni/all_devtools_files.gni
@@ -308,10 +308,7 @@
"front_end/ui/legacy/components/text_editor/module.json",
"front_end/third_party/fabricjs/fabric.js",
"front_end/third_party/fabricjs/module.json",
- "front_end/third_party/lighthouse/lighthouse-dt-bundle.js",
"front_end/third_party/lighthouse/report-assets/report.css",
- "front_end/third_party/lighthouse/report-assets/report.js",
- "front_end/third_party/lighthouse/report-assets/report-generator.js",
"front_end/third_party/lighthouse/report-assets/template.html",
"front_end/third_party/lighthouse/report-assets/templates.html",
"front_end/panels/timeline/historyToolbarButton.css",
diff --git a/front_end/BUILD.gn b/front_end/BUILD.gn
index faa7846..03a7216 100644
--- a/front_end/BUILD.gn
+++ b/front_end/BUILD.gn
@@ -149,13 +149,16 @@
]
}
+copy_to_gen("integration_test_runner-gen") {
+ sources = [ "integration_test_runner.html" ]
+}
+
group("integration_test_runner") {
public_deps = [ ":integration_test_runner-gen" ]
data_deps = public_deps
-}
-
-copy_to_gen("integration_test_runner-gen") {
- sources = [ "integration_test_runner.html" ]
+ metadata = {
+ grd_files = get_target_outputs(":integration_test_runner-gen")
+ }
}
node_action("html_entrypoints") {
@@ -179,15 +182,27 @@
"$target_gen_dir/toolbox.html",
"$target_gen_dir/worker_app.html",
]
+
+ metadata = {
+ grd_files = outputs
+ }
}
-copy_to_gen("embedder-scripts") {
+copy_to_gen("embedder-scripts-gen") {
sources = [
"Tests.js",
"devtools_compatibility.js",
]
}
+group("embedder-scripts") {
+ public_deps = [ ":embedder-scripts-gen" ]
+ data_deps = public_deps
+ metadata = {
+ grd_files = get_target_outputs(":embedder-scripts-gen")
+ }
+}
+
# This target is used to perform checks on all generated `.d.ts` files.
# Previously we would only run these checks when `is_debug=false`, but
# this complicated debugging. Therefore, this target now always perform
diff --git a/front_end/Images/BUILD.gn b/front_end/Images/BUILD.gn
index 9177820..aa18d97 100644
--- a/front_end/Images/BUILD.gn
+++ b/front_end/Images/BUILD.gn
@@ -24,4 +24,11 @@
]
data = [ "$target_gen_dir/Images.js" ]
+
+ metadata = {
+ grd_files = data
+ foreach(_image_file, devtools_image_files) {
+ grd_files += [ "$target_gen_dir/$_image_file" ]
+ }
+ }
}
diff --git a/front_end/emulated_devices/optimized/BUILD.gn b/front_end/emulated_devices/optimized/BUILD.gn
index f4f045a..d8745ed 100644
--- a/front_end/emulated_devices/optimized/BUILD.gn
+++ b/front_end/emulated_devices/optimized/BUILD.gn
@@ -4,11 +4,14 @@
import("../../../scripts/build/ninja/copy.gni")
import("./optimized_images.gni")
+copy_to_gen("optimized_emulated_devices-gen") {
+ sources = devtools_emulated_devices_images
+}
+
group("optimized_emulated_devices") {
public_deps = [ ":optimized_emulated_devices-gen" ]
data_deps = public_deps
-}
-
-copy_to_gen("optimized_emulated_devices-gen") {
- sources = devtools_emulated_devices_images
+ metadata = {
+ grd_files = get_target_outputs(":optimized_emulated_devices-gen")
+ }
}
diff --git a/front_end/entrypoints/lighthouse_worker/BUILD.gn b/front_end/entrypoints/lighthouse_worker/BUILD.gn
index 5d5b370..c1ec821 100644
--- a/front_end/entrypoints/lighthouse_worker/BUILD.gn
+++ b/front_end/entrypoints/lighthouse_worker/BUILD.gn
@@ -4,11 +4,6 @@
import("../../../scripts/build/ninja/copy.gni")
-group("bundle") {
- public_deps = [ ":gen" ]
- data_deps = public_deps
-}
-
copy_to_gen("gen") {
sources = [
"LighthouseService.js",
@@ -17,3 +12,11 @@
deps = [ "../../third_party/lighthouse" ]
}
+
+group("bundle") {
+ public_deps = [ ":gen" ]
+ data_deps = public_deps
+ metadata = {
+ grd_files = get_target_outputs(":gen")
+ }
+}
diff --git a/front_end/legacy_test_runner/BUILD.gn b/front_end/legacy_test_runner/BUILD.gn
index 84faa83..5600de5 100644
--- a/front_end/legacy_test_runner/BUILD.gn
+++ b/front_end/legacy_test_runner/BUILD.gn
@@ -11,6 +11,10 @@
]
data = [ "$target_gen_dir/legacy_test_runner.js" ]
+
+ metadata = {
+ grd_files = data
+ }
}
ts_library("legacy_test_runner-source") {
diff --git a/front_end/third_party/acorn-loose/BUILD.gn b/front_end/third_party/acorn-loose/BUILD.gn
index 4ff569d..99611f0 100644
--- a/front_end/third_party/acorn-loose/BUILD.gn
+++ b/front_end/third_party/acorn-loose/BUILD.gn
@@ -5,6 +5,8 @@
import("../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("acorn-loose") {
+ sources_are_release = false
+
sources = [
"acorn-loose-tsconfig.json",
"package/dist/acorn-loose.d.ts",
diff --git a/front_end/third_party/acorn/BUILD.gn b/front_end/third_party/acorn/BUILD.gn
index 85e7007..af07bca 100644
--- a/front_end/third_party/acorn/BUILD.gn
+++ b/front_end/third_party/acorn/BUILD.gn
@@ -6,6 +6,8 @@
import("../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("acorn") {
+ sources_are_release = false
+
sources = [
"acorn-tsconfig.json",
"package/dist/acorn.d.ts",
diff --git a/front_end/third_party/chromium/client-variations/BUILD.gn b/front_end/third_party/chromium/client-variations/BUILD.gn
index dc453e6..dd5d279 100644
--- a/front_end/third_party/chromium/client-variations/BUILD.gn
+++ b/front_end/third_party/chromium/client-variations/BUILD.gn
@@ -6,6 +6,8 @@
import("../../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("client-variations") {
+ sources_are_release = false
+
sources = [
"ClientVariations.d.ts",
"ClientVariations.js",
diff --git a/front_end/third_party/codemirror/BUILD.gn b/front_end/third_party/codemirror/BUILD.gn
index e697640..df707b8 100644
--- a/front_end/third_party/codemirror/BUILD.gn
+++ b/front_end/third_party/codemirror/BUILD.gn
@@ -7,6 +7,8 @@
import("../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("codemirror") {
+ sources_are_release = false
+
sources = [
"codemirror-tsconfig.json",
"package/addon/comment/comment.d.ts",
diff --git a/front_end/third_party/lighthouse/BUILD.gn b/front_end/third_party/lighthouse/BUILD.gn
index cad8d72..4a23a39 100644
--- a/front_end/third_party/lighthouse/BUILD.gn
+++ b/front_end/third_party/lighthouse/BUILD.gn
@@ -4,23 +4,40 @@
import("../../../config/gni/all_devtools_files.gni")
import("../../../scripts/build/ninja/copy.gni")
+import("../../../scripts/build/ninja/devtools_pre_built.gni")
-lighthouse_sources = lighthouse_locale_files + [
- "lighthouse-tsconfig.json",
- "report-assets/report.js",
- "report-assets/report.d.ts",
- "report-assets/report-generator.js",
- "report-assets/report-generator.d.ts",
- "lighthouse-dt-bundle.js",
- "lighthouse-dt-bundle.d.ts",
- ]
+_lighthouse_sources = lighthouse_locale_files + [
+ "lighthouse-tsconfig.json",
+ "lighthouse-dt-bundle.d.ts",
+ ]
-group("lighthouse") {
- public_deps = [ ":lighthouse-gen" ]
-
- data_deps = [ ":lighthouse-gen" ]
+copy_to_gen("lighthouse-locale-files") {
+ sources = _lighthouse_sources
}
-copy_to_gen("lighthouse-gen") {
- sources = lighthouse_sources
+devtools_pre_built("lighthouse-javscript-sources-debug") {
+ sources_are_release = false
+
+ sources = [
+ "report-assets/report-generator.d.ts",
+ "report-assets/report-generator.js",
+ "report-assets/report.d.ts",
+ "report-assets/report.js",
+ ]
+}
+
+copy_to_gen("lighthouse-javscript-sources-release") {
+ sources = [ "lighthouse-dt-bundle.js" ]
+}
+
+group("lighthouse") {
+ public_deps = [
+ ":lighthouse-javscript-sources-debug",
+ ":lighthouse-javscript-sources-release",
+ ":lighthouse-locale-files",
+ ]
+ data_deps = public_deps
+ metadata = {
+ grd_files = get_target_outputs(":lighthouse-javscript-sources-release")
+ }
}
diff --git a/front_end/third_party/lit-html/BUILD.gn b/front_end/third_party/lit-html/BUILD.gn
index efbf712..37eeb05 100644
--- a/front_end/third_party/lit-html/BUILD.gn
+++ b/front_end/third_party/lit-html/BUILD.gn
@@ -7,6 +7,8 @@
import("../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("lit-html") {
+ sources_are_release = false
+
sources = [
"lit-html-tsconfig.json",
"package/directives/class-map.d.ts",
diff --git a/front_end/third_party/marked/BUILD.gn b/front_end/third_party/marked/BUILD.gn
index 7efda07..119dc6f 100644
--- a/front_end/third_party/marked/BUILD.gn
+++ b/front_end/third_party/marked/BUILD.gn
@@ -6,6 +6,8 @@
import("../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("marked") {
+ sources_are_release = false
+
sources = [
"marked-tsconfig.json",
"package/lib/marked.esm.d.ts",
diff --git a/front_end/third_party/puppeteer/BUILD.gn b/front_end/third_party/puppeteer/BUILD.gn
index a843eac..e5aa8eb 100644
--- a/front_end/third_party/puppeteer/BUILD.gn
+++ b/front_end/third_party/puppeteer/BUILD.gn
@@ -6,6 +6,8 @@
import("../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("puppeteer") {
+ sources_are_release = false
+
sources = [
"package/lib/esm/puppeteer/api-docs-entry.d.ts",
"package/lib/esm/puppeteer/api-docs-entry.d.ts.map",
diff --git a/front_end/third_party/wasmparser/BUILD.gn b/front_end/third_party/wasmparser/BUILD.gn
index 3848e04..a247a15 100644
--- a/front_end/third_party/wasmparser/BUILD.gn
+++ b/front_end/third_party/wasmparser/BUILD.gn
@@ -6,6 +6,8 @@
import("../../../scripts/build/ninja/devtools_pre_built.gni")
devtools_pre_built("wasmparser") {
+ sources_are_release = false
+
sources = [
"package/dist/esm/WasmDis.js",
"package/dist/esm/WasmParser.js",
diff --git a/scripts/build/assert_grd.py b/scripts/build/assert_grd.py
new file mode 100644
index 0000000..03110b8
--- /dev/null
+++ b/scripts/build/assert_grd.py
@@ -0,0 +1,57 @@
+#!/usr/bin/env vpython
+# -*- coding: UTF-8 -*-
+#
+# Copyright 2021 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+"""
+Asserts that expected and generated list of GRD files is equal.
+"""
+
+import sys
+import json
+
+
+def main(argv):
+ expected_grd_sources = open(argv[1], 'r').read()
+ generated_grd_sources = open(argv[2], 'r').read()
+ stamp_file = argv[3]
+
+ expected_json = json.loads(expected_grd_sources)
+ generated_json = json.loads(generated_grd_sources)
+
+ expected_json.sort()
+ generated_json.sort()
+
+ return_code = 0
+
+ for expected_file in expected_json:
+ if expected_file not in generated_json:
+ print(
+ "File " + expected_file +
+ " is not generated by any action in front_end." +
+ " Either remove it from config/gni/devtools_grd_files.gni" +
+ " or add the missing file to an action" +
+ " (for example a devtools_module or devtools_entrypoint definition).\n"
+ )
+
+ return_code = 1
+
+ for generated_file in generated_json:
+ if generated_file not in expected_json:
+ print(
+ "File " + generated_file +
+ " is not listed in config/gni/devtools_grd_files.gni." +
+ " Either add the file to the grd_files_release_sources/grd_files_debug_sources,"
+ + " or remove the generated file from an action.\n")
+
+ return_code = 1
+
+ with open(stamp_file, 'w', encoding="utf8") as fp:
+ fp.write("")
+
+ return return_code
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
diff --git a/scripts/build/ninja/devtools_entrypoint.gni b/scripts/build/ninja/devtools_entrypoint.gni
index 9113f3e..79d1145 100644
--- a/scripts/build/ninja/devtools_entrypoint.gni
+++ b/scripts/build/ninja/devtools_entrypoint.gni
@@ -200,6 +200,10 @@
outputs = [ _generated_tsconfig_location ]
data = _target_outputs
+
+ metadata = {
+ grd_files = _target_outputs
+ }
}
_target_name = invoker.entrypoint
diff --git a/scripts/build/ninja/devtools_module.gni b/scripts/build/ninja/devtools_module.gni
index a90b3f2..1e7ac0a 100644
--- a/scripts/build/ninja/devtools_module.gni
+++ b/scripts/build/ninja/devtools_module.gni
@@ -26,9 +26,11 @@
visibility += [ ":*" ]
}
+ _target_outputs = get_target_outputs(_typescript_target_dep)
+ _javascript_implementation_files =
+ filter_include(_target_outputs + invoker.data, [ "*.js" ])
if (is_debug) {
- _target_outputs = get_target_outputs(_typescript_target_dep)
_filtered_target_outputs =
filter_include(
filter_exclude(_target_outputs, generated_typescript_modules),
@@ -44,12 +46,13 @@
visibility = invoker.visibility + [ ":*" ]
- data = invoker.data +
- filter_include(get_target_outputs(_typescript_target_dep),
- [
- "*.js",
- "*.map",
- ])
+ data = _javascript_implementation_files +
+ filter_include(invoker.data + _target_outputs, [ "*.map" ])
+ if (is_debug) {
+ metadata = {
+ grd_files = _javascript_implementation_files
+ }
+ }
}
}
diff --git a/scripts/build/ninja/devtools_pre_built.gni b/scripts/build/ninja/devtools_pre_built.gni
index c830ba4..6b17875 100644
--- a/scripts/build/ninja/devtools_pre_built.gni
+++ b/scripts/build/ninja/devtools_pre_built.gni
@@ -15,20 +15,27 @@
deps = invoker.deps
}
+ _target_outputs = get_target_outputs(_copy_gen_target_dep)
+ _javascript_implementation_files =
+ invoker.data + filter_include(_target_outputs,
+ [
+ "*.js",
+ "*.mjs",
+ ])
+
group(target_name) {
public_deps = [ _copy_gen_target_dep ]
- data =
- invoker.data + filter_include(get_target_outputs(_copy_gen_target_dep),
- [
- "*.js",
- "*.mjs",
- "*.map",
- ])
+ data = _javascript_implementation_files +
+ filter_include(_target_outputs, [ "*.map" ])
+ if (invoker.sources_are_release || is_debug) {
+ metadata = {
+ grd_files = _javascript_implementation_files
+ }
+ }
}
if (is_debug) {
- _target_outputs = get_target_outputs(_copy_gen_target_dep)
_filtered_target_outputs =
filter_include(
filter_exclude(_target_outputs, generated_typescript_modules),
@@ -42,4 +49,5 @@
set_defaults("devtools_pre_built") {
deps = []
data = []
+ sources_are_release = true
}