Use -processorpath for annotation processors

ErrorProne needs to be added to -processorpath, but once anything is
passed via -processorpath javac stops looking in the classpath for
annotation processors.  Move annotation processors to -processorpath
in preparation.

This reapplies Ife06b3c7432ab971f5605dcc18a558bcbd99a675 with fixes
to processorpath in errorprone rules.

Test: m java
Change-Id: I188136771386a2183fb31f4b70b50c95ac419ff8
This commit is contained in:
Colin Cross 2018-06-19 22:43:34 -07:00
parent ab97ae08cd
commit 6a77c9871c
2 changed files with 13 additions and 5 deletions

View file

@ -43,7 +43,7 @@ var (
Command: `rm -rf "$outDir" "$annoDir" "$srcJarDir" && mkdir -p "$outDir" "$annoDir" "$srcJarDir" && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`${config.SoongJavacWrapper} ${config.JavacWrapper}${config.JavacCmd} ${config.JavacHeapFlags} ${config.CommonJdkFlags} ` +
`$javacFlags $bootClasspath $classpath ` +
`$processorpath $javacFlags $bootClasspath $classpath ` +
`-source $javaVersion -target $javaVersion ` +
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list && ` +
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
@ -56,7 +56,7 @@ var (
Rspfile: "$out.rsp",
RspfileContent: "$in",
},
"javacFlags", "bootClasspath", "classpath", "srcJars", "srcJarDir",
"javacFlags", "bootClasspath", "classpath", "processorpath", "srcJars", "srcJarDir",
"outDir", "annoDir", "javaVersion")
kotlinc = pctx.AndroidGomaStaticRule("kotlinc",
@ -85,7 +85,7 @@ var (
Command: `rm -rf "$outDir" "$annoDir" "$srcJarDir" && mkdir -p "$outDir" "$annoDir" "$srcJarDir" && ` +
`${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` +
`${config.SoongJavacWrapper} ${config.ErrorProneCmd} ` +
`$javacFlags $bootClasspath $classpath ` +
`$processorpath $javacFlags $bootClasspath $classpath ` +
`-source $javaVersion -target $javaVersion ` +
`-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list && ` +
`${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir`,
@ -100,7 +100,7 @@ var (
Rspfile: "$out.rsp",
RspfileContent: "$in",
},
"javacFlags", "bootClasspath", "classpath", "srcJars", "srcJarDir",
"javacFlags", "bootClasspath", "classpath", "processorpath", "srcJars", "srcJarDir",
"outDir", "annoDir", "javaVersion")
turbine = pctx.AndroidStaticRule("turbine",
@ -155,6 +155,7 @@ type javaBuilderFlags struct {
javacFlags string
bootClasspath classpath
classpath classpath
processorPath classpath
systemModules classpath
aidlFlags string
javaVersion string
@ -295,6 +296,7 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
}
deps = append(deps, flags.classpath...)
deps = append(deps, flags.processorPath...)
srcJarDir := "srcjars"
outDir := "classes"
@ -315,6 +317,7 @@ func transformJavaToClasses(ctx android.ModuleContext, outputFile android.Writab
"javacFlags": flags.javacFlags,
"bootClasspath": bootClasspath,
"classpath": flags.classpath.FormJavaClassPath("-classpath"),
"processorpath": flags.processorPath.FormJavaClassPath("-processorpath"),
"srcJars": strings.Join(srcJars.Strings(), " "),
"srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(),
"outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(),

View file

@ -331,6 +331,7 @@ type dependencyTag struct {
var (
staticLibTag = dependencyTag{name: "staticlib"}
libTag = dependencyTag{name: "javalib"}
annoTag = dependencyTag{name: "annotation processor"}
bootClasspathTag = dependencyTag{name: "bootclasspath"}
systemModulesTag = dependencyTag{name: "system modules"}
frameworkResTag = dependencyTag{name: "framework-res"}
@ -521,7 +522,7 @@ func (j *Module) deps(ctx android.BottomUpMutatorContext) {
ctx.AddDependency(ctx.Module(), libTag, j.properties.Libs...)
ctx.AddDependency(ctx.Module(), staticLibTag, j.properties.Static_libs...)
ctx.AddDependency(ctx.Module(), libTag, j.properties.Annotation_processors...)
ctx.AddDependency(ctx.Module(), annoTag, j.properties.Annotation_processors...)
android.ExtractSourcesDeps(ctx, j.properties.Srcs)
android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs)
@ -602,6 +603,7 @@ func (j *Module) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.Opt
type deps struct {
classpath classpath
bootClasspath classpath
processorPath classpath
staticJars android.Paths
staticHeaderJars android.Paths
staticJarResources android.Paths
@ -726,6 +728,8 @@ func (j *Module) collectDeps(ctx android.ModuleContext) deps {
deps.staticHeaderJars = append(deps.staticHeaderJars, dep.HeaderJars()...)
// sdk lib names from dependencies are re-exported
j.exportedSdkLibs = append(j.exportedSdkLibs, dep.ExportedSdkLibs()...)
case annoTag:
deps.processorPath = append(deps.processorPath, dep.ImplementationJars()...)
case frameworkResTag:
if ctx.ModuleName() == "framework" {
// framework.jar has a one-off dependency on the R.java and Manifest.java files
@ -850,6 +854,7 @@ func (j *Module) collectBuilderFlags(ctx android.ModuleContext, deps deps) javaB
// classpath
flags.bootClasspath = append(flags.bootClasspath, deps.bootClasspath...)
flags.classpath = append(flags.classpath, deps.classpath...)
flags.processorPath = append(flags.processorPath, deps.processorPath...)
if len(flags.bootClasspath) == 0 && ctx.Host() && !ctx.Config().TargetOpenJDK9() &&
!Bool(j.properties.No_standard_libs) &&