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
This commit is contained in:
Colin Cross
2022-03-28 18:27:17 -07:00
parent b5db401599
commit c6ef485370
4 changed files with 51 additions and 24 deletions

View File

@@ -155,22 +155,34 @@ func TestKapt(t *testing.T) {
t.Errorf("expected %q in turbine-apt implicits %v", kaptStubs.Output.String(), kotlinc.Implicits.Strings())
}
turbineAptSrcjarOutput := turbineApt.ImplicitOutputs[0]
// Test that the turbine-apt srcjar is a dependency of kotlinc and javac rules
if !inList(turbineApt.Output.String(), kotlinc.Implicits.Strings()) {
t.Errorf("expected %q in kotlinc implicits %v", turbineApt.Output.String(), kotlinc.Implicits.Strings())
if !inList(turbineAptSrcjarOutput.String(), kotlinc.Implicits.Strings()) {
t.Errorf("expected %q in kotlinc implicits %v", turbineAptSrcjarOutput.String(), kotlinc.Implicits.Strings())
}
if !inList(turbineApt.Output.String(), javac.Implicits.Strings()) {
t.Errorf("expected %q in javac implicits %v", turbineApt.Output.String(), javac.Implicits.Strings())
if !inList(turbineAptSrcjarOutput.String(), javac.Implicits.Strings()) {
t.Errorf("expected %q in javac implicits %v", turbineAptSrcjarOutput.String(), javac.Implicits.Strings())
}
// Test that the turbine-apt srcjar is extracted by the kotlinc and javac rules
if kotlinc.Args["srcJars"] != turbineApt.Output.String() {
t.Errorf("expected %q in kotlinc srcjars %v", turbineApt.Output.String(), kotlinc.Args["srcJars"])
if kotlinc.Args["srcJars"] != turbineAptSrcjarOutput.String() {
t.Errorf("expected %q in kotlinc srcjars %v", turbineAptSrcjarOutput.String(), kotlinc.Args["srcJars"])
}
if javac.Args["srcJars"] != turbineApt.Output.String() {
t.Errorf("expected %q in javac srcjars %v", turbineApt.Output.String(), kotlinc.Args["srcJars"])
if javac.Args["srcJars"] != turbineAptSrcjarOutput.String() {
t.Errorf("expected %q in javac srcjars %v", turbineAptSrcjarOutput.String(), kotlinc.Args["srcJars"])
}
// Test that the turbine-apt header jar is a dependency of the javac rules
turbineAptHeaderjarOutput := turbineApt.Output
android.AssertStringListContains(t, "javac dependency", javac.Implicits.Strings(), turbineAptHeaderjarOutput.String())
android.AssertStringDoesContain(t, "javac classpath", javac.Args["classpath"], turbineAptHeaderjarOutput.String())
// Test that the kotlinc header jar is a not a dependency of the javac rules
kotlincHeaderJarOutput := kotlinc.ImplicitOutput
android.AssertStringListDoesNotContain(t, "javac dependency", javac.Implicits.Strings(), kotlincHeaderJarOutput.String())
android.AssertStringDoesNotContain(t, "javac classpath", javac.Args["classpath"], kotlincHeaderJarOutput.String())
// Test that the processors are passed to kapt
expectedProcessorPath := "-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + bar +
" -P plugin:org.jetbrains.kotlin.kapt3:apclasspath=" + baz