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

@@ -44,7 +44,7 @@ var (
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`(if [ -s $srcJarDir/list ] || [ -s $out.rsp ] ; then ` +
`${config.SoongJavacWrapper} ${config.JavacWrapper}${config.JavacCmd} ${config.JavacHeapFlags} ${config.CommonJdkFlags} ` +
`$processorpath $javacFlags $bootClasspath $classpath ` +
`$processorpath $processor $javacFlags $bootClasspath $classpath ` +
`-source $javaVersion -target $javaVersion ` +
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list ; fi ) && ` +
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
@@ -57,7 +57,7 @@ var (
Rspfile: "$out.rsp",
RspfileContent: "$in",
},
"javacFlags", "bootClasspath", "classpath", "processorpath", "srcJars", "srcJarDir",
"javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir",
"outDir", "annoDir", "javaVersion")
turbine = pctx.AndroidStaticRule("turbine",
@@ -141,6 +141,7 @@ type javaBuilderFlags struct {
bootClasspath classpath
classpath classpath
processorPath classpath
processor string
systemModules classpath
aidlFlags string
javaVersion string
@@ -254,6 +255,12 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
deps = append(deps, flags.classpath...)
deps = append(deps, flags.processorPath...)
// TODO(b/77284273): pass -processor:none if no plugins are listed
processor := ""
if flags.processor != "" {
processor = "-processor " + flags.processor
}
srcJarDir := "srcjars"
outDir := "classes"
annoDir := "anno"
@@ -274,6 +281,7 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
"bootClasspath": bootClasspath,
"classpath": flags.classpath.FormJavaClassPath("-classpath"),
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
"processor": processor,
"srcJars": strings.Join(srcJars.Strings(), " "),
"srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(),
"outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(),