Skip to content

Commit

Permalink
Add GN Closure Compilation ui/webui/
Browse files Browse the repository at this point in the history
This CL converts ui/webui/ to use GN for its Closure Compilation. For
now this will run side-by-side with GYP, with the GYP compilation being
removed once all clients are switched to GN.

The compile_js.gni has been augmented with extra_sources support and
the ability to type check a group of js_library targets. A PRESUBMIT
which warns when BUILD.gn files are not updated has been added.

Bug: 632206
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ibad3213eb67f5c0ea42555cc45126a00cbdb783e
Reviewed-on: https://chromium-review.googlesource.com/942128
Commit-Queue: calamity <calamity@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Demetrios Papadopoulos <dpapad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#541316}
  • Loading branch information
nik3daz authored and Commit Bot committed Mar 7, 2018
1 parent 195955a commit 739a90d
Show file tree
Hide file tree
Showing 32 changed files with 1,125 additions and 10 deletions.
8 changes: 8 additions & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,14 @@ template("assert_valid_out_dir") {
"Do not use a platform name in your output directory (found \"$root_build_dir\"). http://crbug.com/548283")
}

if (!is_win) {
group("webui_closure_compile") {
data_deps = [
"ui/webui/resources:closure_compile",
]
}
}

assert_valid_out_dir("_unused") {
actual_sources = [ "$root_build_dir/foo" ]
}
2 changes: 1 addition & 1 deletion third_party/closure_compiler/closure_args.gni
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ checking_closure_args = [
"jscomp_error=uselessCode",
"jscomp_error=visibility",

"language_in=ECMASCRIPT6_STRICT",
"language_in=ECMASCRIPT_NEXT",
"language_out=ECMASCRIPT5_STRICT",

"chrome_pass",
Expand Down
19 changes: 19 additions & 0 deletions third_party/closure_compiler/compile_js.gni
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import("//third_party/closure_compiler/closure_args.gni")
script_path = "//third_party/closure_compiler"
compiler_path = "$script_path/compiler/compiler.jar"
externs_path = "$script_path/externs"
interfaces_path = "$script_path/interfaces"
polymer_externs = "$externs_path/polymer-1.0.js"

# Defines a target that creates an ordering for .js files to be used by
Expand All @@ -24,6 +25,12 @@ polymer_externs = "$externs_path/polymer-1.0.js"
# List of any other rules to depend on. E.g. a rule that generates js source
# files
#
# externs_list:
# A list of .js files to pass to the compiler as externs
#
# extra_sources:
# A list of .js files to pass to the compiler as interfaces
#
# Example:
# js_library("apple_tree") {
# sources = ["tree_main.js"]
Expand All @@ -42,6 +49,7 @@ template("js_library") {
"sources",
"deps",
"externs_list",
"extra_sources",
"extra_deps",
])
output_file = "$target_gen_dir/$target_name.js_library"
Expand All @@ -57,6 +65,9 @@ template("js_library") {
}

args += [ "--sources" ] + rebase_path(sources, root_build_dir)
if (defined(extra_sources)) {
args += rebase_path(extra_sources, root_build_dir)
}

if (defined(deps)) {
args += [ "--deps" ]
Expand Down Expand Up @@ -197,3 +208,11 @@ template("js_binary") {
}
}
}

# Defines a target that compiles a group of js_library targets.
template("js_type_check") {
js_binary(target_name) {
sources = []
forward_variables_from(invoker, [ "deps" ])
}
}
13 changes: 13 additions & 0 deletions ui/webui/resources/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2018 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.

import("//third_party/closure_compiler/compile_js.gni")

group("closure_compile") {
deps = [
"cr_components:closure_compile",
"cr_elements:closure_compile",
"js:closure_compile",
]
}
27 changes: 27 additions & 0 deletions ui/webui/resources/PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import os

def PostUploadHook(cl, change, output_api):
return output_api.EnsureCQIncludeTrybotsAreAdded(
cl,
Expand All @@ -18,6 +20,30 @@ def CheckChangeOnUpload(input_api, output_api):
def CheckChangeOnCommit(input_api, output_api):
return _CommonChecks(input_api, output_api)

# For every modified gyp file, warn if the corresponding GN file is not updated.
def _CheckForGNUpdate(input_api, output_api):
gyp_folders = set()
for f in input_api.AffectedFiles():
local_path = f.LocalPath()
if local_path.endswith('compiled_resources2.gyp'):
gyp_folders.add(os.path.dirname(local_path))

for f in input_api.AffectedFiles():
local_path = f.LocalPath()
dir_name = os.path.dirname(local_path)
if local_path.endswith('BUILD.gn') and dir_name in gyp_folders:
gyp_folders.remove(dir_name)

if not gyp_folders:
return []

return [output_api.PresubmitPromptWarning("""
You may have forgotten to update the BUILD.gn Closure Compilation for the
following folders:
""" + "\n".join(["- " + x for x in gyp_folders]) + """
Ping calamity@ or check go/closure-compile-gn for more details.
""")]

def _CheckForTranslations(input_api, output_api):
shared_keywords = ['i18n(']
Expand Down Expand Up @@ -60,6 +86,7 @@ def _CheckForTranslations(input_api, output_api):
def _CommonChecks(input_api, output_api):
results = []
results += _CheckForTranslations(input_api, output_api)
results += _CheckForGNUpdate(input_api, output_api)
results += input_api.canned_checks.CheckPatchFormatted(input_api, output_api,
check_js=True)
try:
Expand Down
12 changes: 12 additions & 0 deletions ui/webui/resources/cr_components/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Copyright 2018 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.

import("//third_party/closure_compiler/compile_js.gni")

group("closure_compile") {
deps = [
"certificate_manager:closure_compile",
"chromeos:closure_compile",
]
}
128 changes: 128 additions & 0 deletions ui/webui/resources/cr_components/certificate_manager/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# Copyright 2018 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.

import("//third_party/closure_compiler/compile_js.gni")

js_type_check("closure_compile") {
deps = [
":ca_trust_edit_dialog",
":certificate_delete_confirmation_dialog",
":certificate_entry",
":certificate_list",
":certificate_manager",
":certificate_manager_types",
":certificate_password_decryption_dialog",
":certificate_password_encryption_dialog",
":certificate_subentry",
":certificates_browser_proxy",
":certificates_error_dialog",
]
}

js_library("ca_trust_edit_dialog") {
deps = [
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js:load_time_data",
]
}

js_library("certificate_delete_confirmation_dialog") {
deps = [
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js:load_time_data",
]
}

js_library("certificate_entry") {
deps = [
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
]
}

js_library("certificate_list") {
deps = [
":certificate_manager_types",
":certificate_subentry",
":certificates_browser_proxy",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
]
}

js_library("certificate_manager") {
deps = [
":certificate_list",
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/js:assert",
"//ui/webui/resources/js:load_time_data",
"//ui/webui/resources/js:web_ui_listener_behavior",
"//ui/webui/resources/js/cr/ui:focus_without_ink",
]
}

js_library("certificate_manager_types") {
deps = [
":certificates_browser_proxy",
]
}

js_library("certificate_password_decryption_dialog") {
deps = [
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
]
}

js_library("certificate_password_encryption_dialog") {
deps = [
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
]
}

js_library("certificate_subentry") {
deps = [
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/cr_elements/cr_action_menu:cr_action_menu",
"//ui/webui/resources/cr_elements/cr_lazy_render:cr_lazy_render",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
]
}

js_library("certificates_browser_proxy") {
deps = [
"//ui/webui/resources/js:cr",
]
}

js_library("certificates_error_dialog") {
deps = [
":certificate_manager_types",
":certificates_browser_proxy",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
"//ui/webui/resources/js:load_time_data",
]
}
38 changes: 38 additions & 0 deletions ui/webui/resources/cr_components/chromeos/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2018 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.

import("//third_party/closure_compiler/compile_js.gni")

group("closure_compile") {
deps = [
":chromeos_resources",
"network:closure_compile",
"quick_unlock:closure_compile",
]
}

js_type_check("chromeos_resources") {
deps = [
":bluetooth_dialog",
]
}

js_library("bluetooth_dialog") {
deps = [
"//third_party/polymer/v1_0/components-chromium/iron-resizable-behavior:iron-resizable-behavior-extracted",
"//third_party/polymer/v1_0/components-chromium/paper-input:paper-input-extracted",
"//ui/webui/resources/cr_elements/cr_dialog:cr_dialog",
"//ui/webui/resources/js:assert",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:i18n_behavior",
]
externs_list = [
"$externs_path/bluetooth.js",
"$externs_path/bluetooth_private.js",
]
extra_sources = [
"$interfaces_path/bluetooth_interface.js",
"$interfaces_path/bluetooth_private_interface.js",
]
}
Loading

0 comments on commit 739a90d

Please sign in to comment.