aboutsummaryrefslogtreecommitdiffstats
path: root/java/kotlin.go
diff options
context:
space:
mode:
authorColin Cross <ccross@android.com>2020-06-18 15:46:32 -0700
committerColin Cross <ccross@android.com>2020-06-19 12:53:09 -0700
commit3791b45f670062d8d01c87b1debb7c36cbed9e70 (patch)
tree8001bfe3d6e59170071adf5b8605eb01dcfa3d50 /java/kotlin.go
parent1e28e3c61593571db5ecea328d134ee50501104d (diff)
downloadbuild_soong-3791b45f670062d8d01c87b1debb7c36cbed9e70.tar.gz
build_soong-3791b45f670062d8d01c87b1debb7c36cbed9e70.tar.bz2
build_soong-3791b45f670062d8d01c87b1debb7c36cbed9e70.zip
Fix annotation processors in kotlin modules that generate resources
The kapt rule was only keeping the generated sources, and not the generated classes directory. The generated classes directory will contain resources generated by the annotation processor and needs to be added to the final jar. Test: m ApiFinder Bug: 153485543 Change-Id: I89197d0afcb1eee011c01aa400f9977e66f43768 Merged-In: I89197d0afcb1eee011c01aa400f9977e66f43768 (cherry picked from commit 9ca38d22a49127901dadb14ffa093e29a2942f2d)
Diffstat (limited to 'java/kotlin.go')
-rw-r--r--java/kotlin.go21
1 files changed, 13 insertions, 8 deletions
diff --git a/java/kotlin.go b/java/kotlin.go
index 9b160a08..673970b9 100644
--- a/java/kotlin.go
+++ b/java/kotlin.go
@@ -90,7 +90,8 @@ func kotlinCompile(ctx android.ModuleContext, outputFile android.WritablePath,
var kapt = pctx.AndroidRemoteStaticRule("kapt", android.RemoteRuleSupports{Goma: true},
blueprint.RuleParams{
- Command: `rm -rf "$srcJarDir" "$kotlinBuildFile" "$kaptDir" && mkdir -p "$srcJarDir" "$kaptDir" && ` +
+ Command: `rm -rf "$srcJarDir" "$kotlinBuildFile" "$kaptDir" && ` +
+ `mkdir -p "$srcJarDir" "$kaptDir/sources" "$kaptDir/classes" && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`${config.GenKotlinBuildFileCmd} $classpath "$name" "" $out.rsp $srcJarDir/list > $kotlinBuildFile &&` +
`${config.KotlincCmd} ${config.KotlincSuppressJDK9Warnings} ${config.JavacHeapFlags} $kotlincFlags ` +
@@ -105,6 +106,7 @@ var kapt = pctx.AndroidRemoteStaticRule("kapt", android.RemoteRuleSupports{Goma:
`$kaptProcessor ` +
`-Xbuild-file=$kotlinBuildFile && ` +
`${config.SoongZipCmd} -jar -o $out -C $kaptDir/sources -D $kaptDir/sources && ` +
+ `${config.SoongZipCmd} -jar -o $classesJarOut -C $kaptDir/classes -D $kaptDir/classes && ` +
`rm -rf "$srcJarDir"`,
CommandDeps: []string{
"${config.KotlincCmd}",
@@ -118,13 +120,14 @@ var kapt = pctx.AndroidRemoteStaticRule("kapt", android.RemoteRuleSupports{Goma:
RspfileContent: `$in`,
},
"kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "kaptProcessor",
- "classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile", "name")
+ "classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile", "name",
+ "classesJarOut")
// kotlinKapt 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, outputFile android.WritablePath,
+func kotlinKapt(ctx android.ModuleContext, srcJarOutputFile, resJarOutputFile android.WritablePath,
srcFiles, srcJars android.Paths,
flags javaBuilderFlags) {
@@ -152,11 +155,12 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
kotlinName = strings.ReplaceAll(kotlinName, "/", "__")
ctx.Build(pctx, android.BuildParams{
- Rule: kapt,
- Description: "kapt",
- Output: outputFile,
- Inputs: srcFiles,
- Implicits: deps,
+ Rule: kapt,
+ Description: "kapt",
+ Output: srcJarOutputFile,
+ ImplicitOutput: resJarOutputFile,
+ Inputs: srcFiles,
+ Implicits: deps,
Args: map[string]string{
"classpath": flags.kotlincClasspath.FormJavaClassPath("-classpath"),
"kotlincFlags": flags.kotlincFlags,
@@ -168,6 +172,7 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
"kaptDir": android.PathForModuleOut(ctx, "kapt/gen").String(),
"encodedJavacFlags": encodedJavacFlags,
"name": kotlinName,
+ "classesJarOut": resJarOutputFile.String(),
},
})
}