in src/main/kotlin/io/bazel/kotlin/builder/tasks/jvm/KotlinJvmTaskExecutor.kt [51:143]
fun execute(context: CompilationTaskContext, task: JvmCompilationTask) {
val preprocessedTask = task
.preProcessingSteps(context)
.runPlugins(context, plugins, compiler)
context.execute("compile classes") {
preprocessedTask.apply {
sequenceOf(
runCatching {
context.execute("kotlinc") {
if (compileKotlin) {
compileKotlin(
context,
compiler,
args = baseArgs()
.given(outputs.jdeps).notEmpty {
plugin(plugins.jdeps) {
flag("output", outputs.jdeps)
flag("target_label", info.label)
inputs.directDependenciesList.forEach {
flag("direct_dependencies", it)
}
flag("strict_kotlin_deps", info.strictKotlinDeps)
}
}
.given(outputs.jar).notEmpty {
append(codeGenArgs())
}
.given(outputs.abijar).notEmpty {
plugin(plugins.jvmAbiGen) {
flag("outputDir", directories.abiClasses)
}
given(outputs.jar).empty {
plugin(plugins.skipCodeGen)
}
},
printOnFail = false)
} else {
emptyList()
}
}
context.execute("javac") {
if (compileJava) {
javaCompiler.compile(context, this)
} else {
emptyList()
}
}
}
).map {
(it.getOrNull() ?: emptyList()) to it.exceptionOrNull()
}.map {
when (it.second) {
// TODO(issue/296): remove when the CompilationStatusException is unified.
is CompilationStatusException ->
(it.second as CompilationStatusException).lines + it.first to it.second
else -> it
}
}.fold(Pair<List<String>, Throwable?>(emptyList(), null)) { acc, result ->
acc.first + result.first to combine(acc.second, result.second)
}.apply {
first.apply(context::printCompilerOutput)
second?.let {
throw it
}
}
if (outputs.jar.isNotEmpty()) {
if (instrumentCoverage) {
context.execute("create instrumented jar", ::createCoverageInstrumentedJar)
} else {
context.execute("create jar", ::createOutputJar)
}
}
if (outputs.abijar.isNotEmpty()) {
context.execute("create abi jar", ::createAbiJar)
}
if (outputs.javaJdeps.isNotEmpty()) {
context.execute("generate jdeps for Java compilation") { jDepsGenerator.generateJDeps(this) }
}
if (outputs.generatedJavaSrcJar.isNotEmpty()) {
context.execute("creating KAPT generated Java source jar", ::createGeneratedJavaSrcJar)
}
if (outputs.generatedJavaStubJar.isNotEmpty()) {
context.execute("creating KAPT generated Kotlin stubs jar", ::createGeneratedStubJar)
}
if (outputs.generatedClassJar.isNotEmpty()) {
context.execute("creating KAPT generated stub class jar", ::createGeneratedClassJar)
}
}
}
}