Bazel: Remove bower
The only core plugin: codemirror-editor that is still using bower
toolchain was migrated to rules_nodejs in: Ib0114d9ab3e.
Non core plugins should add the dependencies in plugin's package.json
and then link that file to plugins/package.json in gerrit.
Change-Id: I22307a6cb9bf1d65a194f3c07c49c20fa13da83f
diff --git a/WORKSPACE b/WORKSPACE
index 0d9b06a..6c01d03 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -976,197 +976,6 @@
yarn_lock = "//:plugins/yarn.lock",
)
-load("//tools/bzl:js.bzl", "bower_archive", "npm_binary")
-
-# NPM binaries bundled along with their dependencies.
-#
-# For full instructions on adding new binaries to the build, see
-# http://gerrit-review.googlesource.com/Documentation/dev-bazel.html#npm-binary
-npm_binary(
- name = "bower",
-)
-
-npm_binary(
- name = "polymer-bundler",
- repository = GERRIT,
-)
-
-npm_binary(
- name = "crisper",
- repository = GERRIT,
-)
-
-# bower_archive() seed components.
-bower_archive(
- name = "iron-autogrow-textarea",
- package = "polymerelements/iron-autogrow-textarea",
- sha1 = "2f04c7e2a72d462de36093ab2b4889db20f699f6",
- version = "2.2.0",
-)
-
-bower_archive(
- name = "es6-promise",
- package = "stefanpenner/es6-promise",
- sha1 = "a3a797bb22132f1ef75f9a2556173f81870c2e53",
- version = "3.3.0",
-)
-
-bower_archive(
- name = "fetch",
- package = "fetch",
- sha1 = "1b05a2bb40c73232c2909dc196de7519fe4db7a9",
- version = "1.0.0",
-)
-
-bower_archive(
- name = "iron-dropdown",
- package = "polymerelements/iron-dropdown",
- sha1 = "3902ba164552b1bfc59e6fa692efa4a1fd8dd4ea",
- version = "2.2.1",
-)
-
-bower_archive(
- name = "iron-input",
- package = "polymerelements/iron-input",
- sha1 = "f79952ff4f6f103c0a2cbd3dacf25935257ff392",
- version = "2.1.3",
-)
-
-bower_archive(
- name = "iron-overlay-behavior",
- package = "polymerelements/iron-overlay-behavior",
- sha1 = "c2d2eac1b162420d9475ade2f16d5db8959b93fc",
- version = "2.3.4",
-)
-
-bower_archive(
- name = "iron-selector",
- package = "polymerelements/iron-selector",
- sha1 = "3f3fcb55f6bd606ea493f99eab9daae21f7a6139",
- version = "2.1.0",
-)
-
-bower_archive(
- name = "paper-button",
- package = "polymerelements/paper-button",
- sha1 = "bcb783d74e1177c1d0836340e7c0280699d1438c",
- version = "2.1.3",
-)
-
-bower_archive(
- name = "paper-input",
- package = "polymerelements/paper-input",
- sha1 = "c1a81a4173d22e72e8ab609eb3715a75273396b3",
- version = "2.2.3",
-)
-
-bower_archive(
- name = "paper-tabs",
- package = "polymerelements/paper-tabs",
- sha1 = "589b8e6efa0f171c93233137c8ea013dcea0ffc7",
- version = "2.1.1",
-)
-
-bower_archive(
- name = "iron-icon",
- package = "polymerelements/iron-icon",
- sha1 = "d21e7d4f1bdc6de881390f888e28d53155eeb551",
- version = "2.1.0",
-)
-
-bower_archive(
- name = "iron-iconset-svg",
- package = "polymerelements/iron-iconset-svg",
- sha1 = "07c0ce02ce6479856758893416a3709009db7f22",
- version = "2.2.1",
-)
-
-bower_archive(
- name = "moment",
- package = "moment/moment",
- sha1 = "fc8ce2c799bab21f6ced7aff928244f4ca8880aa",
- version = "2.13.0",
-)
-
-bower_archive(
- name = "page",
- package = "visionmedia/page.js",
- sha1 = "4a31889cd75cc5e7f68a4c7f256eecaf27102eee",
- version = "1.11.4",
-)
-
-bower_archive(
- name = "paper-item",
- package = "polymerelements/paper-item",
- sha1 = "c3bad022cf182d2bf1c8a44374c7fcb1409afbfa",
- version = "2.1.1",
-)
-
-bower_archive(
- name = "paper-listbox",
- package = "polymerelements/paper-listbox",
- sha1 = "78247cc32bb776f204efef17cff3095878036a40",
- version = "2.1.1",
-)
-
-bower_archive(
- name = "paper-toggle-button",
- package = "polymerelements/paper-toggle-button",
- sha1 = "9927960afb0062726ec1b585ef3e32764c3bbac9",
- version = "2.1.1",
-)
-
-bower_archive(
- name = "polymer",
- package = "polymer/polymer",
- sha1 = "d06e17a1d8dc6187ee5aa8c5b3501da10901c82f",
- version = "2.7.2",
-)
-
-bower_archive(
- name = "polymer-resin",
- package = "polymer/polymer-resin",
- sha1 = "94c29926c20ea3a9b636f26b3e0d689ead8137e5",
- version = "2.0.1",
-)
-
-bower_archive(
- name = "resemblejs",
- package = "rsmbl/Resemble.js",
- sha1 = "49d5f022417c389b630d6f7ee667aa9540075c42",
- version = "2.10.1",
-)
-
-bower_archive(
- name = "codemirror-minified",
- package = "Dominator008/codemirror-minified",
- sha1 = "a1ddf3a6dcc6817597eacc52688cfe5083ded4cd",
- version = "5.59.1",
-)
-
-# bower test stuff
-
-bower_archive(
- name = "iron-test-helpers",
- package = "polymerelements/iron-test-helpers",
- sha1 = "882be2d4c8714b39299b5f7bf25253c4e8a40761",
- version = "2.0.1",
-)
-
-bower_archive(
- name = "test-fixture",
- package = "polymerelements/test-fixture",
- sha1 = "7d72ddfebf555a2dd1fc60a85427d9026b509723",
- version = "3.0.0",
-)
-
-bower_archive(
- name = "web-component-tester",
- package = "polymer/web-component-tester",
- sha1 = "d84f6a13bde5f8fd39ee208d43f33925410530d7",
- version = "6.5.1",
-)
-
external_plugin_deps()
# When upgrading elasticsearch-rest-client, also upgrade httpcore-nio
diff --git a/lib/LICENSE-codemirror-minified b/lib/LICENSE-codemirror-minified
deleted file mode 100644
index 89f23625..0000000
--- a/lib/LICENSE-codemirror-minified
+++ /dev/null
@@ -1,22 +0,0 @@
-The MIT License (MIT)
-
-Copyright (c) 2016 Marijn Haverbeke <marijnh@gmail.com> and others
-Copyright (c) 2016 Michael Zhou <zhoumotongxue008@gmail.com>
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
-SOFTWARE.
diff --git a/lib/LICENSE-resemblejs b/lib/LICENSE-resemblejs
deleted file mode 100644
index b265c8a..0000000
--- a/lib/LICENSE-resemblejs
+++ /dev/null
@@ -1,18 +0,0 @@
-The MIT License (MIT) Copyright © 2013 Huddle
-
-Permission is hereby granted, free of charge, to any person obtaining a copy of
-this software and associated documentation files (the “Software”), to deal in
-the Software without restriction, including without limitation the rights to
-use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
-the Software, and to permit persons to whom the Software is furnished to do so,
-subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in all
-copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
-FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
-COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
-IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
-CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/lib/js/BUILD b/lib/js/BUILD
index 106aabb..82089bd 100644
--- a/lib/js/BUILD
+++ b/lib/js/BUILD
@@ -1,4 +1,4 @@
-load("//tools/bzl:js.bzl", "bower_component", "js_component")
+load("//tools/bzl:js.bzl", "js_component")
package(default_visibility = ["//visibility:public"])
@@ -22,15 +22,3 @@
srcs = ["//lib/ba-linkify:ba-linkify.js"],
license = "//lib:LICENSE-ba-linkify",
)
-
-##TODO: remove after plugins migration to npm
-bower_component(
- name = "codemirror-minified",
- license = "//lib:LICENSE-codemirror-minified",
-)
-
-bower_component(
- name = "resemblejs",
- license = "//lib:LICENSE-resemblejs",
-)
-#End of removal
diff --git a/lib/js/npm.bzl b/lib/js/npm.bzl
deleted file mode 100644
index 5a6a8c0..0000000
--- a/lib/js/npm.bzl
+++ /dev/null
@@ -1,11 +0,0 @@
-NPM_VERSIONS = {
- "bower": "1.8.8",
- "crisper": "2.0.2",
- "polymer-bundler": "4.0.9",
-}
-
-NPM_SHA1S = {
- "bower": "82544be34a33aeae7efb8bdf9905247b2cffa985",
- "crisper": "7183c58cea33632fb036c91cefd1b43e390d22a2",
- "polymer-bundler": "c80c9815690d76656d1fa6a231481850b4fa3874",
-}
diff --git a/plugins/codemirror-editor b/plugins/codemirror-editor
index 7c94eb2..42d5fe0 160000
--- a/plugins/codemirror-editor
+++ b/plugins/codemirror-editor
@@ -1 +1 @@
-Subproject commit 7c94eb2fd3cdea33a200ae7c73c19777ca865a41
+Subproject commit 42d5fe041ee2ef6be579c0085396fa5e60889222
diff --git a/tools/bzl/js.bzl b/tools/bzl/js.bzl
index b09454c..7c63cc3 100644
--- a/tools/bzl/js.bzl
+++ b/tools/bzl/js.bzl
@@ -1,167 +1,9 @@
load("@npm//@bazel/rollup:index.bzl", "rollup_bundle")
load("@npm//@bazel/terser:index.bzl", "terser_minified")
-load("//lib/js:npm.bzl", "NPM_SHA1S", "NPM_VERSIONS")
load("//tools/bzl:genrule2.bzl", "genrule2")
-NPMJS = "NPMJS"
-
-GERRIT = "GERRIT:"
-
-def _npm_tarball(name):
- return "%s@%s.npm_binary.tgz" % (name, NPM_VERSIONS[name])
-
-def _npm_binary_impl(ctx):
- """rule to download a NPM archive."""
- name = ctx.name
- version = NPM_VERSIONS[name]
- sha1 = NPM_SHA1S[name]
-
- dir = "%s-%s" % (name, version)
- filename = "%s.tgz" % dir
- base = "%s@%s.npm_binary.tgz" % (name, version)
- dest = ctx.path(base)
- repository = ctx.attr.repository
- if repository == GERRIT:
- url = "https://gerrit-maven.storage.googleapis.com/npm-packages/%s" % filename
- elif repository == NPMJS:
- url = "https://registry.npmjs.org/%s/-/%s" % (name, filename)
- else:
- fail("repository %s not in {%s,%s}" % (repository, GERRIT, NPMJS))
-
- python = ctx.which("python3")
- script = ctx.path(ctx.attr._download_script)
-
- args = [python, script, "-o", dest, "-u", url, "-v", sha1]
- out = ctx.execute(args)
- if out.return_code:
- fail("failed %s: %s" % (args, out.stderr))
- ctx.file("BUILD", "package(default_visibility=['//visibility:public'])\nfilegroup(name='tarball', srcs=['%s'])" % base, False)
-
-npm_binary = repository_rule(
- attrs = {
- "repository": attr.string(default = NPMJS),
- # Label resolves within repo of the .bzl file.
- "_download_script": attr.label(default = Label("//tools:download_file.py")),
- },
- local = True,
- implementation = _npm_binary_impl,
-)
-
ComponentInfo = provider()
-# for use in repo rules.
-def _run_npm_binary_str(ctx, tarball, args):
- python_bin = ctx.which("python3")
- return " ".join([
- str(python_bin),
- str(ctx.path(ctx.attr._run_npm)),
- str(ctx.path(tarball)),
- ] + args)
-
-def _bower_archive(ctx):
- """Download a bower package."""
- download_name = "%s__download_bower.zip" % ctx.name
- renamed_name = "%s__renamed.zip" % ctx.name
- version_name = "%s__version.json" % ctx.name
-
- cmd = [
- ctx.which("python3"),
- ctx.path(ctx.attr._download_bower),
- "-b",
- "%s" % _run_npm_binary_str(ctx, ctx.attr._bower_archive, []),
- "-n",
- ctx.name,
- "-p",
- ctx.attr.package,
- "-v",
- ctx.attr.version,
- "-s",
- ctx.attr.sha1,
- "-o",
- download_name,
- ]
-
- out = ctx.execute(cmd)
- if out.return_code:
- fail("failed %s: %s" % (cmd, out.stderr))
-
- _bash(ctx, " && ".join([
- "TMP=$(mktemp -d || mktemp -d -t bazel-tmp)",
- "TZ=UTC",
- "export UTC",
- "cd $TMP",
- "mkdir bower_components",
- "cd bower_components",
- "unzip %s" % ctx.path(download_name),
- "cd ..",
- "find . -exec touch -t 198001010000 '{}' ';'",
- "zip -Xr %s bower_components" % renamed_name,
- "cd ..",
- "rm -rf ${TMP}",
- ]))
-
- dep_version = ctx.attr.semver if ctx.attr.semver else ctx.attr.version
- ctx.file(
- version_name,
- '"%s":"%s#%s"' % (ctx.name, ctx.attr.package, dep_version),
- )
- ctx.file(
- "BUILD",
- "\n".join([
- "package(default_visibility=['//visibility:public'])",
- "filegroup(name = 'zipfile', srcs = ['%s'], )" % download_name,
- "filegroup(name = 'version_json', srcs = ['%s'], visibility=['//visibility:public'])" % version_name,
- ]),
- False,
- )
-
-def _bash(ctx, cmd):
- cmd_list = ["bash", "-c", cmd]
- out = ctx.execute(cmd_list)
- if out.return_code:
- fail("failed %s: %s" % (cmd_list, out.stderr))
-
-bower_archive = repository_rule(
- _bower_archive,
- attrs = {
- "package": attr.string(mandatory = True),
- "semver": attr.string(),
- "sha1": attr.string(mandatory = True),
- "version": attr.string(mandatory = True),
- "_bower_archive": attr.label(default = Label("@bower//:%s" % _npm_tarball("bower"))),
- "_download_bower": attr.label(default = Label("//tools/js:download_bower.py")),
- "_run_npm": attr.label(default = Label("//tools/js:run_npm_binary.py")),
- },
-)
-
-def _bower_component_impl(ctx):
- transitive_zipfiles = depset(
- direct = [ctx.file.zipfile],
- transitive = [d[ComponentInfo].transitive_zipfiles for d in ctx.attr.deps],
- )
-
- transitive_licenses = depset(
- direct = [ctx.file.license],
- transitive = [d[ComponentInfo].transitive_licenses for d in ctx.attr.deps],
- )
-
- transitive_versions = depset(
- direct = ctx.files.version_json,
- transitive = [d[ComponentInfo].transitive_versions for d in ctx.attr.deps],
- )
-
- return [
- ComponentInfo(
- transitive_licenses = transitive_licenses,
- transitive_versions = transitive_versions,
- transitive_zipfiles = transitive_zipfiles,
- ),
- ]
-
-_common_attrs = {
- "deps": attr.label_list(providers = [ComponentInfo]),
-}
-
def _js_component(ctx):
dir = ctx.outputs.zip.path + ".dir"
name = ctx.outputs.zip.basename
@@ -182,7 +24,7 @@
inputs = ctx.files.srcs,
outputs = [ctx.outputs.zip],
command = cmd,
- mnemonic = "GenBowerZip",
+ mnemonic = "GenJsComponentZip",
)
licenses = []
@@ -199,248 +41,15 @@
js_component = rule(
_js_component,
- attrs = dict(_common_attrs.items() + {
+ attrs = {
"srcs": attr.label_list(allow_files = [".js"]),
"license": attr.label(allow_single_file = True),
- }.items()),
+ },
outputs = {
"zip": "%{name}.zip",
},
)
-_bower_component = rule(
- _bower_component_impl,
- attrs = dict(_common_attrs.items() + {
- "license": attr.label(allow_single_file = True),
-
- # If set, define by hand, and don't regenerate this entry in bower2bazel.
- "seed": attr.bool(default = False),
- "version_json": attr.label(allow_files = [".json"]),
- "zipfile": attr.label(allow_single_file = [".zip"]),
- }.items()),
-)
-
-# TODO(hanwen): make license mandatory.
-def bower_component(name, license = None, **kwargs):
- prefix = "//lib:LICENSE-"
- if license and not license.startswith(prefix):
- license = prefix + license
- _bower_component(
- name = name,
- license = license,
- zipfile = "@%s//:zipfile" % name,
- version_json = "@%s//:version_json" % name,
- **kwargs
- )
-
-def _bower_component_bundle_impl(ctx):
- """A bunch of bower components zipped up."""
- zips = depset()
- for d in ctx.attr.deps:
- files = d[ComponentInfo].transitive_zipfiles
-
- # TODO(davido): Make sure the field always contains a depset
- if type(files) == "list":
- files = depset(files)
- zips = depset(transitive = [zips, files])
-
- versions = depset(transitive = [d[ComponentInfo].transitive_versions for d in ctx.attr.deps])
-
- licenses = depset(transitive = [d[ComponentInfo].transitive_versions for d in ctx.attr.deps])
-
- out_zip = ctx.outputs.zip
- out_versions = ctx.outputs.version_json
-
- ctx.actions.run_shell(
- inputs = zips.to_list(),
- outputs = [out_zip],
- command = " && ".join([
- "p=$PWD",
- "TZ=UTC",
- "export TZ",
- "rm -rf %s.dir" % out_zip.path,
- "mkdir -p %s.dir/bower_components" % out_zip.path,
- "cd %s.dir/bower_components" % out_zip.path,
- "for z in %s; do unzip -q $p/$z ; done" % " ".join(sorted([z.path for z in zips.to_list()])),
- "cd ..",
- "find . -exec touch -t 198001010000 '{}' ';'",
- "zip -Xqr $p/%s bower_components/*" % out_zip.path,
- ]),
- mnemonic = "BowerCombine",
- )
-
- ctx.actions.run_shell(
- inputs = versions.to_list(),
- outputs = [out_versions],
- mnemonic = "BowerVersions",
- command = "(echo '{' ; for j in %s ; do cat $j; echo ',' ; done ; echo \\\"\\\":\\\"\\\"; echo '}') > %s" % (" ".join([v.path for v in versions.to_list()]), out_versions.path),
- )
-
- return [
- ComponentInfo(
- transitive_licenses = licenses,
- transitive_versions = versions,
- transitive_zipfiles = zips,
- ),
- ]
-
-bower_component_bundle = rule(
- _bower_component_bundle_impl,
- attrs = _common_attrs,
- outputs = {
- "version_json": "%{name}-versions.json",
- "zip": "%{name}.zip",
- },
-)
-
-def _bundle_impl(ctx):
- """Groups a set of .html and .js together in a zip file.
-
- Outputs:
- NAME-versions.json:
- a JSON file containing a PKG-NAME => PKG-NAME#VERSION mapping for the
- transitive dependencies.
- NAME.zip:
- a zip file containing the transitive dependencies for this bundle.
- """
-
- # intermediate artifact if split is wanted.
- if ctx.attr.split:
- bundled = ctx.actions.declare_file(ctx.outputs.html.path + ".bundled.html")
- else:
- bundled = ctx.outputs.html
- destdir = ctx.outputs.html.path + ".dir"
- zips = [z for d in ctx.attr.deps for z in d[ComponentInfo].transitive_zipfiles.to_list()]
-
- # We are splitting off the package dir from the app.path such that
- # we can set the package dir as the root for the bundler, which means
- # that absolute imports are interpreted relative to that root.
- pkg_dir = ctx.attr.pkg.lstrip("/")
- app_path = ctx.file.app.path
- app_path = app_path[app_path.index(pkg_dir) + len(pkg_dir):]
-
- hermetic_npm_binary = " ".join([
- "python3",
- "$p/" + ctx.file._run_npm.path,
- "$p/" + ctx.file._bundler_archive.path,
- "--inline-scripts",
- "--inline-css",
- "--sourcemaps",
- "--strip-comments",
- "--out-file",
- "$p/" + bundled.path,
- "--root",
- pkg_dir,
- app_path,
- ])
-
- cmd = " && ".join([
- # unpack dependencies.
- "export PATH",
- "p=$PWD",
- "rm -rf %s" % destdir,
- "mkdir -p %s/%s/bower_components" % (destdir, pkg_dir),
- "for z in %s; do unzip -qd %s/%s/bower_components/ $z; done" % (
- " ".join([z.path for z in zips]),
- destdir,
- pkg_dir,
- ),
- "tar -cf - %s | tar -C %s -xf -" % (" ".join([s.path for s in ctx.files.srcs]), destdir),
- "cd %s" % destdir,
- hermetic_npm_binary,
- ])
-
- # Node/NPM is not (yet) hermeticized, so we have to get the binary
- # from the environment, and it may be under $HOME, so we can't run
- # in the sandbox.
- node_tweaks = dict(
- execution_requirements = {"local": "1"},
- use_default_shell_env = True,
- )
- ctx.actions.run_shell(
- mnemonic = "Bundle",
- inputs = [
- ctx.file._run_npm,
- ctx.file.app,
- ctx.file._bundler_archive,
- ] + list(zips) + ctx.files.srcs,
- outputs = [bundled],
- command = cmd,
- **node_tweaks
- )
-
- if ctx.attr.split:
- hermetic_npm_command = "export PATH && " + " ".join([
- "python3",
- ctx.file._run_npm.path,
- ctx.file._crisper_archive.path,
- "--script-in-head=false",
- "--always-write-script",
- "--source",
- bundled.path,
- "--html",
- ctx.outputs.html.path,
- "--js",
- ctx.outputs.js.path,
- ])
-
- ctx.actions.run_shell(
- mnemonic = "Crisper",
- inputs = [
- ctx.file._run_npm,
- ctx.file.app,
- ctx.file._crisper_archive,
- bundled,
- ],
- outputs = [ctx.outputs.js, ctx.outputs.html],
- command = hermetic_npm_command,
- **node_tweaks
- )
-
-def _bundle_output_func(name, split):
- _ignore = [name] # unused.
- out = {"html": "%{name}.html"}
- if split:
- out["js"] = "%{name}.js"
- return out
-
-_bundle_rule = rule(
- _bundle_impl,
- attrs = {
- "srcs": attr.label_list(allow_files = [
- ".js",
- ".html",
- ".txt",
- ".css",
- ".ico",
- ]),
- "app": attr.label(
- mandatory = True,
- allow_single_file = True,
- ),
- "pkg": attr.string(mandatory = True),
- "split": attr.bool(default = True),
- "deps": attr.label_list(providers = [ComponentInfo]),
- "_bundler_archive": attr.label(
- default = Label("@polymer-bundler//:%s" % _npm_tarball("polymer-bundler")),
- allow_single_file = True,
- ),
- "_crisper_archive": attr.label(
- default = Label("@crisper//:%s" % _npm_tarball("crisper")),
- allow_single_file = True,
- ),
- "_run_npm": attr.label(
- default = Label("//tools/js:run_npm_binary.py"),
- allow_single_file = True,
- ),
- },
- outputs = _bundle_output_func,
-)
-
-def bundle_assets(*args, **kwargs):
- """Combine html, js, css files and optionally split into js and html bundles."""
- _bundle_rule(pkg = native.package_name(), *args, **kwargs)
-
def polygerrit_plugin(name, app, plugin_name = None):
"""Produces plugin file set with minified javascript.
diff --git a/tools/js/BUILD b/tools/js/BUILD
index 1a272e2..d696496 100644
--- a/tools/js/BUILD
+++ b/tools/js/BUILD
@@ -1 +1 @@
-exports_files(["run_npm_binary.py", "eslint-chdir.js"])
+exports_files(["eslint-chdir.js"])
diff --git a/tools/js/bowerutil.py b/tools/js/bowerutil.py
deleted file mode 100644
index 9fb82af..0000000
--- a/tools/js/bowerutil.py
+++ /dev/null
@@ -1,46 +0,0 @@
-# Copyright (C) 2013 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.
-
-import os
-
-
-def hash_bower_component(hash_obj, path):
- """Hash the contents of a bower component directory.
-
- This is a stable hash of a directory downloaded with `bower install`, minus
- the .bower.json file, which is autogenerated each time by bower. Used in
- lieu of hashing a zipfile of the contents, since zipfiles are difficult to
- hash in a stable manner.
-
- Args:
- hash_obj: an open hash object, e.g. hashlib.sha1().
- path: path to the directory to hash.
-
- Returns:
- The passed-in hash_obj.
- """
- if not os.path.isdir(path):
- raise ValueError('Not a directory: %s' % path)
-
- path = os.path.abspath(path)
- for root, dirs, files in os.walk(path):
- dirs.sort()
- for f in sorted(files):
- if f == '.bower.json':
- continue
- p = os.path.join(root, f)
- hash_obj.update(p[len(path)+1:].encode("utf-8"))
- hash_obj.update(open(p, "rb").read())
-
- return hash_obj
diff --git a/tools/js/download_bower.py b/tools/js/download_bower.py
deleted file mode 100755
index 7cf40e1..0000000
--- a/tools/js/download_bower.py
+++ /dev/null
@@ -1,135 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (C) 2015 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.
-
-from __future__ import print_function
-
-import argparse
-import hashlib
-import json
-import os
-import shutil
-import subprocess
-import sys
-
-import bowerutil
-
-CACHE_DIR = os.path.expanduser(os.path.join(
- '~', '.gerritcodereview', 'bazel-cache', 'downloaded-artifacts'))
-
-
-def bower_cmd(bower, *args):
- cmd = bower.split(' ')
- cmd.extend(args)
- return cmd
-
-
-def bower_info(bower, name, package, version):
- cmd = bower_cmd(bower, '-l=error', '-j',
- 'info', '%s#%s' % (package, version))
- try:
- p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
- except:
- sys.stderr.write("error executing: %s\n" % ' '.join(cmd))
- raise
- out, err = p.communicate()
- if p.returncode:
- # For python3 support we wrap str around err.
- sys.stderr.write(str(err))
- raise OSError('Command failed: %s' % ' '.join(cmd))
-
- try:
- info = json.loads(out)
- except ValueError:
- raise ValueError('invalid JSON from %s:\n%s' % (" ".join(cmd), out))
- info_name = info.get('name')
- if info_name != name:
- raise ValueError(
- 'expected package name %s, got: %s' % (name, info_name))
- return info
-
-
-def ignore_deps(info):
- # Tell bower to ignore dependencies so we just download this component.
- # This is just an optimization, since we only pick out the component we
- # need, but it's important when downloading sizable dependency trees.
- #
- # As of 1.6.5 I don't think ignoredDependencies can be specified on the
- # command line with --config, so we have to create .bowerrc.
- deps = info.get('dependencies')
- if deps:
- with open(os.path.join('.bowerrc'), 'w') as f:
- json.dump({'ignoredDependencies': list(deps.keys())}, f)
-
-
-def cache_entry(name, package, version, sha1):
- if not sha1:
- sha1 = hashlib.sha1('%s#%s' % (package, version)).hexdigest()
- return os.path.join(CACHE_DIR, '%s-%s.zip-%s' % (name, version, sha1))
-
-
-def main():
- parser = argparse.ArgumentParser()
- parser.add_argument('-n', help='short name of component')
- parser.add_argument('-b', help='bower command')
- parser.add_argument('-p', help='full package name of component')
- parser.add_argument('-v', help='version number')
- parser.add_argument('-s', help='expected content sha1')
- parser.add_argument('-o', help='output file location')
- args = parser.parse_args()
-
- assert args.p
- assert args.v
- assert args.n
-
- cwd = os.getcwd()
- outzip = os.path.join(cwd, args.o)
- cached = cache_entry(args.n, args.p, args.v, args.s)
-
- if not os.path.exists(cached):
- info = bower_info(args.b, args.n, args.p, args.v)
- ignore_deps(info)
- subprocess.check_call(
- bower_cmd(
- args.b, '--quiet', 'install', '%s#%s' % (args.p, args.v)))
- bc = os.path.join(cwd, 'bower_components')
- subprocess.check_call(
- ['zip', '-q', '--exclude', '.bower.json', '-r', cached, args.n],
- cwd=bc)
-
- if args.s:
- path = os.path.join(bc, args.n)
- sha1 = bowerutil.hash_bower_component(
- hashlib.sha1(), path).hexdigest()
- if args.s != sha1:
- print((
- '%s#%s:\n'
- 'expected %s\n'
- 'received %s\n') % (args.p, args.v, args.s, sha1),
- file=sys.stderr)
- try:
- os.remove(cached)
- except OSError as err:
- if path.exists(cached):
- print('error removing %s: %s' % (cached, err),
- file=sys.stderr)
- return 1
-
- shutil.copyfile(cached, outzip)
- return 0
-
-
-if __name__ == '__main__':
- sys.exit(main())
diff --git a/tools/js/run_npm_binary.py b/tools/js/run_npm_binary.py
deleted file mode 100644
index 31f8a54..0000000
--- a/tools/js/run_npm_binary.py
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/usr/bin/env python3
-# Copyright (C) 2015 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.
-
-from __future__ import print_function
-
-import atexit
-from distutils import spawn
-import hashlib
-import os
-import shutil
-import subprocess
-import sys
-import tarfile
-import tempfile
-
-
-def extract(path, outdir, bin):
- if os.path.exists(os.path.join(outdir, bin)):
- return # Another process finished extracting, ignore.
-
- # Use a temp directory adjacent to outdir so shutil.move can use the same
- # device atomically.
- tmpdir = tempfile.mkdtemp(dir=os.path.dirname(outdir))
-
- def cleanup():
- try:
- shutil.rmtree(tmpdir)
- except OSError:
- pass # Too late now
- atexit.register(cleanup)
-
- def extract_one(mem):
- dest = os.path.join(outdir, mem.name)
- tar.extract(mem, path=tmpdir)
- try:
- os.makedirs(os.path.dirname(dest))
- except OSError:
- pass # Either exists, or will fail on the next line.
- shutil.move(os.path.join(tmpdir, mem.name), dest)
-
- with tarfile.open(path, 'r:gz') as tar:
- for mem in tar.getmembers():
- if mem.name != bin:
- extract_one(mem)
- # Extract bin last so other processes only short circuit when
- # extraction is finished.
- if bin in tar.getnames():
- extract_one(tar.getmember(bin))
-
-
-def main(args):
- path = args[0]
- suffix = '.npm_binary.tgz'
- tgz = os.path.basename(path)
-
- parts = tgz[:-len(suffix)].split('@')
-
- if not tgz.endswith(suffix) or len(parts) != 2:
- print('usage: %s <path/to/npm_binary>' % sys.argv[0], file=sys.stderr)
- return 1
-
- name, _ = parts
-
- # Avoid importing from gerrit because we don't want to depend on the right
- # working directory
- sha1 = hashlib.sha1(open(path, 'rb').read()).hexdigest()
- outdir = '%s-%s' % (path[:-len(suffix)], sha1)
- 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)
- libbin = os.path.join(outdir, rel_lib_bin)
- if not os.path.isfile(bin):
- extract(path, outdir, rel_bin)
-
- nodejs = spawn.find_executable('nodejs')
- if nodejs:
- # Debian installs Node.js as 'nodejs', due to a conflict with another
- # package.
- 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:
- subprocess.check_call([bin] + args[1:])
-
-
-if __name__ == '__main__':
- sys.exit(main(sys.argv[1:]))
diff --git a/tools/node_tools/legacy/BUILD b/tools/node_tools/legacy/BUILD
deleted file mode 100644
index ed0946e..0000000
--- a/tools/node_tools/legacy/BUILD
+++ /dev/null
@@ -1,15 +0,0 @@
-load("@build_bazel_rules_nodejs//:index.bzl", "nodejs_binary")
-
-package(default_visibility = ["//visibility:public"])
-
-nodejs_binary(
- name = "polymer-bundler-bin",
- data = ["@tools_npm//:node_modules"],
- entry_point = "@tools_npm//:node_modules/polymer-bundler/lib/bin/polymer-bundler.js",
-)
-
-nodejs_binary(
- name = "crisper-bin",
- data = ["@tools_npm//:node_modules"],
- entry_point = "@tools_npm//:node_modules/crisper/bin/crisper",
-)
diff --git a/tools/node_tools/legacy/index.bzl b/tools/node_tools/legacy/index.bzl
deleted file mode 100644
index fe66bf8..0000000
--- a/tools/node_tools/legacy/index.bzl
+++ /dev/null
@@ -1,66 +0,0 @@
-""" File contains a wrapper for legacy polymer-bundler and crisper tools. """
-
-# File must be removed after get rid of HTML imports
-
-def _polymer_bundler_tool_impl(ctx):
- """Wrapper for the polymer-bundler and crisper command-line tools"""
-
- html_bundled_file = ctx.actions.declare_file(ctx.label.name + "_tmp.html")
- ctx.actions.run(
- executable = ctx.executable._bundler,
- outputs = [html_bundled_file],
- inputs = ctx.files.srcs,
- arguments = [
- "--inline-css",
- "--sourcemaps",
- "--strip-comments",
- "--root",
- ctx.file.entry_point.dirname,
- "--out-file",
- html_bundled_file.path,
- "--in-file",
- ctx.file.entry_point.basename,
- ],
- )
-
- output_js_file = ctx.outputs.js
- if ctx.attr.script_src_value:
- output_js_file = ctx.actions.declare_file(ctx.attr.script_src_value, sibling = ctx.outputs.html)
- script_src_value = ctx.attr.script_src_value if ctx.attr.script_src_value else ctx.outputs.js.path
-
- ctx.actions.run(
- executable = ctx.executable._crisper,
- outputs = [ctx.outputs.html, output_js_file],
- inputs = [html_bundled_file],
- arguments = ["-s", html_bundled_file.path, "-h", ctx.outputs.html.path, "-j", output_js_file.path, "--always-write-script", "--script-in-head=false"],
- )
-
- if ctx.attr.script_src_value:
- ctx.actions.expand_template(
- template = output_js_file,
- output = ctx.outputs.js,
- substitutions = {},
- )
-
-polymer_bundler_tool = rule(
- implementation = _polymer_bundler_tool_impl,
- attrs = {
- "entry_point": attr.label(allow_single_file = True, mandatory = True),
- "srcs": attr.label_list(allow_files = True),
- "script_src_value": attr.string(),
- "_bundler": attr.label(
- default = ":polymer-bundler-bin",
- executable = True,
- cfg = "host",
- ),
- "_crisper": attr.label(
- default = ":crisper-bin",
- executable = True,
- cfg = "host",
- ),
- },
- outputs = {
- "html": "%{name}.html",
- "js": "%{name}.js",
- },
-)