Commit 84e30b50 authored by Trent Apted's avatar Trent Apted Committed by Commit Bot

Upstream js_unit_tests.gni to third_party/closure_compiler.

This is used for unit tests in ui/file_manager, but it is neat and
other targets should use it too. It's now pretty stable. It reduces
boilerplate in BUILD.gn files and allows foo_unittest.html files to
be automatically generated from build dependencies, rather than being
handcrafted.

js_unit_test.py currently lacks the performance optimization added
for js_binary in r581961 to cache dependency subtrees, so it's a
bit slow. Upstreaming allows the two python scripts to share the
dependency walker in a sane manner.

Bug: 860355
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: Iedddd39907137dd40ec21f507cb560756251c8b1
Reviewed-on: https://chromium-review.googlesource.com/1212364
Commit-Queue: Trent Apted <tapted@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#589840}
parent 4787ce43
...@@ -21,3 +21,4 @@ Local modifications: ...@@ -21,3 +21,4 @@ Local modifications:
*_private.js files. *_private.js files.
- Fix bug in js_binary.py causing it to drop externs. - Fix bug in js_binary.py causing it to drop externs.
- Cache dependency subtrees in js_binary.py for a huge performance boost. - Cache dependency subtrees in js_binary.py for a huge performance boost.
- Add js_unit_tests.gni for generating .html files for running unit tests.
...@@ -8,31 +8,15 @@ files to build an html file used for js unit tests. ...@@ -8,31 +8,15 @@ files to build an html file used for js unit tests.
""" """
from argparse import ArgumentParser from argparse import ArgumentParser
from js_binary import CrawlDepsTree
def flatten(deps): def Flatten(deps):
""" """
Recursively follows a list of dep files and returns source files in Recursively follows a list of dep files and returns source files in
dependency order. Ignores externs. dependency order. Ignores externs.
""" """
if len(deps) == 0: sources, externs = CrawlDepsTree(deps)
return [] return sources
sources = []
moredeps = []
for d in deps:
with open(d, "r") as depfile:
assert depfile.readline(
) == 'sources:\n', "Depfile parse error (expected 'sources:')."
line = depfile.readline()
while line != 'deps:\n':
assert line != '', "Depfile parse error (expected 'deps:')."
sources.append(line[:-1])
line = depfile.readline()
line = depfile.readline()
while line != 'externs:\n':
assert line != '', "Depfile parse error (expected 'externs:')."
moredeps.append(line[:-1])
line = depfile.readline()
return flatten(moredeps) + sources
def main(): def main():
parser = ArgumentParser() parser = ArgumentParser()
...@@ -44,14 +28,7 @@ def main(): ...@@ -44,14 +28,7 @@ def main():
help='Generated html output with flattened dependencies') help='Generated html output with flattened dependencies')
args = parser.parse_args() args = parser.parse_args()
alldeps = flatten([args.input]) uniquedeps = Flatten([args.input])
uniquedeps = []
# No such thing as include guards, so do that here with a set.
seen = set()
for d in alldeps:
if d not in seen:
seen.add(d)
uniquedeps.append(d)
with open(args.output, 'w') as out: with open(args.output, 'w') as out:
out.write('<!DOCTYPE html>\n<html>\n<body>\n') out.write('<!DOCTYPE html>\n<html>\n<body>\n')
out.write( out.write(
......
...@@ -43,7 +43,7 @@ import("//third_party/closure_compiler/compile_js.gni") ...@@ -43,7 +43,7 @@ import("//third_party/closure_compiler/compile_js.gni")
template("js_unit_tests") { template("js_unit_tests") {
html_gen_target_name = target_name + "_html_gen" html_gen_target_name = target_name + "_html_gen"
action_foreach(html_gen_target_name) { action_foreach(html_gen_target_name) {
script_path = "//ui/file_manager" script_path = "//third_party/closure_compiler"
script = "$script_path/js_unit_test.py" script = "$script_path/js_unit_test.py"
forward_variables_from(invoker, forward_variables_from(invoker,
[ [
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
import("//ui/file_manager/js_unit_tests.gni") import("//third_party/closure_compiler/js_unit_tests.gni")
js_type_check("closure_compile_module") { js_type_check("closure_compile_module") {
deps = [ deps = [
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
import("//ui/file_manager/js_unit_tests.gni") import("//third_party/closure_compiler/js_unit_tests.gni")
js_type_check("closure_compile_module") { js_type_check("closure_compile_module") {
deps = [ deps = [
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
import("//ui/file_manager/js_unit_tests.gni") import("//third_party/closure_compiler/js_unit_tests.gni")
js_type_check("closure_compile_module") { js_type_check("closure_compile_module") {
deps = [ deps = [
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
# found in the LICENSE file. # found in the LICENSE file.
import("//third_party/closure_compiler/compile_js.gni") import("//third_party/closure_compiler/compile_js.gni")
import("//ui/file_manager/js_unit_tests.gni") import("//third_party/closure_compiler/js_unit_tests.gni")
js_type_check("closure_compile_module") { js_type_check("closure_compile_module") {
deps = [ deps = [
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment