From 9eab336e4c19c947ad510f4e0afc009481a2d110 Mon Sep 17 00:00:00 2001 From: Viktar Donich Date: Mon, 9 Jul 2018 21:00:36 -0700 Subject: [PATCH] Upgrade polygerrit_plugin rule Now polygerrit_plugin does the following: - creates output rule with the plugin name to create output static files - combines (i.e. vulcanizes) plugin JS/HTML sources - closure compiles with compilation_level = "SIMPLE" - includes assets to output filegroup Change-Id: Ie63367a3aa566779fa816aa0f22915ef323a4c3b --- plugins/codemirror-editor | 2 +- polygerrit-ui/externs/BUILD | 25 ++++++++ polygerrit-ui/externs/plugin.js | 28 +++++++++ tools/bzl/js.bzl | 102 ++++++++++++++++++++++++++++---- 4 files changed, 146 insertions(+), 11 deletions(-) create mode 100644 polygerrit-ui/externs/BUILD create mode 100644 polygerrit-ui/externs/plugin.js diff --git a/plugins/codemirror-editor b/plugins/codemirror-editor index 53dccff17c..318504d0eb 160000 --- a/plugins/codemirror-editor +++ b/plugins/codemirror-editor @@ -1 +1 @@ -Subproject commit 53dccff17c029459999ff70ac886b80626af634b +Subproject commit 318504d0eb74f2f9c2967e9865ace6d5b57638c6 diff --git a/polygerrit-ui/externs/BUILD b/polygerrit-ui/externs/BUILD new file mode 100644 index 0000000000..fab3954be5 --- /dev/null +++ b/polygerrit-ui/externs/BUILD @@ -0,0 +1,25 @@ +# Copyright (C) 2018 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 = "plugin", + srcs = ["plugin.js"], + no_closure_library = True, +) diff --git a/polygerrit-ui/externs/plugin.js b/polygerrit-ui/externs/plugin.js new file mode 100644 index 0000000000..edace7d3b8 --- /dev/null +++ b/polygerrit-ui/externs/plugin.js @@ -0,0 +1,28 @@ +/** + * @license + * Copyright (C) 2018 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. + */ + +/** + * @fileoverview Closure compiler externs for the Gerrit UI plugins. + * @externs + */ + +var Gerrit = {}; + +/** + * @param {!Function} callback + */ +Gerrit.install = function(callback) {}; diff --git a/tools/bzl/js.bzl b/tools/bzl/js.bzl index fbacfad641..03ee87c985 100644 --- a/tools/bzl/js.bzl +++ b/tools/bzl/js.bzl @@ -3,6 +3,7 @@ NPMJS = "NPMJS" GERRIT = "GERRIT:" load("//lib/js:npm.bzl", "NPM_SHA1S", "NPM_VERSIONS") +load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_js_library") def _npm_tarball(name): return "%s@%s.npm_binary.tgz" % (name, NPM_VERSIONS[name]) @@ -146,9 +147,9 @@ def _bower_component_impl(ctx): transitive_versions += d.transitive_versions return struct( - transitive_zipfiles = transitive_zipfiles, - transitive_versions = transitive_versions, transitive_licenses = transitive_licenses, + transitive_versions = transitive_versions, + transitive_zipfiles = transitive_zipfiles, ) _common_attrs = { @@ -187,9 +188,9 @@ def _js_component(ctx): licenses += depset([ctx.file.license]) return struct( - transitive_zipfiles = list([ctx.outputs.zip]), - transitive_versions = depset(), transitive_licenses = licenses, + transitive_versions = depset(), + transitive_zipfiles = list([ctx.outputs.zip]), ) js_component = rule( @@ -271,9 +272,9 @@ def _bower_component_bundle_impl(ctx): ) return struct( - transitive_zipfiles = zips, - transitive_versions = versions, transitive_licenses = licenses, + transitive_versions = versions, + transitive_zipfiles = zips, ) bower_component_bundle = rule( @@ -341,8 +342,8 @@ def _vulcanize_impl(ctx): # from the environment, and it may be under $HOME, so we can't run # in the sandbox. node_tweaks = dict( - use_default_shell_env = True, execution_requirements = {"local": "1"}, + use_default_shell_env = True, ) ctx.actions.run_shell( mnemonic = "Vulcanize", @@ -427,6 +428,87 @@ def vulcanize(*args, **kwargs): """Vulcanize runs vulcanize and (optionally) crisper on a set of sources.""" _vulcanize_rule(*args, pkg = PACKAGE_NAME, **kwargs) -def polygerrit_plugin(*args, **kwargs): - """Bundles plugin dependencies for deployment.""" - _vulcanize_rule(*args, pkg = PACKAGE_NAME, **kwargs) +def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs): + """Bundles plugin dependencies for deployment. + + This rule bundles all Polymer elements and JS dependencies into .html and .js files. + Run-time dependencies (e.g. JS libraries loaded after plugin starts) should be provided using "assets" property. + Output of this rule is a FileSet with "${name}_fs", with deploy artifacts in "plugins/${name}/static". + + Args: + name: String, plugin name. + app: String, the main or root source file. + assets: Fileset, additional files to be used by plugin in runtime, exported to "plugins/${name}/static". + srcs: Source files required for combining. + """ + + # Combines all .js and .html files into foo_combined.js and foo_combined.html + _vulcanize_rule(name = name + "_combined", app = app, srcs = srcs + [app], pkg = PACKAGE_NAME, **kwargs) + + closure_js_binary( + name = name + "_bin", + compilation_level = "SIMPLE", + defs = [ + "--polymer_version=1", + "--language_out=ECMASCRIPT6", + "--rewrite_polyfills=false", + ], + deps = [ + name + "_closure_lib", + ], + ) + + closure_js_library( + name = name + "_closure_lib", + srcs = [name + "_combined.js"], + convention = "GOOGLE", + no_closure_library = True, + deps = [ + "//lib/polymer_externs:polymer_closure", + "//polygerrit-ui/externs:plugin", + ], + ) + + native.genrule( + name = name + "_rename_html", + srcs = [name + "_combined.html"], + outs = [name + ".html"], + cmd = "sed 's/