summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorviktard <viktard@google.com>2018-10-22 14:39:46 -0700
committerPaladox none <thomasmulhall410@yahoo.com>2018-10-25 21:03:49 +0000
commit063bdc632d3bc523036fb62029ac37d4cffcc458 (patch)
tree60cad765160132c1b632b2e19d251ba6b55cd093
parentadbef6be8e788914a370464844e3d444645138dd (diff)
Update polygerrit_plugin() build rule
Add support for .js based plugins, custom plugin_name to prevent conflicts with server-side plugins with the same name. Here's an example: https://chromium-review.googlesource.com/c/infra/gerrit-plugins/landingwidget/+/1295049 So what we want to achieve is to have: gerrit_plugin( name = "landingwidget", [...] and polygerrit_plugin( name = "landingwidget_ui", plugin_name = "landingwidget", [...] and produce the following final artifacts: landingwidget.jar landingwidget.js Change-Id: Ic9c68809cbaaf4650301d98e56d7c1c76e008251 (cherry picked from commit 3c1139ee689ae0df4f99a6b6fd7575c994490c93)
-rw-r--r--tools/bzl/js.bzl76
1 files changed, 43 insertions, 33 deletions
diff --git a/tools/bzl/js.bzl b/tools/bzl/js.bzl
index 0997bcb8df..23d1ccd516 100644
--- a/tools/bzl/js.bzl
+++ b/tools/bzl/js.bzl
@@ -428,7 +428,7 @@ def bundle_assets(*args, **kwargs):
"""Combine html, js, css files and optionally split into js and html bundles."""
_bundle_rule(*args, pkg = native.package_name(), **kwargs)
-def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs):
+def polygerrit_plugin(name, app, srcs = [], assets = None, plugin_name = None, **kwargs):
"""Bundles plugin dependencies for deployment.
This rule bundles all Polymer elements and JS dependencies into .html and .js files.
@@ -436,19 +436,39 @@ def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs):
Output of this rule is a FileSet with "${name}_fs", with deploy artifacts in "plugins/${name}/static".
Args:
- name: String, plugin name.
+ name: String, rule 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.
+ plugin_name: String, plugin name. ${name} is used if not provided.
"""
+ if not plugin_name:
+ plugin_name = name
+
+ html_plugin = app.endswith(".html")
+ srcs = srcs if app in srcs else srcs + [app]
+
+ if html_plugin:
+ # Combines all .js and .html files into foo_combined.js and foo_combined.html
+ _bundle_rule(
+ name = name + "_combined",
+ app = app,
+ srcs = srcs,
+ pkg = native.package_name(),
+ **kwargs
+ )
+ js_srcs = [name + "_combined.js"]
+ else:
+ js_srcs = srcs
- # Combines all .js and .html files into foo_combined.js and foo_combined.html
- _bundle_rule(
- name = name + "_combined",
- app = app,
- srcs = srcs if app in srcs else srcs + [app],
- pkg = native.package_name(),
- **kwargs
+ closure_js_library(
+ name = name + "_closure_lib",
+ srcs = js_srcs,
+ convention = "GOOGLE",
+ no_closure_library = True,
+ deps = [
+ "//lib/polymer_externs:polymer_closure",
+ "//polygerrit-ui/app/externs:plugin",
+ ],
)
closure_js_binary(
@@ -464,37 +484,27 @@ def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs):
],
)
- 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/app/externs:plugin",
- ],
- )
-
- native.genrule(
- name = name + "_rename_html",
- srcs = [name + "_combined.html"],
- outs = [name + ".html"],
- cmd = "sed 's/<script src=\"" + name + "_combined.js\"/<script src=\"" + name + ".js\"/g' $(SRCS) > $(OUTS)",
- output_to_bindir = True,
- )
+ if html_plugin:
+ native.genrule(
+ name = name + "_rename_html",
+ srcs = [name + "_combined.html"],
+ outs = [plugin_name + ".html"],
+ cmd = "sed 's/<script src=\"" + name + "_combined.js\"/<script src=\"" + plugin_name + ".js\"/g' $(SRCS) > $(OUTS)",
+ output_to_bindir = True,
+ )
native.genrule(
name = name + "_rename_js",
srcs = [name + "_bin.js"],
- outs = [name + ".js"],
+ outs = [plugin_name + ".js"],
cmd = "cp $< $@",
output_to_bindir = True,
)
- static_files = [
- name + ".js",
- name + ".html",
- ]
+ if html_plugin:
+ static_files = [plugin_name + ".js", plugin_name + ".html"]
+ else:
+ static_files = [plugin_name + ".js"]
if assets:
nested, direct = [], []