Merge "Upgrade polygerrit_plugin rule"

This commit is contained in:
viktard 2018-07-11 21:37:33 +00:00 committed by Gerrit Code Review
commit 39dc9ab6af
4 changed files with 146 additions and 11 deletions

@ -1 +1 @@
Subproject commit 53dccff17c029459999ff70ac886b80626af634b
Subproject commit 318504d0eb74f2f9c2967e9865ace6d5b57638c6

View File

@ -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,
)

View File

@ -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) {};

View File

@ -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/<script src=\"" + name + "_combined.js\"/<script src=\"" + name + ".js\"/g' $(SRCS) > $(OUTS)",
output_to_bindir = True,
)
native.genrule(
name = name + "_rename_js",
srcs = [name + "_bin.js"],
outs = [name + ".js"],
cmd = "cp $< $@",
output_to_bindir = True,
)
static_files = [
name + ".js",
name + ".html",
]
if assets:
nested, direct = [], []
for x in assets:
target = nested if "/" in x else direct
target.append(x)
static_files += direct
if nested:
native.genrule(
name = name + "_copy_assets",
srcs = assets,
outs = [f.split("/")[-1] for f in nested],
cmd = "cp $(SRCS) $(@D)",
output_to_bindir = True,
)
static_files += [":" + name + "_copy_assets"]
native.filegroup(
name = name,
srcs = static_files,
)