Remove desugar support
Desugaring is always handled by d8 now. Test: m checkbuild Change-Id: I29e8f68e51b194a4090866acc63f19f0605e318d
This commit is contained in:
parent
dd0b4e06f5
commit
000280bb0e
|
@ -627,10 +627,6 @@ func (c *config) Android64() bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *config) UseD8Desugar() bool {
|
|
||||||
return !c.IsEnvFalse("USE_D8_DESUGAR")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *config) UseGoma() bool {
|
func (c *config) UseGoma() bool {
|
||||||
return Bool(c.productVariables.UseGoma)
|
return Bool(c.productVariables.UseGoma)
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,7 +243,7 @@ func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.
|
||||||
// ensure java does not fall back to the default bootclasspath.
|
// ensure java does not fall back to the default bootclasspath.
|
||||||
bootClasspath = `--bootclasspath ""`
|
bootClasspath = `--bootclasspath ""`
|
||||||
} else {
|
} else {
|
||||||
bootClasspath = strings.Join(flags.bootClasspath.FormDesugarClasspath("--bootclasspath"), " ")
|
bootClasspath = strings.Join(flags.bootClasspath.FormTurbineClasspath("--bootclasspath"), " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
|
@ -256,7 +256,7 @@ func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.
|
||||||
"javacFlags": flags.javacFlags,
|
"javacFlags": flags.javacFlags,
|
||||||
"bootClasspath": bootClasspath,
|
"bootClasspath": bootClasspath,
|
||||||
"srcJars": strings.Join(srcJars.Strings(), " "),
|
"srcJars": strings.Join(srcJars.Strings(), " "),
|
||||||
"classpath": strings.Join(flags.classpath.FormDesugarClasspath("--classpath"), " "),
|
"classpath": strings.Join(flags.classpath.FormTurbineClasspath("--classpath"), " "),
|
||||||
"outDir": android.PathForModuleOut(ctx, "turbine", "classes").String(),
|
"outDir": android.PathForModuleOut(ctx, "turbine", "classes").String(),
|
||||||
"javaVersion": flags.javaVersion,
|
"javaVersion": flags.javaVersion,
|
||||||
},
|
},
|
||||||
|
@ -419,7 +419,7 @@ func (x *classpath) FormJavaSystemModulesPath(optName string, forceEmpty bool) s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *classpath) FormDesugarClasspath(optName string) []string {
|
func (x *classpath) FormTurbineClasspath(optName string) []string {
|
||||||
if x == nil || *x == nil {
|
if x == nil || *x == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,18 +93,6 @@ func init() {
|
||||||
pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
|
pctx.HostBinToolVariable("Zip2ZipCmd", "zip2zip")
|
||||||
pctx.HostBinToolVariable("ZipSyncCmd", "zipsync")
|
pctx.HostBinToolVariable("ZipSyncCmd", "zipsync")
|
||||||
pctx.HostBinToolVariable("ApiCheckCmd", "apicheck")
|
pctx.HostBinToolVariable("ApiCheckCmd", "apicheck")
|
||||||
pctx.VariableFunc("DxCmd", func(ctx android.PackageVarContext) string {
|
|
||||||
config := ctx.Config()
|
|
||||||
if config.IsEnvFalse("USE_D8") {
|
|
||||||
if config.UnbundledBuild() || config.IsPdkBuild() {
|
|
||||||
return "prebuilts/build-tools/common/bin/dx"
|
|
||||||
} else {
|
|
||||||
return pctx.HostBinToolPath(ctx, "dx").String()
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return pctx.HostBinToolPath(ctx, "d8-compat-dx").String()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
pctx.HostBinToolVariable("D8Cmd", "d8")
|
pctx.HostBinToolVariable("D8Cmd", "d8")
|
||||||
pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
|
pctx.HostBinToolVariable("R8Cmd", "r8-compat-proguard")
|
||||||
|
|
||||||
|
@ -118,7 +106,6 @@ func init() {
|
||||||
})
|
})
|
||||||
|
|
||||||
pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
|
pctx.HostJavaToolVariable("JarjarCmd", "jarjar.jar")
|
||||||
pctx.HostJavaToolVariable("DesugarJar", "desugar.jar")
|
|
||||||
pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar")
|
pctx.HostJavaToolVariable("JsilverJar", "jsilver.jar")
|
||||||
pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar")
|
pctx.HostJavaToolVariable("DoclavaJar", "doclava.jar")
|
||||||
pctx.HostJavaToolVariable("MetalavaJar", "metalava.jar")
|
pctx.HostJavaToolVariable("MetalavaJar", "metalava.jar")
|
||||||
|
|
|
@ -46,15 +46,8 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
|
||||||
ctx.Strict("JAVADOC", "${JavadocCmd}")
|
ctx.Strict("JAVADOC", "${JavadocCmd}")
|
||||||
ctx.Strict("COMMON_JDK_FLAGS", "${CommonJdkFlags}")
|
ctx.Strict("COMMON_JDK_FLAGS", "${CommonJdkFlags}")
|
||||||
|
|
||||||
if ctx.Config().UseD8Desugar() {
|
ctx.Strict("DX", "${D8Cmd}")
|
||||||
ctx.Strict("DX", "${D8Cmd}")
|
ctx.Strict("DX_COMMAND", "${D8Cmd} -JXms16M -JXmx2048M")
|
||||||
ctx.Strict("DX_COMMAND", "${D8Cmd} -JXms16M -JXmx2048M")
|
|
||||||
ctx.Strict("USE_D8_DESUGAR", "true")
|
|
||||||
} else {
|
|
||||||
ctx.Strict("DX", "${DxCmd}")
|
|
||||||
ctx.Strict("DX_COMMAND", "${DxCmd} -JXms16M -JXmx2048M")
|
|
||||||
ctx.Strict("USE_D8_DESUGAR", "false")
|
|
||||||
}
|
|
||||||
ctx.Strict("R8_COMPAT_PROGUARD", "${R8Cmd}")
|
ctx.Strict("R8_COMPAT_PROGUARD", "${R8Cmd}")
|
||||||
|
|
||||||
ctx.Strict("TURBINE", "${TurbineJar}")
|
ctx.Strict("TURBINE", "${TurbineJar}")
|
||||||
|
|
120
java/dex.go
120
java/dex.go
|
@ -22,78 +22,6 @@ import (
|
||||||
"android/soong/android"
|
"android/soong/android"
|
||||||
)
|
)
|
||||||
|
|
||||||
var desugar = pctx.AndroidStaticRule("desugar",
|
|
||||||
blueprint.RuleParams{
|
|
||||||
Command: `rm -rf $dumpDir && mkdir -p $dumpDir && ` +
|
|
||||||
`${config.JavaCmd} ` +
|
|
||||||
`-Djdk.internal.lambda.dumpProxyClasses=$$(cd $dumpDir && pwd) ` +
|
|
||||||
`$javaFlags ` +
|
|
||||||
`-jar ${config.DesugarJar} $classpathFlags $desugarFlags ` +
|
|
||||||
`-i $in -o $out`,
|
|
||||||
CommandDeps: []string{"${config.DesugarJar}", "${config.JavaCmd}"},
|
|
||||||
},
|
|
||||||
"javaFlags", "classpathFlags", "desugarFlags", "dumpDir")
|
|
||||||
|
|
||||||
func (j *Module) desugar(ctx android.ModuleContext, flags javaBuilderFlags,
|
|
||||||
classesJar android.Path, jarName string) android.Path {
|
|
||||||
|
|
||||||
desugarFlags := []string{
|
|
||||||
"--min_sdk_version " + j.minSdkVersionNumber(ctx),
|
|
||||||
"--desugar_try_with_resources_if_needed=false",
|
|
||||||
"--allow_empty_bootclasspath",
|
|
||||||
}
|
|
||||||
|
|
||||||
if inList("--core-library", j.deviceProperties.Dxflags) {
|
|
||||||
desugarFlags = append(desugarFlags, "--core_library")
|
|
||||||
}
|
|
||||||
|
|
||||||
desugarJar := android.PathForModuleOut(ctx, "desugar", jarName)
|
|
||||||
dumpDir := android.PathForModuleOut(ctx, "desugar", "classes")
|
|
||||||
|
|
||||||
javaFlags := ""
|
|
||||||
if ctx.Config().UseOpenJDK9() {
|
|
||||||
javaFlags = "--add-opens java.base/java.lang.invoke=ALL-UNNAMED"
|
|
||||||
}
|
|
||||||
|
|
||||||
var classpathFlags []string
|
|
||||||
classpathFlags = append(classpathFlags, flags.bootClasspath.FormDesugarClasspath("--bootclasspath_entry")...)
|
|
||||||
classpathFlags = append(classpathFlags, flags.classpath.FormDesugarClasspath("--classpath_entry")...)
|
|
||||||
|
|
||||||
var deps android.Paths
|
|
||||||
deps = append(deps, flags.bootClasspath...)
|
|
||||||
deps = append(deps, flags.classpath...)
|
|
||||||
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
|
||||||
Rule: desugar,
|
|
||||||
Description: "desugar",
|
|
||||||
Output: desugarJar,
|
|
||||||
Input: classesJar,
|
|
||||||
Implicits: deps,
|
|
||||||
Args: map[string]string{
|
|
||||||
"dumpDir": dumpDir.String(),
|
|
||||||
"javaFlags": javaFlags,
|
|
||||||
"classpathFlags": strings.Join(classpathFlags, " "),
|
|
||||||
"desugarFlags": strings.Join(desugarFlags, " "),
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
return desugarJar
|
|
||||||
}
|
|
||||||
|
|
||||||
var dx = pctx.AndroidStaticRule("dx",
|
|
||||||
blueprint.RuleParams{
|
|
||||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
|
||||||
`${config.DxCmd} --dex --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")
|
|
||||||
|
|
||||||
var d8 = pctx.AndroidStaticRule("d8",
|
var d8 = pctx.AndroidStaticRule("d8",
|
||||||
blueprint.RuleParams{
|
blueprint.RuleParams{
|
||||||
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` +
|
||||||
|
@ -125,39 +53,24 @@ var r8 = pctx.AndroidStaticRule("r8",
|
||||||
},
|
},
|
||||||
"outDir", "outDict", "dxFlags", "r8Flags")
|
"outDir", "outDict", "dxFlags", "r8Flags")
|
||||||
|
|
||||||
func (j *Module) dxFlags(ctx android.ModuleContext, fullD8 bool) []string {
|
func (j *Module) dxFlags(ctx android.ModuleContext) []string {
|
||||||
flags := j.deviceProperties.Dxflags
|
flags := j.deviceProperties.Dxflags
|
||||||
if fullD8 {
|
// Translate all the DX flags to D8 ones until all the build files have been migrated
|
||||||
// Translate all the DX flags to D8 ones until all the build files have been migrated
|
// to D8 flags. See: b/69377755
|
||||||
// to D8 flags. See: b/69377755
|
flags = android.RemoveListFromList(flags,
|
||||||
flags = android.RemoveListFromList(flags,
|
[]string{"--core-library", "--dex", "--multi-dex"})
|
||||||
[]string{"--core-library", "--dex", "--multi-dex"})
|
|
||||||
}
|
|
||||||
|
|
||||||
if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
|
if ctx.Config().Getenv("NO_OPTIMIZE_DX") != "" {
|
||||||
if fullD8 {
|
flags = append(flags, "--debug")
|
||||||
flags = append(flags, "--debug")
|
|
||||||
} else {
|
|
||||||
flags = append(flags, "--no-optimize")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
|
if ctx.Config().Getenv("GENERATE_DEX_DEBUG") != "" {
|
||||||
flags = append(flags,
|
flags = append(flags,
|
||||||
"--debug",
|
"--debug",
|
||||||
"--verbose")
|
"--verbose")
|
||||||
if !fullD8 {
|
|
||||||
flags = append(flags,
|
|
||||||
"--dump-to="+android.PathForModuleOut(ctx, "classes.lst").String(),
|
|
||||||
"--dump-width=1000")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if fullD8 {
|
flags = append(flags, "--min-api "+j.minSdkVersionNumber(ctx))
|
||||||
flags = append(flags, "--min-api "+j.minSdkVersionNumber(ctx))
|
|
||||||
} else {
|
|
||||||
flags = append(flags, "--min-sdk-version="+j.minSdkVersionNumber(ctx))
|
|
||||||
}
|
|
||||||
return flags
|
return flags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,7 +79,7 @@ func (j *Module) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8F
|
||||||
|
|
||||||
// When an app contains references to APIs that are not in the SDK specified by
|
// When an app contains references to APIs that are not in the SDK specified by
|
||||||
// its LOCAL_SDK_VERSION for example added by support library or by runtime
|
// its LOCAL_SDK_VERSION for example added by support library or by runtime
|
||||||
// classes added by desugar, we artifically raise the "SDK version" "linked" by
|
// classes added by desugaring, we artifically raise the "SDK version" "linked" by
|
||||||
// ProGuard, to
|
// ProGuard, to
|
||||||
// - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
|
// - suppress ProGuard warnings of referencing symbols unknown to the lower SDK version.
|
||||||
// - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
|
// - prevent ProGuard stripping subclass in the support library that extends class added in the higher SDK version.
|
||||||
|
@ -223,13 +136,8 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
||||||
classesJar android.Path, jarName string) android.Path {
|
classesJar android.Path, jarName string) android.Path {
|
||||||
|
|
||||||
useR8 := Bool(j.deviceProperties.Optimize.Enabled)
|
useR8 := Bool(j.deviceProperties.Optimize.Enabled)
|
||||||
fullD8 := useR8 || ctx.Config().UseD8Desugar()
|
|
||||||
|
|
||||||
if !fullD8 {
|
dxFlags := j.dxFlags(ctx)
|
||||||
classesJar = j.desugar(ctx, flags, classesJar, jarName)
|
|
||||||
}
|
|
||||||
|
|
||||||
dxFlags := j.dxFlags(ctx, fullD8)
|
|
||||||
|
|
||||||
// Compile classes.jar into classes.dex and then javalib.jar
|
// Compile classes.jar into classes.dex and then javalib.jar
|
||||||
javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
|
javalibJar := android.PathForModuleOut(ctx, "dex", jarName)
|
||||||
|
@ -256,15 +164,9 @@ func (j *Module) compileDex(ctx android.ModuleContext, flags javaBuilderFlags,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
rule := dx
|
|
||||||
desc := "dx"
|
|
||||||
if fullD8 {
|
|
||||||
rule = d8
|
|
||||||
desc = "d8"
|
|
||||||
}
|
|
||||||
ctx.Build(pctx, android.BuildParams{
|
ctx.Build(pctx, android.BuildParams{
|
||||||
Rule: rule,
|
Rule: d8,
|
||||||
Description: desc,
|
Description: "d8",
|
||||||
Output: javalibJar,
|
Output: javalibJar,
|
||||||
Input: classesJar,
|
Input: classesJar,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
|
|
Loading…
Reference in New Issue