bazel: add test that forbids DO_NOT_DISTRIBUTE in //gerrit-pgm:pgm.

Change-Id: Idf4695294c34bbca157d104cfb6e708bac727473
This commit is contained in:
Han-Wen Nienhuys
2016-09-21 12:07:22 +02:00
committed by David Ostrovsky
parent eb16fe05a1
commit c65ad9749c
5 changed files with 45 additions and 1 deletions

View File

@@ -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")

View File

@@ -1,3 +1,7 @@
exports_files([
"LICENSE-DO_NOT_DISTRIBUTE"
])
java_library(
name = 'servlet-api-3_1',
neverlink = 1,

View File

@@ -1,2 +1,4 @@
exports_files(["license-map.py"])
exports_files([
"license-map.py",
"test_empty.sh"])

View File

@@ -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 ],
)

8
tools/bzl/test_empty.sh Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/sh
if test -s $1
then
echo "$1 not empty:"
cat $1
exit 1
fi