From c6ef4853704080b1340170c5c30046cc4dacd418 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 28 Mar 2022 18:27:17 -0700 Subject: Use kapt stubs for kotlin header jar for javac When compling kotlin code with annotation processors we are generating java stubs for the kotlin sources using kapt, and parsing them in turbine when running the annotation processors. Passing --output to turbine will also compile the stubs into a header jar that can be used as a dependency to javac, allowing the javac and kotlinc rules to run in parallel. The turbine-apt header jar can't be used as the header jar for downstream modules as it doesn't contain the kotlin metadata needed by kotlinc rules, so the kotlinc gen-jvm-abi plugin output is still used for the module's final header jar. Test: TestKapt Bug: 222095735 Change-Id: I82d0900f3dc30f3e3ebd7cab0693dfe741d9b955 --- java/kotlin.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'java/kotlin.go') diff --git a/java/kotlin.go b/java/kotlin.go index eff5bb53f..818bbd5aa 100644 --- a/java/kotlin.go +++ b/java/kotlin.go @@ -163,11 +163,11 @@ var kaptStubs = pctx.AndroidRemoteStaticRule("kaptStubs", android.RemoteRuleSupp "classpath", "srcJars", "commonSrcFilesArg", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile", "name", "classesJarOut") -// kotlinKapt performs Kotlin-compatible annotation processing. It takes .kt and .java sources and srcjars, and runs +// kotlinTurbineApt performs Kotlin-compatible annotation processing. It takes .kt and .java sources and srcjars, and runs // annotation processors over all of them, producing a srcjar of generated code in outputFile. The srcjar should be // added as an additional input to kotlinc and javac rules, and the javac rule should have annotation processing // disabled. -func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile android.WritablePath, +func kotlinTurbineApt(ctx android.ModuleContext, headerJarOutputFile, srcJarOutputFile, resJarOutputFile android.WritablePath, srcFiles, commonSrcFiles, srcJars android.Paths, flags javaBuilderFlags) { @@ -231,7 +231,7 @@ func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile an // Then run turbine to perform annotation processing on the stubs and any .java srcFiles. javaSrcFiles := srcFiles.FilterByExt(".java") turbineSrcJars := append(android.Paths{kaptStubsJar}, srcJars...) - TurbineApt(ctx, srcJarOutputFile, resJarOutputFile, javaSrcFiles, turbineSrcJars, flags) + TurbineApt(ctx, headerJarOutputFile, srcJarOutputFile, resJarOutputFile, javaSrcFiles, turbineSrcJars, flags) } // kapt converts a list of key, value pairs into a base64 encoded Java serialization, which is what kapt expects. -- cgit v1.2.3-59-g8ed1b