kotlin model changes
diff --git a/kotlin/builder/integrationtests/KotlinBuilderTestCase.java b/kotlin/builder/integrationtests/KotlinBuilderTestCase.java
index cf23da1..f21119d 100644
--- a/kotlin/builder/integrationtests/KotlinBuilderTestCase.java
+++ b/kotlin/builder/integrationtests/KotlinBuilderTestCase.java
@@ -87,7 +87,7 @@
builder.clear();
builder.getInfoBuilder()
.setLabel("//some/bogus:" + label)
- .setKotlinModuleName("some_bogus_module")
+ .setModuleName("some_bogus_module")
.setRuleKind("kt_jvm_library")
.setToolchainInfo(
KotlinModel.KotlinToolchainInfo.newBuilder()
diff --git a/kotlin/builder/proto/BUILD b/kotlin/builder/proto/BUILD
index b16e4b6..d8d7109 100644
--- a/kotlin/builder/proto/BUILD
+++ b/kotlin/builder/proto/BUILD
@@ -13,7 +13,7 @@
# limitations under the License.
package(default_visibility=["//visibility:public"])
# commented out till 0.16 is released. We aren't prebuilding the libraries at the moment so it's fine.
-# TODO constrain the visibility when fixing the comments below as well
+# TODO constrain the visibility when fixing the comments below as well
#proto_library(
# name = "kotlin_model_proto",
# srcs = [":kotlin_model.proto"],
@@ -51,4 +51,4 @@
java_import(
name = "kotlin_model",
jars = ["jars/libkotlin_model_proto-speed.jar"],
-)
\ No newline at end of file
+)
diff --git a/kotlin/builder/proto/jars/libkotlin_model_proto-speed.jar b/kotlin/builder/proto/jars/libkotlin_model_proto-speed.jar
index 1a74d68..80467f0 100755
--- a/kotlin/builder/proto/jars/libkotlin_model_proto-speed.jar
+++ b/kotlin/builder/proto/jars/libkotlin_model_proto-speed.jar
Binary files differ
diff --git a/kotlin/builder/proto/kotlin_model.proto b/kotlin/builder/proto/kotlin_model.proto
index a66b7d3..7b5bb38 100644
--- a/kotlin/builder/proto/kotlin_model.proto
+++ b/kotlin/builder/proto/kotlin_model.proto
@@ -68,25 +68,18 @@
message CompilationTask {
message Info {
string label = 1;
- // derived from label
- string package = 2;
- // derived from label
- string target = 3;
-
- string rule_kind = 4;
- string kotlin_module_name = 5;
-
- string passthrough_flags = 6;
- KotlinToolchainInfo toolchain_info = 7;
-
- CompilerPlugins plugins = 8;
-
- // All of the plugin descriptors in the format kotlinc understands.
- // +derived
- repeated string encoded_plugin_descriptors = 9;
-
- // Jars that the kotlin compiler will allow package private access to.
- repeated string friend_paths = 10;
+ // The rule kind requesting the build.
+ string rule_kind = 2;
+ // The name of the module being compiled.
+ string module_name = 3;
+ // Flags to be passed straight through to the compiler.
+ string passthrough_flags = 4;
+ // Toolchain info for this build.
+ KotlinToolchainInfo toolchain_info = 5;
+ // Compiler plugin descriptors.
+ CompilerPlugins plugins = 6;
+ // Paths to Jars that the kotlin compiler will allow package private access to.
+ repeated string friend_paths = 7;
}
// Directories used by the builder.
@@ -114,28 +107,18 @@
message Inputs {
// The full classpath
repeated string classpath = 1;
- // The full joined classpath
- // +derived
- string joined_classpath = 2;
- // Direct dependencies of the target.
- map<string, string> direct_dependencies = 3;
- // Indirect dependencies of the target.
- map<string, string> indirect_dependencies = 4;
+ // Direct dependencies of the target.
+ map<string, string> direct_dependencies = 2;
+ // Indirect dependencies of the target.
+ map<string, string> indirect_dependencies = 3;
+
+ // Partitioned from the builder flags, expanding the source_jars.
+ repeated string kotlin_sources = 4;
// Partitioned from the builder flags and by expanding the source_jars.
- // +derived
- repeated string kotlin_sources = 5;
- // Partitioned from the builder flags and by expanding the source_jars.
- // +derived
- repeated string java_sources = 6;
- // Created during annotation processing and partitioned from the generated_sources directory.
- // +dervived
- repeated string generated_kotlin_sources = 7;
- // Created during annotation processing and partitioned from the generated_sources directory.
- // +derived
- repeated string generated_java_sources = 8;
+ repeated string java_sources = 5;
// Jars containing additional sources.
- repeated string source_jars = 9;
+ repeated string source_jars = 6;
}
Info info = 1;
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/TaskBuilder.kt b/kotlin/builder/src/io/bazel/kotlin/builder/TaskBuilder.kt
index 1746a8e..84d24fc 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/TaskBuilder.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/TaskBuilder.kt
@@ -24,9 +24,7 @@
import javax.inject.Singleton
@Singleton
-class TaskBuilder @Inject internal constructor(
- private val pluginEncoder: KotlinCompilerPluginArgsEncoder
-) {
+class TaskBuilder @Inject internal constructor() {
companion object {
@JvmStatic
private val jsonTypeRegistry = JsonFormat.TypeRegistry.newBuilder()
@@ -101,15 +99,12 @@
argMap.optional(JavaBuilderFlags.SOURCE_JARS.flag)?.also {
addAllSourceJars(it)
}
-
-
- joinedClasspath = classpathList.joinToString(":")
}
with(root.infoBuilder) {
label = argMap.mandatorySingle(JavaBuilderFlags.TARGET_LABEL.flag)
ruleKind = argMap.mandatorySingle(JavaBuilderFlags.RULE_KIND.flag)
- kotlinModuleName = argMap.mandatorySingle("--kotlin_module_name").also {
+ moduleName = argMap.mandatorySingle("--kotlin_module_name").also {
check(it.isNotBlank()) { "--kotlin_module_name should not be blank" }
}
passthroughFlags = argMap.optionalSingle("--kotlin_passthrough_flags")
@@ -124,16 +119,6 @@
it.build()
}
}
-
- if (plugins.annotationProcessorsList.isNotEmpty()) {
- addAllEncodedPluginDescriptors(pluginEncoder.encode(root))
- }
-
- label.split(":").also {
- check(it.size == 2) { "the label ${root.info.label} is invalid" }
- `package` = it[0]
- target = it[1]
- }
}
root.build()
}
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt
index e5053f4..ddbab12 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JDepsGenerator.kt
@@ -21,6 +21,7 @@
import io.bazel.kotlin.builder.CompilationException
import io.bazel.kotlin.builder.CompilationStatusException
import io.bazel.kotlin.builder.KotlinToolchain
+import io.bazel.kotlin.builder.utils.joinedClasspath
import io.bazel.kotlin.builder.utils.resolveVerified
import io.bazel.kotlin.builder.utils.rootCause
import io.bazel.kotlin.model.KotlinModel
@@ -51,9 +52,10 @@
} else {
ByteArrayOutputStream().use { out ->
PrintWriter(out).use { writer ->
+ val joinedClasspath = command.inputs.joinedClasspath
val res = invoker.run(
arrayOf(
- "-cp", command.inputs.joinedClasspath,
+ "-cp", joinedClasspath,
command.outputs.jdeps),
writer)
out.toByteArray().inputStream().bufferedReader().readLines().let {
@@ -64,7 +66,7 @@
JdepsParser.parse(
command.info.label,
command.outputs.jdeps,
- command.inputs.joinedClasspath,
+ joinedClasspath,
it,
isKotlinImplicit
)
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt
index 5f29bec..1fa912e 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/JavaCompiler.kt
@@ -20,6 +20,7 @@
import io.bazel.kotlin.builder.CompilationStatusException
import io.bazel.kotlin.builder.KotlinToolchain
import io.bazel.kotlin.builder.utils.addAll
+import io.bazel.kotlin.builder.utils.joinedClasspath
import io.bazel.kotlin.model.KotlinModel.CompilationTask
@ImplementedBy(DefaultJavaCompiler::class)
@@ -33,7 +34,7 @@
override fun compile(command: CompilationTask) {
val i = command.inputs
val d = command.directories
- if (i.javaSourcesList.isNotEmpty() || i.generatedJavaSourcesList.isNotEmpty()) {
+ if (i.javaSourcesList.isNotEmpty()) {
val args = mutableListOf(
"-cp", "${d.classes}/:${d.temp}/:${i.joinedClasspath}",
"-d", d.classes
@@ -47,7 +48,6 @@
"-target", command.info.toolchainInfo.jvm.jvmTarget
)
it.addAll(i.javaSourcesList)
- it.addAll(i.generatedJavaSourcesList)
it.toTypedArray()
}
javacInvoker.compile(args).takeIf { it != 0 }?.also { throw CompilationStatusException("javac failed", it) }
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinCompiler.kt b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinCompiler.kt
index 8721c73..0c7ec10 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinCompiler.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinCompiler.kt
@@ -18,11 +18,14 @@
import com.google.inject.ImplementedBy
import com.google.inject.Inject
import io.bazel.kotlin.builder.CompilationStatusException
+import io.bazel.kotlin.builder.KotlinCompilerPluginArgsEncoder
import io.bazel.kotlin.builder.KotlinToolchain
import io.bazel.kotlin.builder.utils.addAll
+import io.bazel.kotlin.builder.utils.joinedClasspath
import io.bazel.kotlin.model.KotlinModel
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
+import java.io.File
import java.io.PrintStream
@ImplementedBy(DefaultKotlinCompiler::class)
@@ -38,14 +41,15 @@
// 2 is an internal error
// 3 is the script execution error
private class DefaultKotlinCompiler @Inject constructor(
- val compiler: KotlinToolchain.KotlincInvoker
+ val compiler: KotlinToolchain.KotlincInvoker,
+ val pluginArgsEncoder: KotlinCompilerPluginArgsEncoder
) : KotlinCompiler {
override fun runAnnotationProcessor(command: KotlinModel.CompilationTask): List<String> {
check(command.info.plugins.annotationProcessorsList.isNotEmpty()) {
"method called without annotation processors"
}
return getCommonArgs(command).also {
- it.addAll(command.info.encodedPluginDescriptorsList)
+ it.addAll(pluginArgsEncoder.encode(command))
it.addAll(command.inputs.kotlinSourcesList)
it.addAll(command.inputs.javaSourcesList)
}.let { invokeCompilePhase(it) }
@@ -64,11 +68,11 @@
"-language-version", command.info.toolchainInfo.common.languageVersion,
"-jvm-target", command.info.toolchainInfo.jvm.jvmTarget,
// https://github.com/bazelbuild/rules_kotlin/issues/69: remove once jetbrains adds a flag for it.
- "--friend-paths", command.info.friendPathsList.joinToString(":")
+ "--friend-paths", command.info.friendPathsList.joinToString(File.pathSeparator)
)
args
- .addAll("-module-name", command.info.kotlinModuleName)
+ .addAll("-module-name", command.info.moduleName)
.addAll("-d", command.directories.classes)
command.info.passthroughFlags?.takeIf { it.isNotBlank() }?.also { args.addAll(it.split(" ")) }
@@ -78,9 +82,7 @@
override fun compile(command: KotlinModel.CompilationTask): List<String> =
with(getCommonArgs(command)) {
addAll(command.inputs.javaSourcesList)
- addAll(command.inputs.generatedJavaSourcesList)
addAll(command.inputs.kotlinSourcesList)
- addAll(command.inputs.generatedKotlinSourcesList)
invokeCompilePhase(this)
}
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
index 505e77b..e152033 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt
@@ -19,7 +19,7 @@
import com.google.inject.Inject
import com.google.inject.Singleton
import io.bazel.kotlin.builder.CompilationStatusException
-import io.bazel.kotlin.builder.utils.expandWithGeneratedSources
+import io.bazel.kotlin.builder.utils.expandWithSources
import io.bazel.kotlin.model.KotlinModel.CompilationTask
import java.io.File
import java.util.concurrent.TimeUnit
@@ -58,7 +58,7 @@
.filter { it.isFile }
.map { it.path }
.iterator()
- .let { command.expandWithGeneratedSources(it) }
+ .let { command.expandWithSources(it) }
} else {
command
}
diff --git a/kotlin/builder/src/io/bazel/kotlin/builder/utils/TaskUtils.kt b/kotlin/builder/src/io/bazel/kotlin/builder/utils/TaskUtils.kt
index 2eb749d..55cfc0e 100644
--- a/kotlin/builder/src/io/bazel/kotlin/builder/utils/TaskUtils.kt
+++ b/kotlin/builder/src/io/bazel/kotlin/builder/utils/TaskUtils.kt
@@ -15,31 +15,23 @@
*/
package io.bazel.kotlin.builder.utils
-import io.bazel.kotlin.model.KotlinModel
+import io.bazel.kotlin.model.KotlinModel.CompilationTask
+import java.io.File
-
-fun KotlinModel.CompilationTask.expandWithSources(
+fun CompilationTask.expandWithSources(
sources: Iterator<String>
-): KotlinModel.CompilationTask =
+): CompilationTask =
updateBuilder { builder ->
sources.partitionSources(
{ builder.inputsBuilder.addKotlinSources(it) },
{ builder.inputsBuilder.addJavaSources(it) })
}
+val CompilationTask.Inputs.joinedClasspath: String get() = this.classpathList.joinToString(File.pathSeparator)
-fun KotlinModel.CompilationTask.expandWithGeneratedSources(
- sources: Iterator<String>
-): KotlinModel.CompilationTask =
- updateBuilder { builder ->
- sources.partitionSources(
- { builder.inputsBuilder.addGeneratedKotlinSources(it) },
- { builder.inputsBuilder.addGeneratedJavaSources(it) })
- }
-
-private fun KotlinModel.CompilationTask.updateBuilder(
- init: (KotlinModel.CompilationTask.Builder) -> Unit
-): KotlinModel.CompilationTask =
+private fun CompilationTask.updateBuilder(
+ init: (CompilationTask.Builder) -> Unit
+): CompilationTask =
toBuilder().let {
init(it)
it.build()