bazel: remove code to sniff license field in bower.json.

Instead, use a hard-coded map of licenses.

Hardcode a false dependency on diff-match-patch to avoid a diff for
the Apache2.0 license.

Tested:
  bazel build Documentation:js_licenses.txt
  buck build Documentation:js_licenses.txt
  diff -u  buck-out/gen/Documentation/js_licenses.txt/js_licenses.txt \
    bazel-genfiles/Documentation/js_licenses.txt
 diff shows only diffs for added [[header]] anchors.

Change-Id: I7886e1fadec900cf854a1b3b7c538b83d66af7a4
This commit is contained in:
Han-Wen Nienhuys
2016-12-15 13:44:33 +01:00
parent 2f845a4cd5
commit 42ea853037
4 changed files with 45 additions and 46 deletions

View File

@@ -1,3 +1,11 @@
load("//lib/codemirror:cm.bzl", "pkg_cm")
# This library is only used to insert a license statement into
# js_licenses.txt.
java_library(
name = "diff-match-patch",
runtime_deps = [ "@diff_match_patch//jar" ],
data = [ "//lib:LICENSE-Apache2.0" ],
)
pkg_cm()

View File

@@ -311,6 +311,8 @@ def pkg_cm():
),
tools = [
'@diff_match_patch//jar',
# dependency just for license tracking.
':diff-match-patch',
archive,
"//lib:LICENSE-Apache2.0",
],

View File

@@ -9,19 +9,19 @@ load("//tools/bzl:js.bzl", "bower_component")
def define_bower_components():
bower_component(
name = "accessibility-developer-tools",
license = "//lib:LICENSE-Apache2.0",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "async",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "chai",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "es6-promise",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-es6-promise",
seed = True,
)
bower_component(
@@ -126,7 +126,7 @@ def define_bower_components():
)
bower_component(
name = "iron-test-helpers",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
deps = [ ":polymer" ],
seed = True,
)
@@ -140,11 +140,11 @@ def define_bower_components():
)
bower_component(
name = "lodash",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "mocha",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "moment",
@@ -164,7 +164,7 @@ def define_bower_components():
)
bower_component(
name = "page",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-page.js",
seed = True,
)
bower_component(
@@ -175,25 +175,25 @@ def define_bower_components():
)
bower_component(
name = "promise-polyfill",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-promise-polyfill",
deps = [ ":polymer" ],
seed = True,
)
bower_component(
name = "sinon-chai",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "sinonjs",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "stacky",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
)
bower_component(
name = "test-fixture",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
seed = True,
)
bower_component(
@@ -202,7 +202,7 @@ def define_bower_components():
)
bower_component(
name = "web-component-tester",
license = "//lib:LICENSE-polymer",
license = "//lib:LICENSE-DO_NOT_DISTRIBUTE",
deps = [
":accessibility-developer-tools",
":async",

View File

@@ -31,28 +31,31 @@ import tempfile
import glob
import bowerutil
# Map license names to our canonical names.
license_map = {
"http://polymer.github.io/LICENSE.txt": "polymer",
"Apache-2.0": "Apache2.0",
# TODO(hanwen): remove these, and add appropriate license files under //lib
"BSD": "polymer",
"MIT": "polymer",
"BSD-3-Clause": "polymer",
}
# list of licenses for packages that don't specify one in their bower.json file.
package_licenses = {
"es6-promise": "es6-promise",
"fetch": "fetch",
"iron-a11y-announcer": "polymer",
"iron-a11y-keys-behavior": "polymer",
"iron-autogrow-textarea": "polymer",
"iron-behaviors": "polymer",
"iron-dropdown": "polymer",
"iron-fit-behavior": "polymer",
"iron-flex-layout": "polymer",
"iron-form-element-behavior": "polymer",
"iron-input": "polymer",
"iron-meta": "polymer",
"iron-overlay-behavior": "polymer",
"iron-resizable-behavior": "polymer",
"iron-selector": "polymer",
"iron-validatable-behavior": "polymer",
"moment": "moment",
"neon-animation": "polymer",
"page": "page.js",
"lodash": "polymer", # MIT, actually.
"polymer": "polymer",
"promise-polyfill": "promise-polyfill",
"webcomponentsjs": "polymer", # self-identifies as BSD.
"sinon-chai": "polymer", # WTFPL & BSD.
"sinonjs": "polymer", # BSD.
"web-animations-js": "Apache2.0",
"webcomponentsjs": "polymer",
}
@@ -146,7 +149,7 @@ def main(args):
def dump_workspace(data, seeds, out):
out.write('load("//tools/bzl:js.bzl", "bower_archive")\n')
out.write('load("//tools/bzl:js.bzl", "bower_archive")\n\n')
out.write('def load_bower_archives():\n')
for d in data:
@@ -161,7 +164,7 @@ def dump_workspace(data, seeds, out):
def dump_build(data, seeds, out):
out.write('load("//tools/bzl:js.bzl", "bower_component")\n')
out.write('load("//tools/bzl:js.bzl", "bower_component")\n\n')
out.write('def define_bower_components():\n')
for d in data:
out.write(" bower_component(\n")
@@ -194,21 +197,7 @@ def interpret_bower_json(seeds, ws_out, build_out):
pkg["bazel-sha1"] = bowerutil.hash_bower_component(
hashlib.sha1(), os.path.dirname(f)).hexdigest()
license = pkg.get("license", None)
if type(license) == type([]):
# WTF? Some package specify a list of licenses. ("GPL", "MIT")
pick = license[0]
sys.stderr.write("package %s has multiple licenses: %s, picking %s" % (pkg_name, ", ".join(license), pick))
license = pick
if license:
license = license_map.get(license, license)
else:
if pkg_name not in package_licenses:
msg = "package %s does not specify license: %s" % (pkg_name, pkg)
sys.stderr.write(msg)
raise Exception(msg)
license = package_licenses[pkg_name]
license = package_licenses.get(pkg_name, "DO_NOT_DISTRIBUTE")
pkg["bazel-license"] = license