diff --git a/kotlin/internal/jvm/impl.bzl b/kotlin/internal/jvm/impl.bzl index 8d8977b49..1f4640a7b 100644 --- a/kotlin/internal/jvm/impl.bzl +++ b/kotlin/internal/jvm/impl.bzl @@ -188,7 +188,7 @@ def kt_jvm_import_impl(ctx): runfiles = ctx.runfiles( # Append class jar with the optional sources jar files = [artifact.class_jar] + [artifact.source_jar] if artifact.source_jar else [], - ), + ).merge_all([d[DefaultInfo].default_runfiles for d in ctx.attr.deps]), ), JavaInfo( output_jar = artifact.class_jar, diff --git a/src/main/kotlin/BUILD.release.bazel b/src/main/kotlin/BUILD.release.bazel index 2bad2944c..36653d659 100644 --- a/src/main/kotlin/BUILD.release.bazel +++ b/src/main/kotlin/BUILD.release.bazel @@ -41,11 +41,16 @@ java_binary( ":skip-code-gen", "//src/main/kotlin/io/bazel/kotlin/compiler", "@com_github_jetbrains_kotlin//:jvm-abi-gen", + "@com_github_jetbrains_kotlin//:kotlin-annotation-processing", "@com_github_jetbrains_kotlin//:kotlin-compiler", ], jvm_flags = [ - "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rootpath @com_github_jetbrains_kotlin//:jvm-abi-gen)", - "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rootpath @com_github_jetbrains_kotlin//:kotlin-compiler)", + "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath @com_github_jetbrains_kotlin//:jvm-abi-gen)", + "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-compiler)", + "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-annotation-processing)", + "-D@rules_kotlin...jdeps-gen=$(rlocationpath //src/main/kotlin:jdeps-gen)", + "-D@rules_kotlin...skip-code-gen=$(rlocationpath //src/main/kotlin:skip-code-gen)", + "-D@rules_kotlin...compiler=$(rlocationpath //src/main/kotlin/io/bazel/kotlin/compiler)", "-XX:-MaxFDLimit", ], main_class = "io.bazel.kotlin.builder.cmd.Build", diff --git a/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel index b50e1c9b9..0fdacb7e7 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/builder/cmd/BUILD.bazel @@ -19,11 +19,17 @@ kt_bootstrap_binary( "//src/main/kotlin:skip-code-gen", "//src/main/kotlin/io/bazel/kotlin/compiler", "@com_github_jetbrains_kotlin//:jvm-abi-gen", + "@com_github_jetbrains_kotlin//:kotlin-annotation-processing", "@com_github_jetbrains_kotlin//:kotlin-compiler", ], jvm_flags = [ - "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rootpath @com_github_jetbrains_kotlin//:jvm-abi-gen)", - "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rootpath @com_github_jetbrains_kotlin//:kotlin-compiler)", + "-D@com_github_jetbrains_kotlin...jvm-abi-gen=$(rlocationpath @com_github_jetbrains_kotlin//:jvm-abi-gen)", + "-D@com_github_jetbrains_kotlin...kotlin-compiler=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-compiler)", + "-D@com_github_jetbrains_kotlin...kapt=$(rlocationpath @com_github_jetbrains_kotlin//:kotlin-annotation-processing)", + "-D@rules_kotlin...jdeps-gen=$(rlocationpath //src/main/kotlin:jdeps-gen)", + "-D@rules_kotlin...skip-code-gen=$(rlocationpath //src/main/kotlin:skip-code-gen)", + "-D@rules_kotlin...compiler=$(rlocationpath //src/main/kotlin/io/bazel/kotlin/compiler)", + "-XX:-MaxFDLimit", ], main_class = "io.bazel.kotlin.builder.cmd.Build", runtime_library = ":build_lib", diff --git a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt index c83c02007..b6e62227e 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt +++ b/src/main/kotlin/io/bazel/kotlin/builder/toolchain/KotlinToolchain.kt @@ -32,118 +32,127 @@ import javax.inject.Inject import javax.inject.Singleton class KotlinToolchain private constructor( - val kotlinHome: Path, val classLoader: ClassLoader, - val kapt3Plugin: CompilerPlugin = CompilerPlugin( - kotlinHome.resolveVerified("lib", "kotlin-annotation-processing.jar").absolutePath, - "org.jetbrains.kotlin.kapt3", - ), + val kapt3Plugin: CompilerPlugin, val jvmAbiGen: CompilerPlugin, val skipCodeGen: CompilerPlugin, val jdepsGen: CompilerPlugin, ) { companion object { - // TODO(issue/432): Remove this gross hack and pass the file locations on the command line. - private var RULES_REPOSITORY_NAME = - System.getenv("TEST_WORKSPACE")?.takeIf { it.isNotBlank() } - ?: System.getenv("REPOSITORY_NAME")?.takeIf { it.isNotBlank() } - // ?: System.getProperty("TEST_WORKSPACE")?.takeIf { it.isNotBlank() } - ?: error( - "Unable to determine rules_kotlin repository " + - "name.\nenv:${System.getenv()}\nproperties:${System.getProperties()}", - ) + private val JVM_ABI_PLUGIN by lazy { + BazelRunFiles.resolveVerifiedFromProperty( + "@com_github_jetbrains_kotlin...jvm-abi-gen", + ).toPath() + } + + private val KAPT_PLUGIN by lazy { + BazelRunFiles.resolveVerifiedFromProperty( + "@com_github_jetbrains_kotlin...kapt", + ).toPath() + } + + private val COMPILER by lazy { + BazelRunFiles.resolveVerifiedFromProperty( + "@rules_kotlin...compiler", + ).toPath() + } - private val DEFAULT_JVM_ABI_PATH = BazelRunFiles.resolveVerified( - System.getProperty("@com_github_jetbrains_kotlin...jvm-abi-gen"), - ).toPath() - - private val COMPILER = BazelRunFiles.resolveVerified( - RULES_REPOSITORY_NAME, - "src", "main", "kotlin", "io", "bazel", "kotlin", "compiler", - "compiler.jar", - ).toPath() - - private val SKIP_CODE_GEN_PLUGIN = BazelRunFiles.resolveVerified( - RULES_REPOSITORY_NAME, - "src", - "main", - "kotlin", - "skip-code-gen.jar", - ).toPath() - - private val JDEPS_GEN_PLUGIN = BazelRunFiles.resolveVerified( - RULES_REPOSITORY_NAME, - "src", - "main", - "kotlin", - "jdeps-gen.jar", - ).toPath() + private val SKIP_CODE_GEN_PLUGIN by lazy { + BazelRunFiles.resolveVerifiedFromProperty( + "@rules_kotlin...skip-code-gen", + ).toPath() + } + + private val JDEPS_GEN_PLUGIN by lazy { + BazelRunFiles.resolveVerifiedFromProperty( + "@rules_kotlin...jdeps-gen", + ).toPath() + } + + private val KOTLINC by lazy { + BazelRunFiles.resolveVerifiedFromProperty( + "@com_github_jetbrains_kotlin...kotlin-compiler", + ).toPath() + } internal val NO_ARGS = arrayOf() private val isJdk9OrNewer = !System.getProperty("java.version").startsWith("1.") private fun createClassLoader(javaHome: Path, baseJars: List): ClassLoader = - ClassPreloadingUtils.preloadClasses( - mutableListOf().also { - it += baseJars - if (!isJdk9OrNewer) { - it += javaHome.resolveVerified("lib", "tools.jar") - } - }, - Preloader.DEFAULT_CLASS_NUMBER_ESTIMATE, - ClassLoader.getSystemClassLoader(), - null, - ) + runCatching { + ClassPreloadingUtils.preloadClasses( + mutableListOf().also { + it += baseJars + if (!isJdk9OrNewer) { + it += javaHome.resolveVerified("lib", "tools.jar") + } + }, + Preloader.DEFAULT_CLASS_NUMBER_ESTIMATE, + ClassLoader.getSystemClassLoader(), + null, + ) + }.onFailure { + throw RuntimeException("$javaHome, $baseJars", it) + }.getOrThrow() @JvmStatic fun createToolchain(): KotlinToolchain { - return createToolchain(DEFAULT_JVM_ABI_PATH) + return createToolchain( + FileSystems.getDefault().getPath(System.getProperty("java.home")).let { path -> + path.takeIf { !it.endsWith(Paths.get("jre")) } ?: path.parent + }.verifiedPath(), + KOTLINC.verified().absoluteFile, + COMPILER.verified().absoluteFile, + JVM_ABI_PLUGIN.verified().absoluteFile, + SKIP_CODE_GEN_PLUGIN.verified().absoluteFile, + JDEPS_GEN_PLUGIN.verified().absoluteFile, + KAPT_PLUGIN.verified().absoluteFile, + ) } @JvmStatic - fun createToolchain(jvmAbiGenPath: Path): KotlinToolchain { - val df = FileSystems.getDefault() - val javaHome = df.getPath(System.getProperty("java.home")).let { path -> - path.takeIf { !it.endsWith(Paths.get("jre")) } ?: path.parent - }.verifiedPath() - - val skipCodeGenFile = SKIP_CODE_GEN_PLUGIN.verified().absoluteFile - val jdepsGenFile = JDEPS_GEN_PLUGIN.verified().absoluteFile - - val kotlinCompilerJar = BazelRunFiles.resolveVerified( - System.getProperty("@com_github_jetbrains_kotlin...kotlin-compiler"), - ) - - val jvmAbiGenFile = jvmAbiGenPath.verified() + fun createToolchain( + javaHome: Path, + kotlinc: File, + compiler: File, + jvmAbiGenFile: File, + skipCodeGenFile: File, + jdepsGenFile: File, + kaptFile: File, + ): KotlinToolchain { return KotlinToolchain( - kotlinCompilerJar.toPath().parent.parent, createClassLoader( javaHome, listOf( - kotlinCompilerJar, - COMPILER.verified().absoluteFile, + kotlinc, + compiler, // plugins *must* be preloaded. Not doing so causes class conflicts // (and a NoClassDef err) in the compiler extension interfaces. // This may cause issues in accepting user defined compiler plugins. - jvmAbiGenFile.absoluteFile, + jvmAbiGenFile, skipCodeGenFile, jdepsGenFile, + kaptFile, ), ), jvmAbiGen = CompilerPlugin( - jvmAbiGenFile.absolutePath, + jvmAbiGenFile.path, "org.jetbrains.kotlin.jvm.abi", ), skipCodeGen = CompilerPlugin( - skipCodeGenFile.absolutePath, + skipCodeGenFile.path, "io.bazel.kotlin.plugin.SkipCodeGen", ), jdepsGen = CompilerPlugin( - jdepsGenFile.absolutePath, + jdepsGenFile.path, "io.bazel.kotlin.plugin.jdeps.JDepsGen", ), + kapt3Plugin = CompilerPlugin( + kaptFile.path, + "org.jetbrains.kotlin.kapt3", + ), ) } } diff --git a/src/main/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel b/src/main/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel index 90be5e793..1f5982c55 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel +++ b/src/main/kotlin/io/bazel/kotlin/builder/utils/BUILD.bazel @@ -11,6 +11,7 @@ kt_bootstrap_library( "//src/main/protobuf:deps_java_proto", "//src/main/protobuf:kotlin_model_java_proto", "//src/main/protobuf:worker_protocol_java_proto", + "@bazel_tools//tools/java/runfiles", "@kotlin_rules_maven//:com_google_protobuf_protobuf_java", "@kotlin_rules_maven//:com_google_protobuf_protobuf_java_util", ], diff --git a/src/main/kotlin/io/bazel/kotlin/builder/utils/BazelRunFiles.kt b/src/main/kotlin/io/bazel/kotlin/builder/utils/BazelRunFiles.kt index 108ed6e6e..3003763de 100644 --- a/src/main/kotlin/io/bazel/kotlin/builder/utils/BazelRunFiles.kt +++ b/src/main/kotlin/io/bazel/kotlin/builder/utils/BazelRunFiles.kt @@ -15,82 +15,33 @@ */ package io.bazel.kotlin.builder.utils +import com.google.devtools.build.runfiles.Runfiles import java.io.File -import java.io.FileInputStream -import java.nio.charset.Charset -import java.nio.file.Paths -import java.util.Collections +import java.io.FileNotFoundException /** Utility class for getting runfiles on windows and *nix. */ object BazelRunFiles { - private val isWindows = System.getProperty("os.name").lowercase().indexOf("win") >= 0 - - /** - * Set depending on --enable_runfiles, which defaults to false on Windows and true otherwise. - */ - private val manifestFile: String? = - if (isWindows) { - System.getenv("RUNFILES_MANIFEST_FILE") - } else { - null - } - - private val javaRunFiles = Paths.get(System.getenv("JAVA_RUNFILES")) private val runfiles by lazy { - with(mutableMapOf()) { - FileInputStream(manifestFile) - .bufferedReader(Charset.forName("UTF-8")) - .lines() - .forEach { it -> - val line = it.trim { it <= ' ' } - if (!line.isEmpty()) { - // TODO(bazel-team): This is buggy when the path contains spaces, we should fix the manifest format. - line.split(" ").also { - check(it.size == 2) { "RunFiles manifest entry $line contains more than one space" } - put(it[0], it[1]) - } - } - } - Collections.unmodifiableMap(this) - } + Runfiles.preload().unmapped() } /** * Resolve a run file on windows or *nix. */ @JvmStatic - fun resolveVerified(vararg path: String): File { - check(path.isNotEmpty()) - val fromManifest = manifestFile?.let { mf -> - path.joinToString("/").let { rfPath -> - // trim off the external/ prefix if it is present. - val trimmedPath = - if (rfPath.startsWith("external/")) { - rfPath.replaceFirst("external/", "") - } else { - rfPath - } - File( - checkNotNull(runfiles[trimmedPath]) { - "runfile manifest $mf did not contain path mapping for $rfPath" - }, - ) - }.also { - check(it.exists()) { "file $it resolved from runfiles did not exist" } + fun resolveVerifiedFromProperty(key: String) = + System.getProperty(key) + ?.let { path -> runfiles.rlocation(path) } + ?.let { File(it) } + ?.also { + if (!it.exists()) { + throw IllegalStateException( + "$it does not exist in the runfiles!", + ) + } + } + ?: let { + throw FileNotFoundException("no reference for $key in ${System.getProperties()}") } - } - if (fromManifest != null) { - return fromManifest - } - - // / if it could not be resolved from the manifest then first try to resolve it directly. - val resolvedDirect = File(path.joinToString(File.separator)).takeIf { it.exists() } - if (resolvedDirect != null) { - return resolvedDirect - } - - // Try the java runfiles as the last resort. - return javaRunFiles.resolveVerified(path.joinToString(File.separator)) - } } diff --git a/src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel b/src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel index 85dbde4cc..7efddcef7 100644 --- a/src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel +++ b/src/main/starlark/core/repositories/BUILD.com_github_jetbrains_kotlin.bazel @@ -21,13 +21,20 @@ package(default_visibility = ["//visibility:public"]) # Kotlin home filegroup containing everything that is needed. filegroup( name = "home", - srcs = glob(["**"]), + srcs = glob([ + "**", + "**/*.jar", + ]), ) kt_jvm_import( name = "annotations", jar = "lib/annotations-13.0.jar", - neverlink = 1, +) + +kt_jvm_import( + name = "trove4j", + jar = "lib/trove4j.jar", ) kt_jvm_import( @@ -35,19 +42,27 @@ kt_jvm_import( jar = "lib/jvm-abi-gen.jar", ) -# Kotlin dependencies that are internal to this repo and are meant to be loaded manually into a classloader. -[ - kt_jvm_import( - name = "kotlin-%s" % art, - jar = "lib/kotlin-%s.jar" % art, - neverlink = 1, - ) - for art in [ - "annotation-processing", - "annotation-processing-runtime", - "compiler", - ] -] +kt_jvm_import( + name = "kotlin-compiler", + jar = "lib/kotlin-compiler.jar", + deps = [ + ":annotations", + ":kotlin-reflect", + ":kotlin-script-runtime", + ":kotlin-stdlib", + ":trove4j", + ], +) + +kt_jvm_import( + name = "kotlin-annotation-processing-runtime", + jar = "lib/kotlin-annotation-processing-runtime.jar", +) + +kt_jvm_import( + name = "kotlin-annotation-processing", + jar = "lib/kotlin-annotation-processing.jar", +) kt_jvm_import( name = "kotlinx-serialization-compiler-plugin", diff --git a/src/test/kotlin/io/bazel/kotlin/builder/Deps.java b/src/test/kotlin/io/bazel/kotlin/builder/Deps.java index be098346f..4e6447820 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/Deps.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/Deps.java @@ -44,17 +44,6 @@ public static Stream classpathOf(Dep... dependencies) { return Stream.of(dependencies).flatMap(it -> it.compileJars().stream()); } - /** - * Import a single dep. Similar to a `kt_jvm_import` or a `kt_js_import`. - */ - public static Dep importJar(String label, String compileJar) { - return Dep.builder() - .label(label) - .compileJars( - ImmutableList.of(BazelRunFiles.resolveVerified(compileJar).getAbsolutePath())) - .build(); - } - /** * Import a single dep. Similar to a `kt_jvm_import` or a `kt_js_import`. */ @@ -74,7 +63,7 @@ public static Dep importJar(String label, File compileJar) { * passing. * * @param label The label of the resource expected to be included - * @return Dep reprenseting the resource + * @return Dep representing the resource * @throws IllegalArgumentException if the label does not exist. */ public static Dep fromLabel(String label) { @@ -91,7 +80,7 @@ public static Dep fromLabel(String label) { .label(label) .compileJars( ImmutableList.of( - BazelRunFiles.resolveVerified(properties.getProperty(key)).getPath())) + BazelRunFiles.resolveVerifiedFromProperty(key).getPath())) .build(); } diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java index 272d7d60d..1489d4bd8 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinAbstractTestBuilder.java @@ -18,12 +18,14 @@ import io.bazel.kotlin.builder.toolchain.CompilationStatusException; import io.bazel.kotlin.builder.toolchain.CompilationTaskContext; +import io.bazel.kotlin.builder.toolchain.KotlinToolchain; import io.bazel.kotlin.model.CompilationTaskInfo; import io.bazel.kotlin.model.KotlinToolchainInfo; import io.bazel.kotlin.model.Platform; import io.bazel.kotlin.model.RuleKind; import java.io.*; +import java.nio.file.FileSystem; import java.nio.file.FileSystems; import java.nio.file.Files; import java.nio.file.Path; @@ -56,7 +58,7 @@ private static void assertFileExistence(Stream pathStream, boolean shouldE pathStream.forEach( path -> { if (shouldExist) - assertWithMessage("file did not exist: " + path).that(path.toFile().exists()).isTrue(); + assertWithMessage("file did not exist: %s", path).that(path.toFile().exists()).isTrue(); else assertWithMessage("file existed: " + path).that(path.toFile().exists()).isFalse(); }); } @@ -160,6 +162,7 @@ private R runCompileTask( .lines() .collect(toList())); } + } public final void assertFilesExist(DirectoryType dir, String... paths) { @@ -217,4 +220,21 @@ public final void logDirectoryContents(DirectoryType type) { .map(Path::toString) .collect(Collectors.joining("\n", "directory " + type.name + " contents:\n", ""))); } + + static KotlinToolchain toolchainForTest() { + FileSystem fd = FileSystems.getDefault(); + Path javaHome = fd.getPath(System.getProperty("java.home")); + if (javaHome.endsWith(fd.getPath("jre"))) { + javaHome = javaHome.getParent(); + } + return KotlinToolchain.createToolchain( + javaHome, + new File(Deps.Dep.fromLabel("@com_github_jetbrains_kotlin//:kotlin-compiler").singleCompileJar()), + new File(Deps.Dep.fromLabel("//src/main/kotlin/io/bazel/kotlin/compiler").singleCompileJar()), + new File(Deps.Dep.fromLabel("@com_github_jetbrains_kotlin//:jvm-abi-gen").singleCompileJar()), + new File(Deps.Dep.fromLabel("//src/main/kotlin:skip-code-gen").singleCompileJar()), + new File(Deps.Dep.fromLabel("//src/main/kotlin:jdeps-gen").singleCompileJar()), + new File(Deps.Dep.fromLabel("@com_github_jetbrains_kotlin//:kotlin-annotation-processing").singleCompileJar()) + ); + } } diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinJsTestBuilder.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinJsTestBuilder.java index e9d3e4a5c..fc89b6b0e 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinJsTestBuilder.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinJsTestBuilder.java @@ -15,7 +15,6 @@ */ package io.bazel.kotlin.builder; -import io.bazel.kotlin.builder.toolchain.KotlinToolchain; import io.bazel.kotlin.model.CompilationTaskInfo; import io.bazel.kotlin.model.JsCompilationTask; @@ -29,7 +28,7 @@ public final class KotlinJsTestBuilder extends KotlinAbstractTestBuilder ALL_DIRECTORY_TYPES = EnumSet.of(DirectoryType.SOURCES); private final TaskBuilder taskBuilderInstance = new TaskBuilder(); diff --git a/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java b/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java index 6f44eddc8..b74a91486 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/KotlinJvmTestBuilder.java @@ -21,7 +21,6 @@ import io.bazel.kotlin.builder.Deps.AnnotationProcessor; import io.bazel.kotlin.builder.Deps.Dep; import io.bazel.kotlin.builder.toolchain.CompilationTaskContext; -import io.bazel.kotlin.builder.toolchain.KotlinToolchain; import io.bazel.kotlin.model.CompilationTaskInfo; import io.bazel.kotlin.model.JvmCompilationTask; @@ -90,8 +89,8 @@ public final Dep runCompileTask(Consumer... setup) { private static KotlinBuilderTestComponent component() { if (component == null) { component = DaggerKotlinBuilderTestComponent.builder() - .toolchain(KotlinToolchain.createToolchain()) - .build(); + .toolchain(toolchainForTest()) + .build(); } return component; } @@ -108,10 +107,10 @@ private Dep executeTask( JvmCompilationTask.Outputs outputs = task.getOutputs(); assertFilesExist( Stream.of( - outputs.getAbijar(), - outputs.getJar(), - outputs.getJdeps(), - outputs.getSrcjar()) + outputs.getAbijar(), + outputs.getJar(), + outputs.getJdeps(), + outputs.getSrcjar()) .filter(p -> !p.isEmpty()) .toArray(String[]::new) ); @@ -156,6 +155,7 @@ public TaskBuilder compileJava() { } public TaskBuilder compileKotlin() { + taskBuilder.setInfo(CompilationTaskInfo.newBuilder().addDebug("trace").addDebug("timings")); taskBuilder.setCompileKotlin(true); return this; } @@ -224,19 +224,19 @@ public TaskBuilder outputAbiJar() { public TaskBuilder generatedSourceJar() { taskBuilder.getOutputsBuilder() - .setGeneratedJavaSrcJar(instanceRoot().resolve("gen-src.jar").toAbsolutePath().toString()); + .setGeneratedJavaSrcJar(instanceRoot().resolve("gen-src.jar").toAbsolutePath().toString()); return this; } public TaskBuilder ktStubsJar() { taskBuilder.getOutputsBuilder() - .setGeneratedJavaStubJar(instanceRoot().resolve("kt-stubs.jar").toAbsolutePath().toString()); + .setGeneratedJavaStubJar(instanceRoot().resolve("kt-stubs.jar").toAbsolutePath().toString()); return this; } public TaskBuilder incrementalData() { taskBuilder.getOutputsBuilder() - .setGeneratedClassJar(instanceRoot().resolve("incremental.jar").toAbsolutePath().toString()); + .setGeneratedClassJar(instanceRoot().resolve("incremental.jar").toAbsolutePath().toString()); return this; } diff --git a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmAbiTest.java b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmAbiTest.java index bd05a1bff..7f11c07ea 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmAbiTest.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmAbiTest.java @@ -18,7 +18,6 @@ import io.bazel.kotlin.builder.Deps; import io.bazel.kotlin.builder.KotlinJvmTestBuilder; -import java.util.function.Consumer; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; diff --git a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmKaptTest.java b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmKaptTest.java index 748a6afe3..8e1ec699e 100644 --- a/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmKaptTest.java +++ b/src/test/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinBuilderJvmKaptTest.java @@ -23,7 +23,6 @@ import org.junit.runner.RunWith; import org.junit.runners.JUnit4; -import java.io.File; import java.util.function.Consumer; import java.util.stream.Collectors; diff --git a/src/test/kotlin/io/bazel/kotlin/defs.bzl b/src/test/kotlin/io/bazel/kotlin/defs.bzl index f608ed1af..6e3cb6148 100644 --- a/src/test/kotlin/io/bazel/kotlin/defs.bzl +++ b/src/test/kotlin/io/bazel/kotlin/defs.bzl @@ -28,6 +28,7 @@ def kt_rules_test(name, **kwargs): args.setdefault("size", "small") args.setdefault("data", []) args.setdefault("jvm_flags", []) + args["deps"] = args.setdefault("deps", []) + ["//src/test/kotlin/io/bazel/kotlin/builder:test_lib"] for dep in [ "//src/main/kotlin/io/bazel/kotlin/compiler", @@ -39,10 +40,11 @@ def kt_rules_test(name, **kwargs): "@com_github_jetbrains_kotlin//:kotlin-stdlib", "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk7", "@com_github_jetbrains_kotlin//:kotlin-stdlib-jdk8", + "@com_github_jetbrains_kotlin//:kotlin-annotation-processing", ] + args["data"]: if dep not in args["data"]: args["data"].append(dep) - args["jvm_flags"].append("-D%s=$(rootpath %s)" % (dep.replace("/", ".").replace(":", "."), dep)) + args["jvm_flags"].append("-D%s=$(rlocationpath %s)" % (dep.replace("/", ".").replace(":", "."), dep)) args.setdefault("test_class", _get_class_name(kwargs)) for f in args.get("srcs"):