Merge branch 'stable-2.16' into stable-3.0

* stable-2.16:
  Bazel: Make build tool chain forward compatible
  js.bzl: Avoid using deprecated depset union
  Update Gerrit API to 2.15.14

Change-Id: I8b937ca529c90a1faf388758e94559b405952366
diff --git a/tools/js.bzl b/tools/js.bzl
index 94c11e1..bbae345 100644
--- a/tools/js.bzl
+++ b/tools/js.bzl
@@ -45,6 +45,8 @@
     implementation = _npm_binary_impl,
 )
 
+ComponentInfo = provider()
+
 # for use in repo rules.
 def _run_npm_binary_str(ctx, tarball, args):
     python_bin = ctx.which("python")
@@ -131,33 +133,31 @@
 )
 
 def _bower_component_impl(ctx):
-    transitive_zipfiles = depset([ctx.file.zipfile])
-    for d in ctx.attr.deps:
-        transitive_zipfiles += d.transitive_zipfiles
-
-    transitive_licenses = depset()
-    if ctx.file.license:
-        transitive_licenses += depset([ctx.file.license])
-
-    for d in ctx.attr.deps:
-        transitive_licenses += d.transitive_licenses
-
-    transitive_versions = depset(ctx.files.version_json)
-    for d in ctx.attr.deps:
-        transitive_versions += d.transitive_versions
-
-    return struct(
-        transitive_licenses = transitive_licenses,
-        transitive_versions = transitive_versions,
-        transitive_zipfiles = transitive_zipfiles,
+    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 = [
-        "transitive_zipfiles",
-        "transitive_versions",
-        "transitive_licenses",
-    ]),
+    "deps": attr.label_list(providers = [ComponentInfo]),
 }
 
 def _js_component(ctx):
@@ -183,15 +183,17 @@
         mnemonic = "GenBowerZip",
     )
 
-    licenses = depset()
+    licenses = []
     if ctx.file.license:
-        licenses += depset([ctx.file.license])
+        licenses.append(ctx.file.license)
 
-    return struct(
-        transitive_licenses = licenses,
-        transitive_versions = depset(),
-        transitive_zipfiles = list([ctx.outputs.zip]),
-    )
+    return [
+        ComponentInfo(
+            transitive_licenses = depset(licenses),
+            transitive_versions = depset(),
+            transitive_zipfiles = list([ctx.outputs.zip]),
+        ),
+    ]
 
 js_component = rule(
     _js_component,
@@ -233,15 +235,16 @@
     """A bunch of bower components zipped up."""
     zips = depset()
     for d in ctx.attr.deps:
-        zips += d.transitive_zipfiles
+        files = d[ComponentInfo].transitive_zipfiles
 
-    versions = depset()
-    for d in ctx.attr.deps:
-        versions += d.transitive_versions
+        # TODO(davido): Make sure the field always contains a depset
+        if type(files) == "list":
+            files = depset(files)
+        zips = depset(transitive = [zips, files])
 
-    licenses = depset()
-    for d in ctx.attr.deps:
-        licenses += d.transitive_versions
+    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
@@ -271,11 +274,13 @@
         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 struct(
-        transitive_licenses = licenses,
-        transitive_versions = versions,
-        transitive_zipfiles = zips,
-    )
+    return [
+        ComponentInfo(
+            transitive_licenses = licenses,
+            transitive_versions = versions,
+            transitive_zipfiles = zips,
+        ),
+    ]
 
 bower_component_bundle = rule(
     _bower_component_bundle_impl,
@@ -303,7 +308,7 @@
     else:
         bundled = ctx.outputs.html
     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[ComponentInfo].transitive_zipfiles.to_list()]
 
     hermetic_npm_binary = " ".join([
         "python",
@@ -403,7 +408,7 @@
         ),
         "pkg": attr.string(mandatory = True),
         "split": attr.bool(default = True),
-        "deps": attr.label_list(providers = ["transitive_zipfiles"]),
+        "deps": attr.label_list(providers = [ComponentInfo]),
         "_bundler_archive": attr.label(
             default = Label("@polymer-bundler//:%s" % _npm_tarball("polymer-bundler")),
             allow_single_file = True,