From b5db4015997c61328a31793b0a621acdfeecbf84 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 28 Mar 2022 17:12:39 -0700 Subject: [PATCH] Enable turbine for api generating annotation processors when using kotlin Normally turbine is disabled when an api generating annotation processor is in use because the annotation processors are run in javac, so any generated api would not be present in the turbine header jar. When compiling with kotlin and annotation processors, the annotation processors (including any that generate api) are run in an extra turbine invocation to generate sources to make the results visible to kotlinc, and so can also be compiled by the normal turbine invocation. Force turbine enabled when kotlin sources are present. Test: m SystemUI Bug: 222095735 Change-Id: I5fcfe67e46cb4a4e90388f088327488959b6571f --- java/base.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/java/base.go b/java/base.go index 8b258d6c8..5802099ae 100644 --- a/java/base.go +++ b/java/base.go @@ -1048,6 +1048,12 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { } } + // We don't currently run annotation processors in turbine, which means we can't use turbine + // generated header jars when an annotation processor that generates API is enabled. One + // exception (handled further below) is when kotlin sources are enabled, in which case turbine + // is used to run all of the annotation processors. + disableTurbine := deps.disableTurbine + // Collect .java files for AIDEGen j.expandIDEInfoCompiledSrcs = append(j.expandIDEInfoCompiledSrcs, uniqueSrcFiles.Strings()...) @@ -1055,6 +1061,11 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { var kotlinHeaderJars android.Paths if srcFiles.HasExt(".kt") { + // When using kotlin sources turbine is used to generate annotation processor sources, + // including for annotation processors that generate API, so we can use turbine for + // java sources too. + disableTurbine = false + // user defined kotlin flags. kotlincFlags := j.properties.Kotlincflags CheckKotlincFlags(ctx, kotlincFlags) @@ -1139,7 +1150,7 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) { enableSharding := false var headerJarFileWithoutDepsOrJarjar android.Path - if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !deps.disableTurbine { + if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") && !disableTurbine { if j.properties.Javac_shard_size != nil && *(j.properties.Javac_shard_size) > 0 { enableSharding = true // Formerly, there was a check here that prevented annotation processors