diff options
author | Erik Kuefler <ekuefler@gmail.com> | 2015-09-14 19:11:29 +0000 |
---|---|---|
committer | John Field <jfield@google.com> | 2015-09-15 20:25:43 +0000 |
commit | 1906b26bf333464a2a194a879eee30c2a2c16937 (patch) | |
tree | 12b367a6c3ba882c859af283531787552f382c47 /tools | |
parent | 0cb41b086e5eb886375d6c27d30c72b931bcd76f (diff) |
Support data and resource attributes in Groovy tests
--
Change-Id: If79677c963f4991d1ffca2a0878c845df59a6a64
Reviewed-on: https://bazel-review.googlesource.com/#/c/1970/
MOS_MIGRATED_REVID=103016420
Diffstat (limited to 'tools')
-rw-r--r-- | tools/build_defs/groovy/README.md | 13 | ||||
-rw-r--r-- | tools/build_defs/groovy/groovy.bzl | 37 |
2 files changed, 45 insertions, 5 deletions
diff --git a/tools/build_defs/groovy/README.md b/tools/build_defs/groovy/README.md index 0718833f1d..284a3eccc9 100644 --- a/tools/build_defs/groovy/README.md +++ b/tools/build_defs/groovy/README.md @@ -302,7 +302,7 @@ groovy_test( <a name="groovy_test"></a> ### `groovy_test` -`groovy_binary(name, main_class, srcs, deps, **kwargs)` +`groovy_test(name, deps, srcs, data, resources, jvm_flags, size, tags)` <table> <thead> @@ -344,6 +344,17 @@ groovy_test( </td> </tr> <tr> + <td><code>resources</code></td> + <td> + <code>List of labels, optional</code> + <p> + A list of data files to include on the test's classpath. This is + accomplished by creating a `java_library` containing only the specified + resources and including that library in the test's dependencies. + </p> + </td> + </tr> + <tr> <td><code>jvm_flags</code></td> <td> <code>List of strings, optional</code> diff --git a/tools/build_defs/groovy/groovy.bzl b/tools/build_defs/groovy/groovy.bzl index e7cdd2924b..3c3102c97c 100644 --- a/tools/build_defs/groovy/groovy.bzl +++ b/tools/build_defs/groovy/groovy.bzl @@ -179,7 +179,7 @@ def path_to_class(path): else: fail("groovy_test sources must be under src/test/java or src/test/groovy") -def groovy_test_impl(ctx): +def _groovy_test_impl(ctx): # Collect jars from the Groovy sdk groovy_sdk_jars = [file for file in ctx.files._groovysdk @@ -208,14 +208,15 @@ def groovy_test_impl(ctx): # Return all dependencies needed to run the tests return struct( - runfiles=ctx.runfiles(files=list(all_deps) + ctx.files._jdk), + runfiles=ctx.runfiles(files=list(all_deps) + ctx.files.data + ctx.files._jdk), ) -groovy_test = rule( - implementation = groovy_test_impl, +_groovy_test = rule( + implementation = _groovy_test_impl, attrs = { "srcs": attr.label_list(mandatory=True, allow_files=FileType([".groovy"])), "deps": attr.label_list(allow_files=FileType([".jar"])), + "data": attr.label_list(allow_files=True), "jvm_flags": attr.string_list(), "_groovysdk": attr.label( default=Label("//external:groovy-sdk")), @@ -227,3 +228,31 @@ groovy_test = rule( }, test = True, ) + +def groovy_test( + name, + deps=[], + srcs=[], + data=[], + resources=[], + jvm_flags=[], + size="medium", + tags=[]): + # Create an extra jar to hold the resource files if any were specified + all_deps = deps + if resources: + native.java_library( + name = name + "-resources", + resources = resources, + ) + all_deps += [name + "-resources"] + + _groovy_test( + name = name, + size = size, + tags = tags, + srcs = srcs, + deps = all_deps, + data = data, + jvm_flags = jvm_flags, + ) |