Add transpilation to PolyGerrit

Utilize the Closure compiler in Bazel to transpile. As part of this, a
rather large file of 'externs' must be added in order to call external
code. This file is specific to Polymer and copied from the Closure
Github, and should be synced any time there are major changes to
Polymer.

Test Plan:

  - run `bazel build polygerrit` and verify that whitespaces are removed
    from resulting gr-app.js file
  - run `bazel build Documentation:licenses.txt` and verify that the new
    dependency is listed in resulting
    bazel-genfiles/Documentation/licenses.txt

TODO in later changes:
  - Get closure optimizations working
  - Explore sourcemaps possibilities
  - Maybe use closure linting?

Change-Id: Ic358743dda7286fea3ac1e95a7991a92c96d6341
(cherry picked from commit 1ea918bd36)
This commit is contained in:
Kasper Nilsson 2017-04-25 13:55:01 +02:00 committed by David Pursehouse
parent 1cbeda4978
commit c78fb72fd9
4 changed files with 97 additions and 3 deletions

View File

@ -4,6 +4,40 @@ load("//tools/bzl:maven_jar.bzl", "maven_jar", "GERRIT", "MAVEN_LOCAL")
load("//lib/codemirror:cm.bzl", "CM_VERSION", "DIFF_MATCH_PATCH_VERSION")
load("//plugins:external_plugin_deps.bzl", "external_plugin_deps")
http_archive(
name = "io_bazel_rules_closure",
strip_prefix = "rules_closure-0.4.1",
sha256 = "ba5e2e10cdc4027702f96e9bdc536c6595decafa94847d08ae28c6cb48225124",
url = "http://bazel-mirror.storage.googleapis.com/github.com/bazelbuild/rules_closure/archive/0.4.1.tar.gz",
)
# File is specific to Polymer and copied from the Closure Github -- should be
# synced any time there are major changes to Polymer.
# https://github.com/google/closure-compiler/blob/master/contrib/externs/polymer-1.0.js
http_file(
name = "polymer_closure",
sha256 = "5a589bdba674e1fec7188e9251c8624ebf2d4d969beb6635f9148f420d1e08b1",
url = "https://raw.githubusercontent.com/google/closure-compiler/775609aad61e14aef289ebec4bfc09ad88877f9e/contrib/externs/polymer-1.0.js",
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_repositories")
# Prevent redundant loading of dependencies.
closure_repositories(
omit_aopalliance=True,
omit_args4j=True,
omit_jsr305=True,
omit_gson=True,
omit_guava=True,
omit_guice=True,
omit_soy=True,
omit_icu4j=True,
omit_asm=True,
omit_asm_analysis=True,
omit_asm_commons=True,
omit_asm_util=True,
)
ANTLR_VERS = "3.5.2"
maven_jar(

26
lib/polymer_externs/BUILD Normal file
View File

@ -0,0 +1,26 @@
# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
package(
default_visibility = ["//visibility:public"],
)
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library")
closure_js_library(
name = "polymer_closure",
srcs = ["@polymer_closure//file"],
data = ["//lib:LICENSE-Apache2.0"],
no_closure_library = True,
)

View File

@ -3,6 +3,7 @@ package(
)
load("//tools/bzl:genrule2.bzl", "genrule2")
load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_library", "closure_js_binary")
load(
"//tools/bzl:js.bzl",
"bower_component_bundle",
@ -29,6 +30,31 @@ vulcanize(
deps = ["//polygerrit-ui:polygerrit_components.bower_components"],
)
closure_js_library(
name = "closure_lib",
srcs = ["gr-app.js"],
language = "ECMASCRIPT6",
suppress = [
"JSC_BAD_JSDOC_ANNOTATION",
"JSC_TYPE_PARSE_ERROR",
"JSC_MISPLACED_MSG_ANNOTATION",
],
deps = [
"//lib/polymer_externs:polymer_closure",
"@io_bazel_rules_closure//closure/library",
],
)
closure_js_binary(
name = "closure_bin",
# Known issue: Closure compilation not compatible with Polymer behaviors.
# See: https://github.com/google/closure-compiler/issues/2042
compilation_level = "WHITESPACE_ONLY",
defs = ["--polymer_pass"],
language = "ECMASCRIPT3",
deps = [":closure_lib"],
)
filegroup(
name = "top_sources",
srcs = [
@ -42,6 +68,14 @@ filegroup(
srcs = glob(["styles/**/*.css"]),
)
filegroup(
name = "app_sources",
srcs = [
"closure_bin.js",
"gr-app.html",
],
)
genrule2(
name = "polygerrit_ui",
srcs = [
@ -49,7 +83,7 @@ genrule2(
"//lib/js:highlightjs_files",
":top_sources",
":css_sources",
":gr-app",
":app_sources",
# we extract from the zip, but depend on the component for license checking.
"@webcomponentsjs//:zipfile",
"//lib/js:webcomponentsjs",
@ -57,7 +91,7 @@ genrule2(
outs = ["polygerrit_ui.zip"],
cmd = " && ".join([
"mkdir -p $$TMP/polygerrit_ui/{styles,fonts,bower_components/{highlightjs,webcomponentsjs},elements}",
"cp $(locations :gr-app) $$TMP/polygerrit_ui/elements/",
"for f in $(locations :app_sources); do ext=$${f##*.}; cp -p $$f $$TMP/polygerrit_ui/elements/gr-app.$$ext; done",
"cp $(locations //lib/fonts:sourcecodepro) $$TMP/polygerrit_ui/fonts/",
"for f in $(locations :top_sources); do cp $$f $$TMP/polygerrit_ui/; done",
"for f in $(locations :css_sources); do cp $$f $$TMP/polygerrit_ui/styles; done",

View File

@ -1,2 +1,2 @@
build --workspace_status_command=./tools/workspace-status.sh
build --workspace_status_command=./tools/workspace-status.sh --strategy=Closure=worker
test --build_tests_only