Merge "Support transitive proguard specs in android_library_import" into main

This commit is contained in:
Treehugger Robot 2024-03-28 03:56:29 +00:00 committed by Gerrit Code Review
commit f875565c7f
3 changed files with 54 additions and 15 deletions

View file

@ -1161,11 +1161,17 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
a.rTxt = extractedAARDir.Join(ctx, "R.txt") a.rTxt = extractedAARDir.Join(ctx, "R.txt")
a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip") a.assetsPackage = android.PathForModuleOut(ctx, "assets.zip")
a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt") a.proguardFlags = extractedAARDir.Join(ctx, "proguard.txt")
transitiveProguardFlags, transitiveUnconditionalExportedFlags := collectDepProguardSpecInfo(ctx)
android.SetProvider(ctx, ProguardSpecInfoProvider, ProguardSpecInfo{ android.SetProvider(ctx, ProguardSpecInfoProvider, ProguardSpecInfo{
ProguardFlagsFiles: android.NewDepSet[android.Path]( ProguardFlagsFiles: android.NewDepSet[android.Path](
android.POSTORDER, android.POSTORDER,
android.Paths{a.proguardFlags}, android.Paths{a.proguardFlags},
transitiveProguardFlags,
),
UnconditionallyExportedProguardFlags: android.NewDepSet[android.Path](
android.POSTORDER,
nil, nil,
transitiveUnconditionalExportedFlags,
), ),
}) })

View file

@ -3625,7 +3625,10 @@ func TestExportedProguardFlagFiles(t *testing.T) {
android_app { android_app {
name: "foo", name: "foo",
sdk_version: "current", sdk_version: "current",
static_libs: ["lib1"], static_libs: [
"lib1",
"lib3",
],
} }
android_library { android_library {
@ -3633,22 +3636,49 @@ func TestExportedProguardFlagFiles(t *testing.T) {
sdk_version: "current", sdk_version: "current",
optimize: { optimize: {
proguard_flags_files: ["lib1proguard.cfg"], proguard_flags_files: ["lib1proguard.cfg"],
},
static_libs: ["lib2"],
}
android_library {
name: "lib2",
sdk_version: "current",
optimize: {
proguard_flags_files: ["lib2proguard.cfg"],
} }
} }
android_library_import {
name: "lib3",
sdk_version: "current",
aars: ["lib3.aar"],
static_libs: ["lib4"],
}
android_library {
name: "lib4",
sdk_version: "current",
optimize: {
proguard_flags_files: ["lib4proguard.cfg"],
}
}
`) `)
m := ctx.ModuleForTests("foo", "android_common") m := ctx.ModuleForTests("foo", "android_common")
hasLib1Proguard := false r8 := m.Rule("java.r8")
for _, s := range m.Rule("java.r8").Implicits.Strings() { implicits := r8.Implicits.RelativeToTop().Strings()
if s == "lib1proguard.cfg" { android.AssertStringListContains(t, "r8 implicits", implicits, "lib1proguard.cfg")
hasLib1Proguard = true android.AssertStringListContains(t, "r8 implicits", implicits, "lib2proguard.cfg")
break android.AssertStringListContains(t, "r8 implicits", implicits, "lib4proguard.cfg")
} android.AssertStringListContains(t, "r8 implicits", implicits, "out/soong/.intermediates/lib3/android_common/aar/proguard.txt")
}
if !hasLib1Proguard { flags := r8.Args["r8Flags"]
t.Errorf("App does not use library proguard config") android.AssertStringDoesContain(t, "r8 flags", flags, "-include lib1proguard.cfg")
} android.AssertStringDoesContain(t, "r8 flags", flags, "-include lib2proguard.cfg")
android.AssertStringDoesContain(t, "r8 flags", flags, "-include lib4proguard.cfg")
android.AssertStringDoesContain(t, "r8 flags", flags, "-include out/soong/.intermediates/lib3/android_common/aar/proguard.txt")
} }
func TestTargetSdkVersionManifestFixer(t *testing.T) { func TestTargetSdkVersionManifestFixer(t *testing.T) {

View file

@ -1757,10 +1757,7 @@ func (j *Module) useCompose() bool {
return android.InList("androidx.compose.runtime_runtime", j.properties.Static_libs) return android.InList("androidx.compose.runtime_runtime", j.properties.Static_libs)
} }
func (j *Module) collectProguardSpecInfo(ctx android.ModuleContext) ProguardSpecInfo { func collectDepProguardSpecInfo(ctx android.ModuleContext) (transitiveProguardFlags, transitiveUnconditionalExportedFlags []*android.DepSet[android.Path]) {
transitiveUnconditionalExportedFlags := []*android.DepSet[android.Path]{}
transitiveProguardFlags := []*android.DepSet[android.Path]{}
ctx.VisitDirectDeps(func(m android.Module) { ctx.VisitDirectDeps(func(m android.Module) {
depProguardInfo, _ := android.OtherModuleProvider(ctx, m, ProguardSpecInfoProvider) depProguardInfo, _ := android.OtherModuleProvider(ctx, m, ProguardSpecInfoProvider)
depTag := ctx.OtherModuleDependencyTag(m) depTag := ctx.OtherModuleDependencyTag(m)
@ -1775,6 +1772,12 @@ func (j *Module) collectProguardSpecInfo(ctx android.ModuleContext) ProguardSpec
} }
}) })
return transitiveProguardFlags, transitiveUnconditionalExportedFlags
}
func (j *Module) collectProguardSpecInfo(ctx android.ModuleContext) ProguardSpecInfo {
transitiveProguardFlags, transitiveUnconditionalExportedFlags := collectDepProguardSpecInfo(ctx)
directUnconditionalExportedFlags := android.Paths{} directUnconditionalExportedFlags := android.Paths{}
proguardFlagsForThisModule := android.PathsForModuleSrc(ctx, j.dexProperties.Optimize.Proguard_flags_files) proguardFlagsForThisModule := android.PathsForModuleSrc(ctx, j.dexProperties.Optimize.Proguard_flags_files)
exportUnconditionally := proptools.Bool(j.dexProperties.Optimize.Export_proguard_flags_files) exportUnconditionally := proptools.Bool(j.dexProperties.Optimize.Export_proguard_flags_files)