Add USE_D8_DESUGAR option in build/soong
Add an option to use D8's desugar instead of the standalone version. USE_D8_DESUGAR=true m would trigger DCHECK in dex2oat unless https://android-review.googlesource.com/c/platform/art/+/562595 is patched in as well. Bug: 69329508 Test: m && USE_D8_DESUGAR=false m Change-Id: I864d88e257a2ba0b7f19aa5cced537301950e963
This commit is contained in:
parent
d4c03092cd
commit
9f319118e1
|
@ -161,6 +161,20 @@ var (
|
|||
},
|
||||
"outDir", "dxFlags")
|
||||
|
||||
d8 = pctx.AndroidStaticRule("d8",
|
||||
blueprint.RuleParams{
|
||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||
`${config.D8Cmd} --output $outDir $dxFlags $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{
|
||||
"${config.DxCmd}",
|
||||
"${config.SoongZipCmd}",
|
||||
"${config.MergeZipsCmd}",
|
||||
},
|
||||
},
|
||||
"outDir", "dxFlags")
|
||||
|
||||
jarjar = pctx.AndroidStaticRule("jarjar",
|
||||
blueprint.RuleParams{
|
||||
Command: "${config.JavaCmd} -jar ${config.JarjarCmd} process $rulesFile $in $out",
|
||||
|
@ -420,9 +434,15 @@ func TransformClassesJarToDexJar(ctx android.ModuleContext, outputFile android.W
|
|||
|
||||
outDir := android.PathForModuleOut(ctx, "dex")
|
||||
|
||||
rule := dx
|
||||
desc := "dx"
|
||||
if ctx.AConfig().IsEnvTrue("USE_D8_DESUGAR") {
|
||||
rule = d8
|
||||
desc = "d8"
|
||||
}
|
||||
ctx.Build(pctx, android.BuildParams{
|
||||
Rule: dx,
|
||||
Description: "dx",
|
||||
Rule: rule,
|
||||
Description: desc,
|
||||
Output: outputFile,
|
||||
Input: classesJar,
|
||||
Args: map[string]string{
|
||||
|
|
|
@ -106,6 +106,13 @@ func init() {
|
|||
return path.String(), nil
|
||||
}
|
||||
})
|
||||
pctx.VariableFunc("D8Cmd", func(config android.Config) (string, error) {
|
||||
path, err := pctx.HostBinToolPath(config, "d8")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path.String(), nil
|
||||
})
|
||||
pctx.VariableFunc("TurbineJar", func(config android.Config) (string, error) {
|
||||
turbine := "turbine.jar"
|
||||
if config.UnbundledBuild() {
|
||||
|
|
|
@ -45,8 +45,15 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
|
|||
ctx.Strict("JAR_ARGS", "${JarArgsCmd}")
|
||||
ctx.Strict("JAVADOC", "${JavadocCmd}")
|
||||
ctx.Strict("COMMON_JDK_FLAGS", "${CommonJdkFlags}")
|
||||
ctx.Strict("DX", "${DxCmd}")
|
||||
ctx.Strict("DX_COMMAND", "${DxCmd} -JXms16M -JXmx2048M")
|
||||
|
||||
if ctx.Config().IsEnvTrue("USE_D8_DESUGAR") {
|
||||
ctx.Strict("DX", "${D8Cmd}")
|
||||
ctx.Strict("DX_COMMAND", "${D8Cmd} -JXms16M -JXmx2048M")
|
||||
} else {
|
||||
ctx.Strict("DX", "${DxCmd}")
|
||||
ctx.Strict("DX_COMMAND", "${DxCmd} -JXms16M -JXmx2048M")
|
||||
}
|
||||
|
||||
ctx.Strict("TURBINE", "${TurbineJar}")
|
||||
|
||||
if ctx.Config().IsEnvTrue("RUN_ERROR_PRONE") {
|
||||
|
|
63
java/java.go
63
java/java.go
|
@ -671,6 +671,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
|
|||
// Store the list of .java files that was passed to javac
|
||||
j.compiledJavaSrcs = uniqueSrcFiles
|
||||
j.compiledSrcJars = srcJars
|
||||
fullD8 := ctx.AConfig().IsEnvTrue("USE_D8_DESUGAR")
|
||||
|
||||
enable_sharding := false
|
||||
if ctx.Device() && !ctx.Config().IsEnvFalse("TURBINE_ENABLED") {
|
||||
|
@ -793,7 +794,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
|
|||
j.headerJarFile = j.implementationJarFile
|
||||
}
|
||||
|
||||
if ctx.Device() && j.installable() {
|
||||
if !fullD8 && ctx.Device() && j.installable() {
|
||||
outputFile = j.desugar(ctx, flags, outputFile, jarName)
|
||||
}
|
||||
|
||||
|
@ -808,7 +809,11 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars ...android.Path
|
|||
}
|
||||
|
||||
if ctx.Device() && j.installable() {
|
||||
outputFile = j.compileDex(ctx, flags, outputFile, jarName)
|
||||
if fullD8 {
|
||||
outputFile = j.compileDexFullD8(ctx, flags, outputFile, jarName)
|
||||
} else {
|
||||
outputFile = j.compileDex(ctx, flags, outputFile, jarName)
|
||||
}
|
||||
if ctx.Failed() {
|
||||
return
|
||||
}
|
||||
|
@ -896,15 +901,6 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
|||
classesJar android.Path, jarName string) android.Path {
|
||||
|
||||
dxFlags := j.deviceProperties.Dxflags
|
||||
if false /* emma enabled */ {
|
||||
// If you instrument class files that have local variable debug information in
|
||||
// them emma does not correctly maintain the local variable table.
|
||||
// This will cause an error when you try to convert the class files for Android.
|
||||
// The workaround here is to build different dex file here based on emma switch
|
||||
// then later copy into classes.dex. When emma is on, dx is run with --no-locals
|
||||
// option to remove local variable information
|
||||
dxFlags = append(dxFlags, "--no-locals")
|
||||
}
|
||||
|
||||
if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
|
||||
dxFlags = append(dxFlags, "--no-optimize")
|
||||
|
@ -930,6 +926,51 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
|||
return javalibJar
|
||||
}
|
||||
|
||||
func (j *Module) compileDexFullD8(ctx android.ModuleContext, flags javaBuilderFlags,
|
||||
classesJar android.Path, jarName string) android.Path {
|
||||
|
||||
// Translate all the DX flags to D8 ones until all the build files have been migrated
|
||||
// to D8 flags. See: b/69377755
|
||||
var dxFlags []string
|
||||
for _, x := range j.deviceProperties.Dxflags {
|
||||
if x == "--core-library" {
|
||||
continue
|
||||
}
|
||||
if x == "--dex" {
|
||||
continue
|
||||
}
|
||||
if x == "--multi-dex" {
|
||||
continue
|
||||
}
|
||||
if x == "--no-locals" {
|
||||
dxFlags = append(dxFlags, "--release")
|
||||
continue
|
||||
}
|
||||
dxFlags = append(dxFlags, x)
|
||||
}
|
||||
|
||||
if ctx.AConfig().Getenv("NO_OPTIMIZE_DX") != "" {
|
||||
dxFlags = append(dxFlags, "--debug")
|
||||
}
|
||||
|
||||
if ctx.AConfig().Getenv("GENERATE_DEX_DEBUG") != "" {
|
||||
dxFlags = append(dxFlags,
|
||||
"--debug",
|
||||
"--verbose")
|
||||
}
|
||||
|
||||
dxFlags = append(dxFlags, "--min-api "+j.minSdkVersionNumber(ctx))
|
||||
|
||||
flags.dxFlags = strings.Join(dxFlags, " ")
|
||||
|
||||
// Compile classes.jar into classes.dex and then javalib.jar
|
||||
javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
|
||||
TransformClassesJarToDexJar(ctx, javalibJar, classesJar, flags)
|
||||
|
||||
j.dexJarFile = javalibJar
|
||||
return javalibJar
|
||||
}
|
||||
|
||||
// Returns a sdk version as a string that is guaranteed to be a parseable as a number. For
|
||||
// modules targeting an unreleased SDK (meaning it does not yet have a number) it returns "10000".
|
||||
func (j *Module) minSdkVersionNumber(ctx android.ModuleContext) string {
|
||||
|
|
Loading…
Reference in New Issue