From c65ad9749c842a78234746147e2a9c5df65ff4a4 Mon Sep 17 00:00:00 2001 From: Han-Wen Nienhuys Date: Wed, 21 Sep 2016 12:07:22 +0200 Subject: [PATCH] bazel: add test that forbids DO_NOT_DISTRIBUTE in //gerrit-pgm:pgm. Change-Id: Idf4695294c34bbca157d104cfb6e708bac727473 --- gerrit-pgm/BUILD | 5 +++++ lib/BUILD | 4 ++++ tools/bzl/BUILD | 4 +++- tools/bzl/license.bzl | 25 +++++++++++++++++++++++++ tools/bzl/test_empty.sh | 8 ++++++++ 5 files changed, 45 insertions(+), 1 deletion(-) create mode 100755 tools/bzl/test_empty.sh diff --git a/gerrit-pgm/BUILD b/gerrit-pgm/BUILD index ec86c9a1f8..895b5f112c 100644 --- a/gerrit-pgm/BUILD +++ b/gerrit-pgm/BUILD @@ -1,5 +1,6 @@ load('//tools/bzl:java.bzl', 'java_library2') load('//tools/bzl:junit.bzl', 'junit_tests') +load('//tools/bzl:license.bzl', 'license_test') SRCS = 'src/main/java/com/google/gerrit/pgm/' RSRCS = 'src/main/resources/com/google/gerrit/pgm/' @@ -160,3 +161,7 @@ junit_tests( '//lib/jgit/org.eclipse.jgit.junit:junit', ], ) + +license_test( + name = "pgm_license_test", + target = ":pgm") diff --git a/lib/BUILD b/lib/BUILD index 19abf4f001..20fa1264d3 100644 --- a/lib/BUILD +++ b/lib/BUILD @@ -1,3 +1,7 @@ +exports_files([ + "LICENSE-DO_NOT_DISTRIBUTE" +]) + java_library( name = 'servlet-api-3_1', neverlink = 1, diff --git a/tools/bzl/BUILD b/tools/bzl/BUILD index 90c91c3933..01ae92c333 100644 --- a/tools/bzl/BUILD +++ b/tools/bzl/BUILD @@ -1,2 +1,4 @@ -exports_files(["license-map.py"]) +exports_files([ + "license-map.py", + "test_empty.sh"]) diff --git a/tools/bzl/license.bzl b/tools/bzl/license.bzl index a9a144410b..ca6443869b 100644 --- a/tools/bzl/license.bzl +++ b/tools/bzl/license.bzl @@ -20,3 +20,28 @@ def license_map(name, target): cmd = "python $(location //tools/bzl:license-map.py) $(location :%s.xml) > $@" % name, outs = [ name + ".txt",], tools = [ "//tools/bzl:license-map.py", name + ".xml"]) + +def license_test(name, target): + """Generate XML for all targets that depend directly on a LICENSE file""" + txt = name + "-forbidden.txt" + + # fully qualify target name. + if target[0] not in ":/": + target = ":" + target + if target[0] != "/": + target = "//" + PACKAGE_NAME + target + + forbidden = "//lib:LICENSE-DO_NOT_DISTRIBUTE" + native.genquery( + name = txt, + scope = [ target, forbidden ], + # Find everything that depends on a license file, but remove + # the license files themselves from this list. + expression = 'rdeps(%s, "%s", 1) - rdeps(%s, "%s", 0)' % (target, forbidden, target, forbidden), + ) + native.sh_test( + name = name, + srcs = [ "//tools/bzl:test_empty.sh" ], + args = [ "$(location :%s)" % txt], + data = [ txt ], + ) diff --git a/tools/bzl/test_empty.sh b/tools/bzl/test_empty.sh new file mode 100755 index 0000000000..0d4398d2bc --- /dev/null +++ b/tools/bzl/test_empty.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if test -s $1 +then + echo "$1 not empty:" + cat $1 + exit 1 +fi