Skip to content

Commit

Permalink
Update maven dependencies, and invoke jarjar on the kotlinbuilder to …
Browse files Browse the repository at this point in the history
…shade dagger, avoiding leakage of the bytecode from the builder into compilation jobs peformed by the builder.

Fixes bazelbuild#192
  • Loading branch information
cgruber committed Jun 12, 2019
1 parent d97374f commit 2038046
Show file tree
Hide file tree
Showing 41 changed files with 634 additions and 279 deletions.
19 changes: 17 additions & 2 deletions src/main/kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.
load("//src/main/kotlin:bootstrap.bzl", "kt_bootstrap_library")
load("//kotlin:kotlin.bzl", "kt_jvm_library")
load("//third_party:jarjar.bzl", "jar_jar")

# The compiler library, this is co-located in the kotlin compiler classloader.
kt_bootstrap_library(
Expand All @@ -26,11 +27,25 @@ kt_bootstrap_library(
visibility = ["//src/test/kotlin/io/bazel/kotlin/builder:__subpackages__"],
)

# The builder artifact.
java_binary(
name = "builder_raw",
create_executable = False,
runtime_deps = ["//src/main/kotlin/io/bazel/kotlin/builder"],
)

# The builder artifact. Shaded to ensure that libraries it uses are not leaked to
# the code it's running against (e.g. dagger)
jar_jar(
name = "builder_jar_jar",
input_jar = ":builder_raw_deploy.jar",
rules = "shade.jarjar",
)

java_binary(
name = "builder",
data = [":compiler_lib.jar"],
main_class = "io.bazel.kotlin.builder.KotlinBuilderMain",
runtime_deps = [":builder_jar_jar"],
visibility = ["//visibility:public"],
runtime_deps = ["//src/main/kotlin/io/bazel/kotlin/builder"],
)

1 change: 1 addition & 0 deletions src/main/kotlin/shade.jarjar
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rule dagger.** io.bazel.kotlin.builder.dagger.@1
29 changes: 13 additions & 16 deletions src/test/data/jvm/kapt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,20 @@ java_plugin(
name = "autoservice",
generates_api = 0,
processor_class = "com.google.auto.service.processor.AutoServiceProcessor",
deps = [
"//third_party/jvm/com/google/auto/service:auto_service",
"//third_party/jvm/com/google/guava",
],
deps = ["//third_party/jvm/com/google/auto/service:auto_service"],
)

java_plugin(
name = "autovalue_no_processor_class",
generates_api = 1,
deps = ["//third_party/jvm/com/google/auto/value:auto_value"],
deps = ["//third_party/jvm/com/google/auto/value:auto_value_annotations"],
)

kt_jvm_library(
name = "ap_kotlin",
srcs = ["kotlin/TestKtValue.kt"],
plugins = [":autovalue"],
deps = ["//third_party/jvm/com/google/auto/value:auto_value"],
deps = ["//third_party/jvm/com/google/auto/value:auto_value_annotations"],
)

kt_jvm_library(
Expand All @@ -51,7 +48,7 @@ kt_jvm_library(
"java/TestAPNoGenReferences.java",
"kotlin/TestKtAPNoGenReference.kt",
],
deps = ["//third_party/jvm/com/google/auto/value:auto_value"],
deps = ["//third_party/jvm/com/google/auto/value:auto_value_annotations"],
)

kt_jvm_library(
Expand All @@ -61,14 +58,14 @@ kt_jvm_library(
"kotlin/TestKtValue.kt",
],
plugins = [":autovalue"],
deps = ["//third_party/jvm/com/google/auto/value:auto_value"],
deps = ["//third_party/jvm/com/google/auto/value:auto_value_annotations"],
)

kt_jvm_library(
name = "ap_kotlin_resources",
srcs = ["kotlin/TestKtService.kt"],
plugins = [":autoservice"],
deps = ["//third_party/jvm/com/google/auto/service:auto_service"],
deps = ["//third_party/jvm/com/google/auto/service:auto_service_annotations"],
)

kt_jvm_library(
Expand All @@ -78,7 +75,7 @@ kt_jvm_library(
"kotlin/TestKtService.kt",
],
plugins = [":autoservice"],
deps = ["//third_party/jvm/com/google/auto/service:auto_service"],
deps = ["//third_party/jvm/com/google/auto/service:auto_service_annotations"],
)

kt_jvm_library(
Expand All @@ -94,8 +91,8 @@ kt_jvm_library(
":autovalue",
],
deps = [
"//third_party/jvm/com/google/auto/service:auto_service",
"//third_party/jvm/com/google/auto/value:auto_value",
"//third_party/jvm/com/google/auto/service:auto_service_annotations",
"//third_party/jvm/com/google/auto/value:auto_value_annotations",
],
)

Expand All @@ -112,8 +109,8 @@ kt_jvm_library(
":autovalue_no_processor_class",
],
deps = [
"//third_party/jvm/com/google/auto/service:auto_service",
"//third_party/jvm/com/google/auto/value:auto_value",
"//third_party/jvm/com/google/auto/service:auto_service_annotations",
"//third_party/jvm/com/google/auto/value:auto_value_annotations",
],
)

Expand All @@ -136,8 +133,8 @@ kt_jvm_library(
plugins = [":autovalue"],
deps = [
"library_exporting_autovalue_and_junit",
"//third_party/jvm/com/google/auto/service:auto_service",
"//third_party/jvm/com/google/auto/value:auto_value",
"//third_party/jvm/com/google/auto/service:auto_service_annotations",
"//third_party/jvm/com/google/auto/value:auto_value_annotations",
],
)

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/io/bazel/kotlin/builder/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ kt_rules_test(
srcs = ["tasks/jvm/KotlinBuilderJvmKaptTest.java"],
data = [
"//third_party/jvm/com/google/auto/value:auto_value",
"//third_party/jvm/com/google/auto/value:auto_value_annotations",
],
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,29 @@

@RunWith(JUnit4.class)
public class KotlinBuilderJvmKaptTest {
private static final Dep AUTO_VALUE =
Dep.importJar(
"autovalue",
"external/io_bazel_rules_kotlin_com_google_auto_value_auto_value"
+ "/jar/io_bazel_rules_kotlin_com_google_auto_value_auto_value.jar");
private static final Dep AUTO_VALUE_ANNOTATIONS =
Dep.importJar(
"autovalue",
"external/io_bazel_rules_kotlin_com_google_auto_value_auto_value_annotations"
+ "/jar/io_bazel_rules_kotlin_com_google_auto_value_auto_value_annotations.jar");
private static final Dep AUTO_VALUE =
Dep.importJar(
"autovalue",
"external/io_bazel_rules_kotlin_com_google_auto_value_auto_value"
+ "/jar/io_bazel_rules_kotlin_com_google_auto_value_auto_value.jar");
private static final AnnotationProcessor AUTO_VALUE_ANNOTATION_PROCESSOR =
AnnotationProcessor.builder()
.processClass("com.google.auto.value.processor.AutoValueProcessor")
.processorPath(
Dep.classpathOf(AUTO_VALUE, KOTLIN_ANNOTATIONS).collect(Collectors.toSet()))
Dep.classpathOf(AUTO_VALUE_ANNOTATIONS, AUTO_VALUE, KOTLIN_ANNOTATIONS).collect(Collectors.toSet()))
.build();

private static final KotlinJvmTestBuilder ctx = new KotlinJvmTestBuilder();

private static final Consumer<KotlinJvmTestBuilder.TaskBuilder> ADD_AUTO_VALUE_PLUGIN =
(c) -> {
c.addAnnotationProcessors(AUTO_VALUE_ANNOTATION_PROCESSOR);
c.addDirectDependencies(AUTO_VALUE, KOTLIN_STDLIB);
c.addDirectDependencies(AUTO_VALUE_ANNOTATIONS, AUTO_VALUE, KOTLIN_STDLIB);
};

@Test
Expand Down
9 changes: 8 additions & 1 deletion third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ java_library(
name = "autovalue",
exported_plugins = [":autovalue_plugin"],
neverlink = 1,
exports = ["//third_party/jvm/com/google/auto/value:auto_value"],
exports = ["//third_party/jvm/com/google/auto/value:auto_value_annotations"],
)

java_plugin(
Expand All @@ -61,3 +61,10 @@ java_library(
"//third_party/jvm/javax/inject:javax_inject",
],
)

java_binary(
name = "jarjar_runner",
main_class = "org.pantsbuild.jarjar.Main",
visibility = ["//visibility:public"],
runtime_deps = ["//third_party/jvm/org/pantsbuild:jarjar"],
)
21 changes: 13 additions & 8 deletions third_party/dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
junit:
junit:
lang: "java"
version: "4.12"
version: "4.13-beta-3"
com.google.protobuf:
protobuf:
modules: ["java", "java-util"]
Expand All @@ -27,24 +27,26 @@ dependencies:
com.google.guava:
guava:
lang: "java"
version: "25.0-jre"
version: "27.1-jre"
com.google.truth:
truth:
lang: "java"
version: "0.40"
version: "0.45"
com.google.auto.service:
auto-service:
modules: ["", "auto-service-annotations"]
lang: "java"
version: "1.0-rc4"
version: "1.0-rc5"
com.google.auto.value:
auto-value:
modules: ["", "auto-value-annotations"]
lang: "java"
version: "1.5.3"
version: "1.6.5"
com.google.dagger:
dagger:
modules: ["", "compiler", "producers"]
lang: "java"
version: "2.16"
version: "2.23.1"
javax.inject:
javax.inject:
lang: "java"
Expand All @@ -54,7 +56,10 @@ dependencies:
modules: ["core"]
lang: "java"
version : "0.23.1"

org.pantsbuild:
jarjar:
lang: "java"
version: "1.7.2"
replacements:
org.jetbrains.kotlin:
kotlin-stdlib:
Expand All @@ -65,4 +70,4 @@ replacements:
target: "@com_github_jetbrains_kotlin//:kotlin-reflect"
kotlin-script-runtime:
lang: java
target: "@com_github_jetbrains_kotlin//:kotlin-script-runtime"
target: "@com_github_jetbrains_kotlin//:kotlin-script-runtime"
35 changes: 35 additions & 0 deletions third_party/jarjar.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
load("@bazel_tools//tools/build_defs/repo:jvm.bzl", "jvm_maven_import_external")

def _jar_jar_impl(ctx):
ctx.action(
inputs = [ctx.file.rules, ctx.file.input_jar],
outputs = [ctx.outputs.jar],
executable = ctx.executable.jarjar_runner,
progress_message = "jarjar %s" % ctx.label,
arguments = ["process", ctx.file.rules.path, ctx.file.input_jar.path, ctx.outputs.jar.path],
)

return [
JavaInfo(
output_jar = ctx.outputs.jar,
compile_jar = ctx.outputs.jar,
),
DefaultInfo(files = depset([ctx.outputs.jar])),
]

jar_jar = rule(
implementation = _jar_jar_impl,
attrs = {
"input_jar": attr.label(allow_files = True, single_file = True),
"rules": attr.label(allow_files = True, single_file = True),
"jarjar_runner": attr.label(
executable = True,
cfg = "host",
default = Label("@io_bazel_rules_kotlin//third_party:jarjar_runner"),
),
},
outputs = {
"jar": "%{name}.jar",
},
provides = [JavaInfo],
)
13 changes: 6 additions & 7 deletions third_party/jvm/com/google/auto/BUILD
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
licenses(["notice"])

java_library(
name = "auto_common",
visibility = [
"//third_party/jvm:__subpackages__",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/auto/auto_common"
"//external:jar/io_bazel_rules_kotlin_com/google/auto/auto_common",
],
runtime_deps = [
"//third_party/jvm/com/google/guava:guava"
"//third_party/jvm/com/google/guava",
],
visibility = [
"//third_party/jvm:__subpackages__"
]
)


23 changes: 17 additions & 6 deletions third_party/jvm/com/google/auto/service/BUILD
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
licenses(["notice"])

java_library(
name = "auto_service",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/auto/service/auto_service"
":auto_service_annotations",
"//external:jar/io_bazel_rules_kotlin_com/google/auto/service/auto_service",
],
runtime_deps = [
":auto_service_annotations",
"//third_party/jvm/com/google/auto:auto_common",
"//third_party/jvm/com/google/guava:guava"
"//third_party/jvm/com/google/guava",
],
visibility = [
"//visibility:public"
]
)


java_library(
name = "auto_service_annotations",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/auto/service/auto_service_annotations",
],
)
20 changes: 15 additions & 5 deletions third_party/jvm/com/google/auto/value/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
licenses(["notice"])

java_library(
name = "auto_value",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/auto/value/auto_value"
":auto_value_annotations",
"//external:jar/io_bazel_rules_kotlin_com/google/auto/value/auto_value",
],
visibility = [
"//visibility:public"
]
)


java_library(
name = "auto_value_annotations",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/auto/value/auto_value_annotations",
],
)
11 changes: 5 additions & 6 deletions third_party/jvm/com/google/code/findbugs/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
licenses(["notice"])

java_library(
name = "jsr305",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/code/findbugs/jsr305"
"//external:jar/io_bazel_rules_kotlin_com/google/code/findbugs/jsr305",
],
visibility = [
"//visibility:public"
]
)


Loading

0 comments on commit 2038046

Please sign in to comment.