Merge "Revert "Revert "R8/D8 should use sdk_version prop to determine API surface stability.""" am: de1d5bc90c
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2452286 Change-Id: I7e1d2413e35332ea7d17221761498dbf90c67578 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -1487,7 +1487,14 @@ func (j *Module) compile(ctx android.ModuleContext, aaptSrcJar android.Path) {
|
|||||||
}
|
}
|
||||||
// Dex compilation
|
// Dex compilation
|
||||||
var dexOutputFile android.OutputPath
|
var dexOutputFile android.OutputPath
|
||||||
dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), implementationAndResourcesJar, jarName)
|
params := &compileDexParams{
|
||||||
|
flags: flags,
|
||||||
|
sdkVersion: j.SdkVersion(ctx),
|
||||||
|
minSdkVersion: j.MinSdkVersion(ctx),
|
||||||
|
classesJar: implementationAndResourcesJar,
|
||||||
|
jarName: jarName,
|
||||||
|
}
|
||||||
|
dexOutputFile = j.dexer.compileDex(ctx, params)
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
33
java/dex.go
33
java/dex.go
@@ -184,7 +184,7 @@ var r8, r8RE = pctx.MultiCommandRemoteStaticRules("r8",
|
|||||||
"r8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, []string{"implicits"})
|
"r8Flags", "zipFlags", "tmpJar", "mergeZipsFlags"}, []string{"implicits"})
|
||||||
|
|
||||||
func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
|
func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
|
||||||
minSdkVersion android.SdkSpec) (flags []string, deps android.Paths) {
|
dexParams *compileDexParams) (flags []string, deps android.Paths) {
|
||||||
|
|
||||||
flags = d.dexProperties.Dxflags
|
flags = d.dexProperties.Dxflags
|
||||||
// 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
|
||||||
@@ -213,11 +213,11 @@ func (d *dexer) dexCommonFlags(ctx android.ModuleContext,
|
|||||||
// Note: Targets with a min SDK kind of core_platform (e.g., framework.jar) or unspecified (e.g.,
|
// Note: Targets with a min SDK kind of core_platform (e.g., framework.jar) or unspecified (e.g.,
|
||||||
// services.jar), are not classified as stable, which is WAI.
|
// services.jar), are not classified as stable, which is WAI.
|
||||||
// TODO(b/232073181): Expand to additional min SDK cases after validation.
|
// TODO(b/232073181): Expand to additional min SDK cases after validation.
|
||||||
if !minSdkVersion.Stable() {
|
if !dexParams.sdkVersion.Stable() {
|
||||||
flags = append(flags, "--android-platform-build")
|
flags = append(flags, "--android-platform-build")
|
||||||
}
|
}
|
||||||
|
|
||||||
effectiveVersion, err := minSdkVersion.EffectiveVersion(ctx)
|
effectiveVersion, err := dexParams.minSdkVersion.EffectiveVersion(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.PropertyErrorf("min_sdk_version", "%s", err)
|
ctx.PropertyErrorf("min_sdk_version", "%s", err)
|
||||||
}
|
}
|
||||||
@@ -340,20 +340,27 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl
|
|||||||
return r8Flags, r8Deps
|
return r8Flags, r8Deps
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, minSdkVersion android.SdkSpec,
|
type compileDexParams struct {
|
||||||
classesJar android.Path, jarName string) android.OutputPath {
|
flags javaBuilderFlags
|
||||||
|
sdkVersion android.SdkSpec
|
||||||
|
minSdkVersion android.SdkSpec
|
||||||
|
classesJar android.Path
|
||||||
|
jarName string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *dexer) compileDex(ctx android.ModuleContext, dexParams *compileDexParams) android.OutputPath {
|
||||||
|
|
||||||
// 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).OutputPath
|
javalibJar := android.PathForModuleOut(ctx, "dex", dexParams.jarName).OutputPath
|
||||||
outDir := android.PathForModuleOut(ctx, "dex")
|
outDir := android.PathForModuleOut(ctx, "dex")
|
||||||
tmpJar := android.PathForModuleOut(ctx, "withres-withoutdex", jarName)
|
tmpJar := android.PathForModuleOut(ctx, "withres-withoutdex", dexParams.jarName)
|
||||||
|
|
||||||
zipFlags := "--ignore_missing_files"
|
zipFlags := "--ignore_missing_files"
|
||||||
if proptools.Bool(d.dexProperties.Uncompress_dex) {
|
if proptools.Bool(d.dexProperties.Uncompress_dex) {
|
||||||
zipFlags += " -L 0"
|
zipFlags += " -L 0"
|
||||||
}
|
}
|
||||||
|
|
||||||
commonFlags, commonDeps := d.dexCommonFlags(ctx, minSdkVersion)
|
commonFlags, commonDeps := d.dexCommonFlags(ctx, dexParams)
|
||||||
|
|
||||||
// Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true.
|
// Exclude kotlinc generated files when "exclude_kotlinc_generated_files" is set to true.
|
||||||
mergeZipsFlags := ""
|
mergeZipsFlags := ""
|
||||||
@@ -372,7 +379,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
|
android.ModuleNameWithPossibleOverride(ctx), "unused.txt")
|
||||||
proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
|
proguardUsageZip := android.PathForModuleOut(ctx, "proguard_usage.zip")
|
||||||
d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
|
d.proguardUsageZip = android.OptionalPathForPath(proguardUsageZip)
|
||||||
r8Flags, r8Deps := d.r8Flags(ctx, flags)
|
r8Flags, r8Deps := d.r8Flags(ctx, dexParams.flags)
|
||||||
r8Deps = append(r8Deps, commonDeps...)
|
r8Deps = append(r8Deps, commonDeps...)
|
||||||
rule := r8
|
rule := r8
|
||||||
args := map[string]string{
|
args := map[string]string{
|
||||||
@@ -396,12 +403,12 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
Description: "r8",
|
Description: "r8",
|
||||||
Output: javalibJar,
|
Output: javalibJar,
|
||||||
ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip},
|
ImplicitOutputs: android.WritablePaths{proguardDictionary, proguardUsageZip},
|
||||||
Input: classesJar,
|
Input: dexParams.classesJar,
|
||||||
Implicits: r8Deps,
|
Implicits: r8Deps,
|
||||||
Args: args,
|
Args: args,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
d8Flags, d8Deps := d8Flags(flags)
|
d8Flags, d8Deps := d8Flags(dexParams.flags)
|
||||||
d8Deps = append(d8Deps, commonDeps...)
|
d8Deps = append(d8Deps, commonDeps...)
|
||||||
rule := d8
|
rule := d8
|
||||||
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") {
|
if ctx.Config().UseRBE() && ctx.Config().IsEnvTrue("RBE_D8") {
|
||||||
@@ -411,7 +418,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
Rule: rule,
|
Rule: rule,
|
||||||
Description: "d8",
|
Description: "d8",
|
||||||
Output: javalibJar,
|
Output: javalibJar,
|
||||||
Input: classesJar,
|
Input: dexParams.classesJar,
|
||||||
Implicits: d8Deps,
|
Implicits: d8Deps,
|
||||||
Args: map[string]string{
|
Args: map[string]string{
|
||||||
"d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
|
"d8Flags": strings.Join(append(commonFlags, d8Flags...), " "),
|
||||||
@@ -423,7 +430,7 @@ func (d *dexer) compileDex(ctx android.ModuleContext, flags javaBuilderFlags, mi
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
if proptools.Bool(d.dexProperties.Uncompress_dex) {
|
if proptools.Bool(d.dexProperties.Uncompress_dex) {
|
||||||
alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", jarName).OutputPath
|
alignedJavalibJar := android.PathForModuleOut(ctx, "aligned", dexParams.jarName).OutputPath
|
||||||
TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
|
TransformZipAlign(ctx, alignedJavalibJar, javalibJar)
|
||||||
javalibJar = alignedJavalibJar
|
javalibJar = alignedJavalibJar
|
||||||
}
|
}
|
||||||
|
@@ -43,6 +43,7 @@ func TestR8(t *testing.T) {
|
|||||||
name: "core_platform_app",
|
name: "core_platform_app",
|
||||||
srcs: ["foo.java"],
|
srcs: ["foo.java"],
|
||||||
sdk_version: "core_platform",
|
sdk_version: "core_platform",
|
||||||
|
min_sdk_version: "31",
|
||||||
}
|
}
|
||||||
|
|
||||||
java_library {
|
java_library {
|
||||||
|
10
java/java.go
10
java/java.go
@@ -2067,7 +2067,15 @@ func (j *Import) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||||||
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
j.dexpreopter.uncompressedDex = *j.dexProperties.Uncompress_dex
|
||||||
|
|
||||||
var dexOutputFile android.OutputPath
|
var dexOutputFile android.OutputPath
|
||||||
dexOutputFile = j.dexer.compileDex(ctx, flags, j.MinSdkVersion(ctx), outputFile, jarName)
|
dexParams := &compileDexParams{
|
||||||
|
flags: flags,
|
||||||
|
sdkVersion: j.SdkVersion(ctx),
|
||||||
|
minSdkVersion: j.MinSdkVersion(ctx),
|
||||||
|
classesJar: outputFile,
|
||||||
|
jarName: jarName,
|
||||||
|
}
|
||||||
|
|
||||||
|
dexOutputFile = j.dexer.compileDex(ctx, dexParams)
|
||||||
if ctx.Failed() {
|
if ctx.Failed() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user