0

Support testonly for closure_compile targets in ui/file_manager.

`testonly` ensures that test-only utility files are not depended on by
release files. It also helps when navigating deps in GN's tools.

To cut down on boilerplate, introduce `js_unittest` that automatically
adds testonly = true to js_library and is a better description of these
targets.

Leave "test_support" libraries using js_library + testonly.

Bug: 879035
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I5463718ef3f13ead4fd1efae150ff1f7830e43ad
Reviewed-on: https://chromium-review.googlesource.com/c/1275725
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: calamity <calamity@chromium.org>
Reviewed-by: Noel Gordon <noel@chromium.org>
Cr-Commit-Position: refs/heads/master@{#600200}
This commit is contained in:
Trent Apted
2018-10-17 00:03:30 +00:00
committed by Commit Bot
parent d06a979d44
commit 572ba7554b
11 changed files with 73 additions and 29 deletions
BUILD.gn
third_party/closure_compiler
ui/file_manager
BUILD.gn
base
file_manager
background
common
foreground
gallery
js
BUILD.gn
image_editor
image_loader

@ -1167,6 +1167,7 @@ template("assert_valid_out_dir") {
if (closure_compile) {
group("webui_closure_compile") {
testonly = true
data_deps = [
"chrome/browser/resources:closure_compile",
"content/browser/resources:closure_compile",

@ -48,11 +48,12 @@ template("js_library") {
script = "$script_path/js_library.py"
forward_variables_from(invoker,
[
"sources",
"deps",
"externs_list",
"extra_sources",
"extra_deps",
"extra_sources",
"sources",
"testonly",
"visibility",
])
output_file = "$target_gen_dir/$target_name.js_library"
@ -146,15 +147,16 @@ template("js_binary") {
script = "$script_path/js_binary.py"
forward_variables_from(invoker,
[
"sources",
"deps",
"outputs",
"bootstrap_file",
"config_files",
"checks_only",
"closure_flags",
"config_files",
"deps",
"externs_list",
"extra_deps",
"checks_only",
"outputs",
"sources",
"testonly",
])
args = [
"--compiler",
@ -237,6 +239,7 @@ template("js_type_check") {
[
"deps",
"closure_flags",
"testonly",
])
}
} else {

@ -50,6 +50,7 @@ template("js_unit_tests") {
"deps",
"mocks",
])
testonly = true
sources = []
foreach(dep, deps) {
sources += get_target_outputs(dep)
@ -79,6 +80,7 @@ template("js_unit_tests") {
type_check_target_name = target_name + "_" + dep + "_type_check"
type_check_deps += [ ":$type_check_target_name" ]
js_type_check(type_check_target_name) {
testonly = true
forward_variables_from(invoker, [ "closure_flags" ])
deps = [
dep,
@ -87,12 +89,33 @@ template("js_unit_tests") {
}
type_check_group_name = target_name + "_type_check"
group(type_check_group_name) {
testonly = true
deps = type_check_deps
}
group(target_name) {
data = get_target_outputs(":$html_gen_target_name")
testonly = true
deps = [
":$html_gen_target_name",
]
}
}
# Simple wrapper around js_library to describe a unit test.
template("js_unittest") {
js_library(target_name) {
testonly = true
# Forward everything that js_library forwards except testonly (omitting that
# causes gn to emit "Assignment had no effect" if it's added redundantly).
forward_variables_from(invoker,
[
"deps",
"externs_list",
"extra_deps",
"extra_sources",
"sources",
"visibility",
])
}
}

@ -30,6 +30,10 @@ component("file_manager") {
}
group("closure_compile") {
# Subfolders' closure_compile groups bundle the non-test "module" type-check
# groups as well as unittests and test_support.
testonly = true
deps = [
"audio_player/elements:closure_compile",
"audio_player/js:closure_compile",
@ -50,6 +54,7 @@ group("closure_compile") {
}
group("unit_test_data") {
testonly = true
deps = [
"file_manager/background/js:unit_tests",
"file_manager/common/js:unit_tests",

@ -7,6 +7,7 @@ import("//third_party/closure_compiler/compile_js.gni")
visibility = [ "//ui/file_manager/*" ]
group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":test_support_type_check",
@ -21,6 +22,7 @@ js_type_check("closure_compile_module") {
}
js_type_check("test_support_type_check") {
testonly = true
deps = [
":mock_chrome",
":test_error_reporting",
@ -45,9 +47,11 @@ js_library("filtered_volume_manager") {
}
js_library("mock_chrome") {
testonly = true
}
js_library("test_error_reporting") {
testonly = true
deps = [
# Note we allow targets depending on test_error_reporting to access
# webui_resource_test transitively.

@ -19,6 +19,7 @@ related_apps = [
]
group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",
@ -305,7 +306,7 @@ js_library("volume_manager_factory") {
]
}
js_library("volume_manager_unittest") {
js_unittest("volume_manager_unittest") {
deps = [
":volume_manager_factory",
"//ui/file_manager/base/js:mock_chrome",

@ -9,6 +9,7 @@ import("//third_party/closure_compiler/js_unit_tests.gni")
visibility = [ "//ui/file_manager/*" ]
group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":test_support_type_check",
@ -34,6 +35,7 @@ js_type_check("closure_compile_module") {
}
js_type_check("test_support_type_check") {
testonly = true
deps = [
":test_importer_common",
":unittest_util",
@ -43,7 +45,7 @@ js_type_check("test_support_type_check") {
js_library("async_util") {
}
js_library("async_util_unittest") {
js_unittest("async_util_unittest") {
deps = [
":async_util",
"//ui/file_manager/base/js:test_error_reporting",
@ -57,7 +59,7 @@ js_library("files_app_entry_types") {
externs_list = [ "../../../externs/volume_info.js" ]
}
js_library("files_app_entry_types_unittest") {
js_unittest("files_app_entry_types_unittest") {
deps = [
":files_app_entry_types",
":volume_manager_common",
@ -91,6 +93,7 @@ js_library("importer_common") {
}
js_library("test_importer_common") {
testonly = true
deps = [
":importer_common",
":unittest_util",
@ -100,7 +103,7 @@ js_library("test_importer_common") {
visibility = [ "//ui/file_manager/file_manager/*" ]
}
js_library("importer_common_unittest") {
js_unittest("importer_common_unittest") {
deps = [
":mock_entry",
":test_importer_common",
@ -113,7 +116,7 @@ js_library("importer_common_unittest") {
js_library("lru_cache") {
}
js_library("lru_cache_unittest") {
js_unittest("lru_cache_unittest") {
deps = [
":lru_cache",
"//ui/webui/resources/js:webui_resource_test",
@ -151,7 +154,7 @@ js_library("mock_entry") {
js_library("progress_center_common") {
}
js_library("unittest_util") {
js_unittest("unittest_util") {
# Only files app tests use this util file.
visibility = []
visibility = [ "//ui/file_manager/file_manager/*" ]
@ -179,7 +182,7 @@ js_library("util") {
]
}
js_library("util_unittest") {
js_unittest("util_unittest") {
deps = [
":mock_entry",
":util",

@ -576,7 +576,7 @@ js_library("thumbnail_loader") {
]
}
js_library("thumbnail_loader_unittest") {
js_unittest("thumbnail_loader_unittest") {
deps = [
":thumbnail_loader",
"../../common/js:mock_entry",
@ -614,6 +614,7 @@ js_unit_tests("unit_tests") {
}
group("closure_compile") {
testonly = true
visibility += [ "*" ]
deps = [
":closure_compile_module",

@ -43,7 +43,7 @@ js_library("dimmable_ui_controller") {
]
}
js_library("dimmable_ui_controller_unittest") {
js_unittest("dimmable_ui_controller_unittest") {
deps = [
":dimmable_ui_controller",
"//ui/webui/resources/js:webui_resource_test",
@ -58,7 +58,7 @@ js_library("entry_list_watcher") {
]
}
js_library("entry_list_watcher_unittest") {
js_unittest("entry_list_watcher_unittest") {
deps = [
":entry_list_watcher",
"../../file_manager/common/js:mock_entry",
@ -99,7 +99,7 @@ js_library("gallery_data_model") {
]
}
js_library("gallery_data_model_unittest") {
js_unittest("gallery_data_model_unittest") {
deps = [
":gallery_data_model",
":mock_gallery_item",
@ -120,7 +120,7 @@ js_library("gallery_item") {
externs_list = [ "../../externs/entry_location.js" ]
}
js_library("gallery_item_unittest") {
js_unittest("gallery_item_unittest") {
deps = [
":gallery_item",
":mock_gallery_item",
@ -137,7 +137,7 @@ js_library("gallery_util") {
]
}
js_library("gallery_util_unittest") {
js_unittest("gallery_util_unittest") {
deps = [
":gallery_util",
"../../file_manager/common/js:mock_entry",
@ -168,7 +168,7 @@ js_library("ribbon") {
]
}
js_library("ribbon_unittest") {
js_unittest("ribbon_unittest") {
deps = [
":ribbon",
]
@ -196,7 +196,7 @@ js_library("slide_mode") {
externs_list = [ "../../externs/gallery_foreground.js" ]
}
js_library("slide_mode_unittest") {
js_unittest("slide_mode_unittest") {
deps = [
":slide_mode",
"//ui/file_manager/base/js:test_error_reporting",
@ -229,6 +229,7 @@ js_unit_tests("unit_tests") {
}
group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",

@ -47,7 +47,7 @@ js_library("exif_encoder") {
externs_list = [ "../../../externs/exif_entry.js" ]
}
js_library("exif_encoder_unittest") {
js_unittest("exif_encoder_unittest") {
deps = [
":exif_encoder",
":test_util",
@ -120,7 +120,7 @@ js_library("image_encoder") {
]
}
js_library("image_encoder_unittest") {
js_unittest("image_encoder_unittest") {
deps = [
":image_encoder",
":test_util",
@ -179,7 +179,7 @@ js_library("image_view") {
]
}
js_library("image_view_unittest") {
js_unittest("image_view_unittest") {
deps = [
":image_view",
"..:mock_gallery_item",
@ -207,6 +207,7 @@ js_unit_tests("unit_tests") {
}
group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",

@ -29,7 +29,7 @@ js_library("background") {
js_library("cache") {
}
js_library("cache_unittest") {
js_unittest("cache_unittest") {
deps = [
":cache",
":load_image_request",
@ -48,7 +48,7 @@ js_library("image_loader") {
]
}
js_library("image_loader_unittest") {
js_unittest("image_loader_unittest") {
deps = [
":image_loader",
"//ui/webui/resources/js:webui_resource_test",
@ -82,7 +82,7 @@ js_library("image_loader_client") {
]
}
js_library("image_loader_client_unittest") {
js_unittest("image_loader_client_unittest") {
deps = [
":image_loader_client",
"//ui/file_manager/base/js:test_error_reporting",
@ -96,7 +96,7 @@ js_library("piex_loader") {
]
}
js_library("piex_loader_unittest") {
js_unittest("piex_loader_unittest") {
deps = [
":piex_loader",
"//ui/file_manager/base/js:test_error_reporting",
@ -133,6 +133,7 @@ js_unit_tests("unit_tests") {
}
group("closure_compile") {
testonly = true
deps = [
":closure_compile_module",
":unit_tests_type_check",