From ffb657ebc04e5d81acc810ceb75ed6e4728fe8e5 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Fri, 21 Sep 2018 12:29:22 -0700 Subject: [PATCH] Pass classpath to d8 d8 requires the full classpath if --min-api requires default method or try-with-resources desugaring. Always pass the full classpath, since it will already have been built to generate the input jar. Bug: 116243313 Test: m checkbuild Change-Id: Ib0c18873880697b7cf942e0548dd2c53ee5ad23c --- java/dex.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/java/dex.go b/java/dex.go index 644594037..c612a0c03 100644 --- a/java/dex.go +++ b/java/dex.go @@ -25,7 +25,7 @@ import ( var d8 = pctx.AndroidStaticRule("d8", blueprint.RuleParams{ Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + - `${config.D8Cmd} --output $outDir $dxFlags $in && ` + + `${config.D8Cmd} --output $outDir $d8Flags $in && ` + `${config.SoongZipCmd} -o $outDir/classes.dex.jar -C $outDir -D $outDir && ` + `${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`, CommandDeps: []string{ @@ -34,7 +34,7 @@ var d8 = pctx.AndroidStaticRule("d8", "${config.MergeZipsCmd}", }, }, - "outDir", "dxFlags") + "outDir", "d8Flags") var r8 = pctx.AndroidStaticRule("r8", blueprint.RuleParams{ @@ -44,7 +44,7 @@ var r8 = pctx.AndroidStaticRule("r8", `--force-proguard-compatibility ` + `--no-data-resources ` + `-printmapping $outDict ` + - `$dxFlags $r8Flags && ` + + `$r8Flags && ` + `touch "$outDict" && ` + `${config.SoongZipCmd} -o $outDir/classes.dex.jar -C $outDir -D $outDir && ` + `${config.MergeZipsCmd} -D -stripFile "**/*.class" $out $outDir/classes.dex.jar $in`, @@ -54,9 +54,9 @@ var r8 = pctx.AndroidStaticRule("r8", "${config.MergeZipsCmd}", }, }, - "outDir", "outDict", "dxFlags", "r8Flags") + "outDir", "outDict", "r8Flags") -func (j *Module) dxFlags(ctx android.ModuleContext) []string { +func (j *Module) dexCommonFlags(ctx android.ModuleContext) []string { flags := j.deviceProperties.Dxflags // Translate all the DX flags to D8 ones until all the build files have been migrated // to D8 flags. See: b/69377755 @@ -82,6 +82,15 @@ func (j *Module) dxFlags(ctx android.ModuleContext) []string { return flags } +func (j *Module) d8Flags(ctx android.ModuleContext, flags javaBuilderFlags) []string { + d8Flags := j.dexCommonFlags(ctx) + + d8Flags = append(d8Flags, flags.bootClasspath.FormTurbineClasspath("--lib")...) + d8Flags = append(d8Flags, flags.classpath.FormTurbineClasspath("--lib")...) + + return d8Flags +} + func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Flags []string, r8Deps android.Paths) { opt := j.deviceProperties.Optimize @@ -97,6 +106,8 @@ func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8F proguardRaiseDeps = append(proguardRaiseDeps, dep.(Dependency).HeaderJars()...) }) + r8Flags = append(r8Flags, j.dexCommonFlags(ctx)...) + r8Flags = append(r8Flags, proguardRaiseDeps.FormJavaClassPath("-libraryjars")) r8Flags = append(r8Flags, flags.bootClasspath.FormJavaClassPath("-libraryjars")) r8Flags = append(r8Flags, flags.classpath.FormJavaClassPath("-libraryjars")) @@ -147,8 +158,6 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, useR8 := Bool(j.deviceProperties.Optimize.Enabled) - dxFlags := j.dxFlags(ctx) - // Compile classes.jar into classes.dex and then javalib.jar javalibJar := android.PathForModuleOut(ctx, "dex", jarName) outDir := android.PathForModuleOut(ctx, "dex") @@ -167,20 +176,20 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, Input: classesJar, Implicits: r8Deps, Args: map[string]string{ - "dxFlags": strings.Join(dxFlags, " "), "r8Flags": strings.Join(r8Flags, " "), "outDict": j.proguardDictionary.String(), "outDir": outDir.String(), }, }) } else { + d8Flags := j.d8Flags(ctx, flags) ctx.Build(pctx, android.BuildParams{ Rule: d8, Description: "d8", Output: javalibJar, Input: classesJar, Args: map[string]string{ - "dxFlags": strings.Join(dxFlags, " "), + "d8Flags": strings.Join(d8Flags, " "), "outDir": outDir.String(), }, })