Replace vulcanize with bundle_assets build rule

New rule uses polymer-bundler instead of deprecated vulcanize.
Also use this rule to package UI plugins.
Also for combining PolyGerrit UI.

Feature: Issue 7144
Change-Id: I17380c670fe4a980dc9748b356e7df18aebdb4ca
This commit is contained in:
Viktar Donich
2018-07-17 14:12:22 -07:00
parent 69d1808e49
commit ee7b2a218b
7 changed files with 47 additions and 39 deletions

View File

@@ -955,7 +955,7 @@ npm_binary(
) )
npm_binary( npm_binary(
name = "vulcanize", name = "polymer-bundler",
repository = GERRIT, repository = GERRIT,
) )

View File

@@ -456,7 +456,7 @@ public class StaticModule extends ServletModule {
// Special case assets during development that are built by Bazel and not // Special case assets during development that are built by Bazel and not
// served out of the source tree. // served out of the source tree.
// //
// In the war case, these are either inlined by vulcanize, or live under // In the war case, these are either inlined, or live under
// /polygerrit_ui in the war file, so we can just treat them as normal // /polygerrit_ui in the war file, so we can just treat them as normal
// assets. // assets.
if (paths.isDev()) { if (paths.isDev()) {

View File

@@ -1,11 +1,11 @@
NPM_VERSIONS = { NPM_VERSIONS = {
"bower": "1.8.2", "bower": "1.8.2",
"crisper": "2.0.2", "crisper": "2.0.2",
"vulcanize": "1.14.8", "polymer-bundler": "4.0.2",
} }
NPM_SHA1S = { NPM_SHA1S = {
"bower": "adf53529c8d4af02ef24fb8d5341c1419d33e2f7", "bower": "adf53529c8d4af02ef24fb8d5341c1419d33e2f7",
"crisper": "7183c58cea33632fb036c91cefd1b43e390d22a2", "crisper": "7183c58cea33632fb036c91cefd1b43e390d22a2",
"vulcanize": "679107f251c19ab7539529b1e3fdd40829e6fc63", "polymer-bundler": "6b296b6099ab5a0e93ca914cbe93e753f2395910",
} }

View File

@@ -3,8 +3,8 @@ load("@io_bazel_rules_closure//closure:defs.bzl", "closure_js_binary", "closure_
load( load(
"//tools/bzl:js.bzl", "//tools/bzl:js.bzl",
"bower_component", "bower_component",
"bundle_assets",
"js_component", "js_component",
"vulcanize",
) )
def polygerrit_bundle(name, srcs, outs, app): def polygerrit_bundle(name, srcs, outs, app):
@@ -41,7 +41,7 @@ def polygerrit_bundle(name, srcs, outs, app):
], ],
) )
vulcanize( bundle_assets(
name = appName, name = appName,
srcs = srcs, srcs = srcs,
app = app, app = app,

View File

@@ -286,38 +286,38 @@ bower_component_bundle = rule(
}, },
) )
"""Groups a set of bower components together in a zip file. def _bundle_impl(ctx):
"""Groups a set of .html and .js together in a zip file.
Outputs: Outputs:
NAME-versions.json: NAME-versions.json:
a JSON file containing a PKG-NAME => PKG-NAME#VERSION mapping for the a JSON file containing a PKG-NAME => PKG-NAME#VERSION mapping for the
transitive dependencies. transitive dependencies.
NAME.zip: NAME.zip:
a zip file containing the transitive dependencies for this bundle. a zip file containing the transitive dependencies for this bundle.
""" """
def _vulcanize_impl(ctx):
# intermediate artifact if split is wanted. # intermediate artifact if split is wanted.
if ctx.attr.split: if ctx.attr.split:
vulcanized = ctx.new_file( bundled = ctx.new_file(
ctx.configuration.genfiles_dir, ctx.configuration.genfiles_dir,
ctx.outputs.html, ctx.outputs.html,
".vulcanized.html", ".bundled.html",
) )
else: else:
vulcanized = ctx.outputs.html bundled = ctx.outputs.html
destdir = ctx.outputs.html.path + ".dir" destdir = ctx.outputs.html.path + ".dir"
zips = [z for d in ctx.attr.deps for z in d.transitive_zipfiles] zips = [z for d in ctx.attr.deps for z in d.transitive_zipfiles]
hermetic_npm_binary = " ".join([ hermetic_npm_binary = " ".join([
"python", "python",
"$p/" + ctx.file._run_npm.path, "$p/" + ctx.file._run_npm.path,
"$p/" + ctx.file._vulcanize_archive.path, "$p/" + ctx.file._bundler_archive.path,
"--inline-scripts", "--inline-scripts",
"--inline-css", "--inline-css",
"--strip-comments", "--strip-comments",
"--out-html", "--out-file",
"$p/" + vulcanized.path, "$p/" + bundled.path,
ctx.file.app.path, ctx.file.app.path,
]) ])
@@ -346,13 +346,13 @@ def _vulcanize_impl(ctx):
use_default_shell_env = True, use_default_shell_env = True,
) )
ctx.actions.run_shell( ctx.actions.run_shell(
mnemonic = "Vulcanize", mnemonic = "Bundle",
inputs = [ inputs = [
ctx.file._run_npm, ctx.file._run_npm,
ctx.file.app, ctx.file.app,
ctx.file._vulcanize_archive, ctx.file._bundler_archive,
] + list(zips) + ctx.files.srcs, ] + list(zips) + ctx.files.srcs,
outputs = [vulcanized], outputs = [bundled],
command = cmd, command = cmd,
**node_tweaks **node_tweaks
) )
@@ -364,7 +364,7 @@ def _vulcanize_impl(ctx):
ctx.file._crisper_archive.path, ctx.file._crisper_archive.path,
"--always-write-script", "--always-write-script",
"--source", "--source",
vulcanized.path, bundled.path,
"--html", "--html",
ctx.outputs.html.path, ctx.outputs.html.path,
"--js", "--js",
@@ -377,22 +377,22 @@ def _vulcanize_impl(ctx):
ctx.file._run_npm, ctx.file._run_npm,
ctx.file.app, ctx.file.app,
ctx.file._crisper_archive, ctx.file._crisper_archive,
vulcanized, bundled,
], ],
outputs = [ctx.outputs.js, ctx.outputs.html], outputs = [ctx.outputs.js, ctx.outputs.html],
command = hermetic_npm_command, command = hermetic_npm_command,
**node_tweaks **node_tweaks
) )
def _vulcanize_output_func(name, split): def _bundle_output_func(name, split):
_ignore = [name] # unused. _ignore = [name] # unused.
out = {"html": "%{name}.html"} out = {"html": "%{name}.html"}
if split: if split:
out["js"] = "%{name}.js" out["js"] = "%{name}.js"
return out return out
_vulcanize_rule = rule( _bundle_rule = rule(
_vulcanize_impl, _bundle_impl,
attrs = { attrs = {
"deps": attr.label_list(providers = ["transitive_zipfiles"]), "deps": attr.label_list(providers = ["transitive_zipfiles"]),
"app": attr.label( "app": attr.label(
@@ -412,8 +412,8 @@ _vulcanize_rule = rule(
default = Label("//tools/js:run_npm_binary.py"), default = Label("//tools/js:run_npm_binary.py"),
allow_single_file = True, allow_single_file = True,
), ),
"_vulcanize_archive": attr.label( "_bundler_archive": attr.label(
default = Label("@vulcanize//:%s" % _npm_tarball("vulcanize")), default = Label("@polymer-bundler//:%s" % _npm_tarball("polymer-bundler")),
allow_single_file = True, allow_single_file = True,
), ),
"_crisper_archive": attr.label( "_crisper_archive": attr.label(
@@ -421,12 +421,12 @@ _vulcanize_rule = rule(
allow_single_file = True, allow_single_file = True,
), ),
}, },
outputs = _vulcanize_output_func, outputs = _bundle_output_func,
) )
def vulcanize(*args, **kwargs): def bundle_assets(*args, **kwargs):
"""Vulcanize runs vulcanize and (optionally) crisper on a set of sources.""" """Combine html, js, css files and optionally split into js and html bundles."""
_vulcanize_rule(*args, pkg = PACKAGE_NAME, **kwargs) _bundle_rule(*args, pkg = PACKAGE_NAME, **kwargs)
def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs): def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs):
"""Bundles plugin dependencies for deployment. """Bundles plugin dependencies for deployment.
@@ -443,7 +443,7 @@ def polygerrit_plugin(name, app, srcs = [], assets = None, **kwargs):
""" """
# Combines all .js and .html files into foo_combined.js and foo_combined.html # Combines all .js and .html files into foo_combined.js and foo_combined.html
_vulcanize_rule( _bundle_rule(
name = name + "_combined", name = name + "_combined",
app = app, app = app,
srcs = srcs if app in srcs else srcs + [app], srcs = srcs if app in srcs else srcs + [app],

View File

@@ -56,7 +56,8 @@ def extract(path, outdir, bin):
extract_one(mem) extract_one(mem)
# Extract bin last so other processes only short circuit when # Extract bin last so other processes only short circuit when
# extraction is finished. # extraction is finished.
extract_one(tar.getmember(bin)) if bin in tar.getnames():
extract_one(tar.getmember(bin))
def main(args): def main(args):
@@ -77,7 +78,9 @@ def main(args):
sha1 = hashlib.sha1(open(path, 'rb').read()).hexdigest() sha1 = hashlib.sha1(open(path, 'rb').read()).hexdigest()
outdir = '%s-%s' % (path[:-len(suffix)], sha1) outdir = '%s-%s' % (path[:-len(suffix)], sha1)
rel_bin = os.path.join('package', 'bin', name) rel_bin = os.path.join('package', 'bin', name)
rel_lib_bin = os.path.join('package', 'lib', 'bin', name + '.js')
bin = os.path.join(outdir, rel_bin) bin = os.path.join(outdir, rel_bin)
libbin = os.path.join(outdir, rel_lib_bin)
if not os.path.isfile(bin): if not os.path.isfile(bin):
extract(path, outdir, rel_bin) extract(path, outdir, rel_bin)
@@ -85,7 +88,12 @@ def main(args):
if nodejs: if nodejs:
# Debian installs Node.js as 'nodejs', due to a conflict with another # Debian installs Node.js as 'nodejs', due to a conflict with another
# package. # package.
subprocess.check_call([nodejs, bin] + args[1:]) if not os.path.isfile(bin) and os.path.isfile(libbin):
subprocess.check_call([nodejs, libbin] + args[1:])
else:
subprocess.check_call([nodejs, bin] + args[1:])
elif not os.path.isfile(bin) and os.path.isfile(libbin):
subprocess.check_call([libbin] + args[1:])
else: else:
subprocess.check_call([bin] + args[1:]) subprocess.check_call([bin] + args[1:])