Fix kotlin annotation processing after java_plugin
I37c1e80eba71ae2d6a06199fb102194a51994989 broke kotlin annotation processing with a typo in the processors flag to kapt and by passing -processor to javac with an empty processorpath. Bug: 77284273 Bug: 122251693 Test: kotlin_test.go Test: m checkbuild Change-Id: I17c45d5b3f9df089231af5d2930646ad0e6bf9be
This commit is contained in:
@@ -493,7 +493,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
|
|||||||
// TODO(ccross): move this to a mutator pass that can tell if generated sources contain
|
// TODO(ccross): move this to a mutator pass that can tell if generated sources contain
|
||||||
// Kotlin files
|
// Kotlin files
|
||||||
ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
|
ctx.AddVariationDependencies(nil, kotlinStdlibTag, "kotlin-stdlib")
|
||||||
if len(j.properties.Annotation_processors) > 0 {
|
if len(j.properties.Annotation_processors) > 0 || len(j.properties.Plugins) > 0 {
|
||||||
ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
|
ctx.AddVariationDependencies(nil, kotlinAnnotationsTag, "kotlin-annotations")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1017,6 +1017,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
|
|||||||
srcJars = append(srcJars, kaptSrcJar)
|
srcJars = append(srcJars, kaptSrcJar)
|
||||||
// Disable annotation processing in javac, it's already been handled by kapt
|
// Disable annotation processing in javac, it's already been handled by kapt
|
||||||
flags.processorPath = nil
|
flags.processorPath = nil
|
||||||
|
flags.processor = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
|
kotlinJar := android.PathForModuleOut(ctx, "kotlin", jarName)
|
||||||
|
@@ -121,7 +121,7 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
|
|||||||
|
|
||||||
kaptProcessor := ""
|
kaptProcessor := ""
|
||||||
if flags.processor != "" {
|
if flags.processor != "" {
|
||||||
kaptProcessor = "-P plugin:org.jetbrains.kotlin.kapt3:processor=" + flags.processor
|
kaptProcessor = "-P plugin:org.jetbrains.kotlin.kapt3:processors=" + flags.processor
|
||||||
}
|
}
|
||||||
|
|
||||||
encodedJavacFlags := kaptEncodeFlags([][2]string{
|
encodedJavacFlags := kaptEncodeFlags([][2]string{
|
||||||
|
@@ -15,6 +15,7 @@
|
|||||||
package java
|
package java
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"android/soong/android"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -92,13 +93,19 @@ func TestKapt(t *testing.T) {
|
|||||||
|
|
||||||
java_plugin {
|
java_plugin {
|
||||||
name: "bar",
|
name: "bar",
|
||||||
|
processor_class: "com.bar",
|
||||||
|
srcs: ["b.java"],
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
|
||||||
|
buildOS := android.BuildOs.String()
|
||||||
|
|
||||||
kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt")
|
kapt := ctx.ModuleForTests("foo", "android_common").Rule("kapt")
|
||||||
kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
|
kotlinc := ctx.ModuleForTests("foo", "android_common").Rule("kotlinc")
|
||||||
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
javac := ctx.ModuleForTests("foo", "android_common").Rule("javac")
|
||||||
|
|
||||||
|
bar := ctx.ModuleForTests("bar", buildOS+"_common").Rule("javac").Output.String()
|
||||||
|
|
||||||
// Test that the kotlin and java sources are passed to kapt and kotlinc
|
// Test that the kotlin and java sources are passed to kapt and kotlinc
|
||||||
if len(kapt.Inputs) != 2 || kapt.Inputs[0].String() != "a.java" || kapt.Inputs[1].String() != "b.kt" {
|
if len(kapt.Inputs) != 2 || kapt.Inputs[0].String() != "a.java" || kapt.Inputs[1].String() != "b.kt" {
|
||||||
t.Errorf(`foo kapt inputs %v != ["a.java", "b.kt"]`, kapt.Inputs)
|
t.Errorf(`foo kapt inputs %v != ["a.java", "b.kt"]`, kapt.Inputs)
|
||||||
@@ -127,6 +134,25 @@ func TestKapt(t *testing.T) {
|
|||||||
if javac.Args["srcJars"] != kapt.Output.String() {
|
if javac.Args["srcJars"] != kapt.Output.String() {
|
||||||
t.Errorf("expected %q in javac srcjars %v", kapt.Output.String(), kotlinc.Args["srcJars"])
|
t.Errorf("expected %q in javac srcjars %v", kapt.Output.String(), kotlinc.Args["srcJars"])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that the processors are passed to kapt
|
||||||
|
expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar
|
||||||
|
if kapt.Args["kaptProcessorPath"] != expectedProcessorPath {
|
||||||
|
t.Errorf("expected kaptProcessorPath %q, got %q", expectedProcessorPath, kapt.Args["kaptProcessorPath"])
|
||||||
|
}
|
||||||
|
expectedProcessor := "-P plugin:org.jetbrains.kotlin.kapt3:processors=com.bar"
|
||||||
|
if kapt.Args["kaptProcessor"] != expectedProcessor {
|
||||||
|
t.Errorf("expected kaptProcessor %q, got %q", expectedProcessor, kapt.Args["kaptProcessor"])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that the processors are not passed to javac
|
||||||
|
if javac.Args["processorPath"] != "" {
|
||||||
|
t.Errorf("expected processorPath '', got %q", javac.Args["processorPath"])
|
||||||
|
}
|
||||||
|
// TODO(b/77284273): test for -processor:none
|
||||||
|
if javac.Args["processor"] != "" {
|
||||||
|
t.Errorf("expected processor '', got %q", javac.Args["processor"])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestKaptEncodeFlags(t *testing.T) {
|
func TestKaptEncodeFlags(t *testing.T) {
|
||||||
|
Reference in New Issue
Block a user