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 7913363
Show file tree
Hide file tree
Showing 38 changed files with 603 additions and 256 deletions.
20 changes: 17 additions & 3 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,24 @@ 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
7 changes: 7 additions & 0 deletions third_party/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
19 changes: 11 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,24 @@ 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:
lang: "java"
version: "1.0-rc4"
version: "1.0-rc5"
com.google.auto.value:
auto-value:
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 +54,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 +68,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__"
]
)


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

java_library(
name = "auto_service",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/auto/service/auto_service"
"//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 = [
"//third_party/jvm:__subpackages__",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/auto/service/auto_service_annotations",
],
)
19 changes: 14 additions & 5 deletions third_party/jvm/com/google/auto/value/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
licenses(["notice"])

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


java_library(
name = "auto_value_annotations",
visibility = [
"//third_party/jvm:__subpackages__",
],
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"
]
)


11 changes: 5 additions & 6 deletions third_party/jvm/com/google/code/gson/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
licenses(["notice"])

java_library(
name = "gson",
visibility = [
"//third_party/jvm:__subpackages__",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/code/gson/gson"
"//external:jar/io_bazel_rules_kotlin_com/google/code/gson/gson",
],
visibility = [
"//third_party/jvm:__subpackages__"
]
)


68 changes: 34 additions & 34 deletions third_party/jvm/com/google/dagger/BUILD
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
licenses(["notice"])

java_library(
name = "dagger",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger"
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger",
],
runtime_deps = [
"//third_party/jvm/javax/inject:javax_inject"
"//third_party/jvm/javax/inject:javax_inject",
],
visibility = [
"//visibility:public"
]
)



java_library(
name = "dagger_compiler",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger_compiler"
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger_compiler",
],
runtime_deps = [
":dagger",
":dagger_producers",
":dagger_spi",
"//third_party/jvm/com/google/googlejavaformat:google_java_format",
"//third_party/jvm/com/google/guava:guava",
"//third_party/jvm/com/google/guava",
"//third_party/jvm/com/google/guava:failureaccess",
"//third_party/jvm/com/google/protobuf:protobuf_java",
"//third_party/jvm/com/squareup:javapoet",
"//third_party/jvm/javax/annotation:jsr250_api",
"//third_party/jvm/javax/inject:javax_inject",
":dagger",
":dagger_producers",
":dagger_spi"
"//third_party/jvm/net/ltgt/gradle/incap",
"//third_party/jvm/org/checkerframework:checker_compat_qual",
],
visibility = [
"//visibility:public"
]
)



java_library(
name = "dagger_producers",
visibility = [
"//visibility:public",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger_producers"
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger_producers",
],
runtime_deps = [
"//third_party/jvm/com/google/guava:guava",
":dagger",
"//third_party/jvm/com/google/guava",
"//third_party/jvm/com/google/guava:failureaccess",
"//third_party/jvm/javax/inject:javax_inject",
"//third_party/jvm/org/checkerframework:checker_compat_qual",
":dagger"
],
visibility = [
"//visibility:public"
]
)



java_library(
name = "dagger_spi",
visibility = [
"//third_party/jvm:__subpackages__",
],
exports = [
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger_spi"
"//external:jar/io_bazel_rules_kotlin_com/google/dagger/dagger_spi",
],
runtime_deps = [
"//third_party/jvm/com/google/guava:guava",
"//third_party/jvm/javax/inject:javax_inject",
":dagger",
":dagger_producers"
":dagger_producers",
"//third_party/jvm/com/google/guava",
"//third_party/jvm/com/google/guava:failureaccess",
"//third_party/jvm/com/squareup:javapoet",
"//third_party/jvm/javax/inject:javax_inject",
],
visibility = [
"//third_party/jvm:__subpackages__"
]
)


Loading

0 comments on commit 7913363

Please sign in to comment.