diff options
Diffstat (limited to 'tools/build_defs')
-rw-r--r-- | tools/build_defs/groovy/README.md | 4 | ||||
-rw-r--r-- | tools/build_defs/groovy/groovy.BUILD | 4 | ||||
-rw-r--r-- | tools/build_defs/groovy/groovy.WORKSPACE | 25 | ||||
-rw-r--r-- | tools/build_defs/groovy/groovy.bzl | 61 |
4 files changed, 52 insertions, 42 deletions
diff --git a/tools/build_defs/groovy/README.md b/tools/build_defs/groovy/README.md index 27fb73d31b..0718833f1d 100644 --- a/tools/build_defs/groovy/README.md +++ b/tools/build_defs/groovy/README.md @@ -19,8 +19,8 @@ libraries and vice-versa. To be able to use the Groovy rules, you must provide bindings for the following targets: - * `//external:groovy`, pointing at the core Groovy library - * `//external:groovyc`, pointing at the Groovy compiler + * `//external:groovy-sdk`, pointing at the + [Groovy SDK binaries](http://www.groovy-lang.org/download.html) * `//external:junit`, pointing at JUnit (only required if using `groovy_test`) The easiest way to do so is by copying the content of `groovy.WORKSPACE` to your diff --git a/tools/build_defs/groovy/groovy.BUILD b/tools/build_defs/groovy/groovy.BUILD index 05f378467c..4f65877a3f 100644 --- a/tools/build_defs/groovy/groovy.BUILD +++ b/tools/build_defs/groovy/groovy.BUILD @@ -1,5 +1,5 @@ filegroup( - name = "groovyc", - srcs = ["groovy-2.4.4/bin/groovyc"], + name = "sdk", + srcs = glob(["groovy-2.4.4/**"], exclude_directories=0), visibility = ["//visibility:public"], ) diff --git a/tools/build_defs/groovy/groovy.WORKSPACE b/tools/build_defs/groovy/groovy.WORKSPACE index c1aa147523..545df09232 100644 --- a/tools/build_defs/groovy/groovy.WORKSPACE +++ b/tools/build_defs/groovy/groovy.WORKSPACE @@ -1,28 +1,19 @@ -bind( - name = "groovyc", - actual = "@groovy-bin//:groovyc", -) new_http_archive( - name = "groovy-bin", + name = "groovy-sdk-artifact", url = "http://dl.bintray.com/groovy/maven/apache-groovy-binary-2.4.4.zip", sha256 = "a7cc1e5315a14ea38db1b2b9ce0792e35174161141a6a3e2ef49b7b2788c258c", build_file = "groovy.BUILD", ) - bind( - name = "groovy", - actual = "@groovy-jar//jar", -) -maven_jar( - name = "groovy-jar", - artifact = "org.codehaus.groovy:groovy-all:2.3.7", + name = "groovy-sdk", + actual = "@groovy-sdk-artifact//:sdk", ) -bind ( - name = "junit", - actual = "@junit-jar//jar", -) maven_jar( - name = "junit-jar", + name = "junit-artifact", artifact = "junit:junit:4.12", ) +bind( + name = "junit", + actual = "@junit-artifact//jar", +) diff --git a/tools/build_defs/groovy/groovy.bzl b/tools/build_defs/groovy/groovy.bzl index c9da7b6ed7..b1175919ca 100644 --- a/tools/build_defs/groovy/groovy.bzl +++ b/tools/build_defs/groovy/groovy.bzl @@ -27,10 +27,20 @@ def _groovy_jar_impl(ctx): if hasattr(this_dep, "java"): all_deps += this_dep.java.transitive_runtime_deps + # Set up the output directory and set JAVA_HOME + cmd = "rm -rf %s\n" % build_output + cmd += "mkdir -p %s\n" % build_output + cmd += "export JAVA_HOME=external/local-jdk\n" + + # Set GROOVY_HOME by scanning through the groovy SDK to find the license file, + # which should be at the root of the SDK. + for file in ctx.files._groovysdk: + if file.basename == "CLI-LICENSE.txt": + cmd += "export GROOVY_HOME=%s\n" % file.dirname + break + # Compile all files in srcs with groovyc - cmd = "rm -rf %s; mkdir -p %s\n" % (build_output, build_output) - cmd += "%s %s -d %s %s\n" % ( - ctx.file._groovyc.short_path, + cmd += "$GROOVY_HOME/bin/groovyc %s -d %s %s\n" % ( "-cp " + ":".join([dep.path for dep in all_deps]) if len(all_deps) != 0 else "", build_output, " ".join([src.path for src in ctx.files.srcs]), @@ -43,7 +53,7 @@ def _groovy_jar_impl(ctx): cmd += "root=`pwd`\n" cmd += "cd %s; $root/%s c ../%s `find . -name '*.class' | cut -c 3-`\n" % ( build_output, - ctx.executable._jar.path, + ctx.executable._zipper.path, class_jar.basename, ) cmd += "cd $root\n" @@ -53,7 +63,12 @@ def _groovy_jar_impl(ctx): # Execute the command ctx.action( - inputs = ctx.files.srcs + ctx.files.deps + ctx.files._jar, + inputs = ( + ctx.files.srcs + + list(all_deps) + + ctx.files._groovysdk + + ctx.files._jdk + + ctx.files._zipper), outputs = [class_jar], mnemonic = "Groovyc", command = "set -e;" + cmd, @@ -69,17 +84,18 @@ _groovy_jar = rule( "deps": attr.label_list( mandatory=False, allow_files=FileType([".jar"])), - "_groovyc": attr.label( - default=Label("//external:groovyc"), - single_file=True), - "_jar": attr.label( + "_groovysdk": attr.label( + default=Label("//external:groovy-sdk")), + "_jdk": attr.label( + default=Label("//tools/defaults:jdk")), + "_zipper": attr.label( default=Label("//third_party/ijar:zipper"), executable=True, single_file=True), - }, + }, outputs = { "class_jar": "lib%{name}.jar", - }, + }, ) def groovy_library(name, srcs=[], deps=[], **kwargs): @@ -135,7 +151,6 @@ def groovy_and_java_library(name, srcs=[], deps=[], **kwargs): **kwargs ) - def groovy_binary(name, main_class, srcs=[], deps=[], **kwargs): """Rule analagous to java_binary that accepts .groovy sources instead of .java sources. @@ -165,8 +180,14 @@ def path_to_class(path): fail("groovy_test sources must be under src/test/java or src/test/groovy") def groovy_test_impl(ctx): + # Collect jars from the Groovy sdk + groovy_sdk_jars = [file + for file in ctx.files._groovysdk + if file.basename.endswith(".jar") + ] + # Extract all transitive dependencies - all_deps = set(ctx.files.deps + ctx.files._implicit_deps) + all_deps = set(ctx.files.deps + ctx.files._implicit_deps + groovy_sdk_jars) for this_dep in ctx.attr.deps: if hasattr(this_dep, 'java'): all_deps += this_dep.java.transitive_runtime_deps @@ -175,8 +196,7 @@ def groovy_test_impl(ctx): classes = [path_to_class(src.path) for src in ctx.files.srcs] # Write a file that executes JUnit on the inferred classes - cmd = "%s %s -cp %s org.junit.runner.JUnitCore %s\n" % ( - ctx.executable._java.path, + cmd = "external/local-jdk/bin/java %s -cp %s org.junit.runner.JUnitCore %s\n" % ( " ".join(ctx.attr.jvm_flags), ":".join([dep.short_path for dep in all_deps]), " ".join(classes), @@ -188,7 +208,7 @@ def groovy_test_impl(ctx): # Return all dependencies needed to run the tests return struct( - runfiles=ctx.runfiles(files=list(all_deps) + ctx.files._java), + runfiles=ctx.runfiles(files=list(all_deps) + ctx.files._jdk), ) groovy_test = rule( @@ -197,12 +217,11 @@ groovy_test = rule( "srcs": attr.label_list(mandatory=True, allow_files=FileType([".groovy"])), "deps": attr.label_list(allow_files=FileType([".jar"])), "jvm_flags": attr.string_list(), - "_java": attr.label( - default=Label("@local-jdk//:java"), - executable=True, - single_file=True), + "_groovysdk": attr.label( + default=Label("//external:groovy-sdk")), + "_jdk": attr.label( + default=Label("//tools/defaults:jdk")), "_implicit_deps": attr.label_list(default=[ - Label("//external:groovy"), Label("//external:junit"), ]), }, |