Replace annotation_processors with plugins

Follow bazel's modules for annotation processors by introducing
a java_plugin module type that can contain extra metadata about
the annotation processor, the processor class and a flag to
specify if the annotation processor is compatible with the
turbine optimization.  Deprecate the annotation_processors
property, which took a list of java_library_host modules, in
favor of the plugins property, which takes a list of java_plugin
modules.  The annotation_processors property will be removed
once all uses have been replaced with plugins.

Bug: 77284273
Test: plugin_test.go
Test: m caliper
Change-Id: I37c1e80eba71ae2d6a06199fb102194a51994989
This commit is contained in:
Colin Cross
2019-01-21 21:37:16 -08:00
parent c4efd9cb55
commit be9cdb8d64
8 changed files with 222 additions and 9 deletions

View File

@@ -87,6 +87,7 @@ var kapt = pctx.AndroidGomaStaticRule("kapt",
`-P plugin:org.jetbrains.kotlin.kapt3:aptMode=stubsAndApt ` +
`-P plugin:org.jetbrains.kotlin.kapt3:javacArguments=$encodedJavacFlags ` +
`$kaptProcessorPath ` +
`$kaptProcessor ` +
`-Xbuild-file=$kotlinBuildFile && ` +
`${config.SoongZipCmd} -jar -o $out -C $kaptDir/sources -D $kaptDir/sources`,
CommandDeps: []string{
@@ -100,7 +101,8 @@ var kapt = pctx.AndroidGomaStaticRule("kapt",
Rspfile: "$out.rsp",
RspfileContent: `$in`,
},
"kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile")
"kotlincFlags", "encodedJavacFlags", "kaptProcessorPath", "kaptProcessor",
"classpath", "srcJars", "srcJarDir", "kaptDir", "kotlinJvmTarget", "kotlinBuildFile")
// 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
@@ -117,6 +119,11 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
kaptProcessorPath := flags.processorPath.FormTurbineClasspath("-P plugin:org.jetbrains.kotlin.kapt3:apclasspath=")
kaptProcessor := ""
if flags.processor != "" {
kaptProcessor = "-P plugin:org.jetbrains.kotlin.kapt3:processor=" + flags.processor
}
encodedJavacFlags := kaptEncodeFlags([][2]string{
{"-source", flags.javaVersion},
{"-target", flags.javaVersion},
@@ -135,6 +142,7 @@ func kotlinKapt(ctx android.ModuleContext, outputFile android.WritablePath,
"srcJarDir": android.PathForModuleOut(ctx, "kapt", "srcJars").String(),
"kotlinBuildFile": android.PathForModuleOut(ctx, "kapt", "build.xml").String(),
"kaptProcessorPath": strings.Join(kaptProcessorPath, " "),
"kaptProcessor": kaptProcessor,
"kaptDir": android.PathForModuleOut(ctx, "kapt/gen").String(),
"encodedJavacFlags": encodedJavacFlags,
},