Merge "Include proguard flag files from transitive java_library deps" am: c1260dd095
am: 0edced0f95
Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2095983 Change-Id: I92ff1e1483ed537fd8752b979a42f4dcc7b8b674 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
f422d94b19
4 changed files with 87 additions and 13 deletions
22
java/aar.go
22
java/aar.go
|
@ -29,8 +29,8 @@ import (
|
|||
)
|
||||
|
||||
type AndroidLibraryDependency interface {
|
||||
LibraryDependency
|
||||
ExportPackage() android.Path
|
||||
ExportedProguardFlagFiles() android.Paths
|
||||
ExportedRRODirs() []rroDir
|
||||
ExportedStaticPackages() android.Paths
|
||||
ExportedManifests() android.Paths
|
||||
|
@ -498,8 +498,7 @@ type AndroidLibrary struct {
|
|||
|
||||
aarFile android.WritablePath
|
||||
|
||||
exportedProguardFlagFiles android.Paths
|
||||
exportedStaticPackages android.Paths
|
||||
exportedStaticPackages android.Paths
|
||||
}
|
||||
|
||||
var _ android.OutputFileProducer = (*AndroidLibrary)(nil)
|
||||
|
@ -514,10 +513,6 @@ func (a *AndroidLibrary) OutputFiles(tag string) (android.Paths, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths {
|
||||
return a.exportedProguardFlagFiles
|
||||
}
|
||||
|
||||
func (a *AndroidLibrary) ExportedStaticPackages() android.Paths {
|
||||
return a.exportedStaticPackages
|
||||
}
|
||||
|
@ -566,13 +561,16 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
|
|||
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles,
|
||||
android.PathsForModuleSrc(ctx, a.dexProperties.Optimize.Proguard_flags_files)...)
|
||||
ctx.VisitDirectDeps(func(m android.Module) {
|
||||
if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
||||
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
|
||||
a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportPackage())
|
||||
a.exportedStaticPackages = append(a.exportedStaticPackages, lib.ExportedStaticPackages()...)
|
||||
if ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
||||
if lib, ok := m.(LibraryDependency); ok {
|
||||
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
|
||||
}
|
||||
if alib, ok := m.(AndroidLibraryDependency); ok {
|
||||
a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportPackage())
|
||||
a.exportedStaticPackages = append(a.exportedStaticPackages, alib.ExportedStaticPackages()...)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
|
||||
a.exportedStaticPackages = android.FirstUniquePaths(a.exportedStaticPackages)
|
||||
|
||||
|
|
|
@ -457,7 +457,7 @@ func (a *AndroidApp) aaptBuildActions(ctx android.ModuleContext) {
|
|||
func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) {
|
||||
var staticLibProguardFlagFiles android.Paths
|
||||
ctx.VisitDirectDeps(func(m android.Module) {
|
||||
if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
||||
if lib, ok := m.(LibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
||||
staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
|
||||
}
|
||||
})
|
||||
|
|
|
@ -155,3 +155,57 @@ func TestD8(t *testing.T) {
|
|||
android.AssertStringDoesNotContain(t, "expected no static_lib header jar in foo javac classpath",
|
||||
fooD8.Args["d8Flags"], staticLibHeader.String())
|
||||
}
|
||||
|
||||
func TestProguardFlagsInheritance(t *testing.T) {
|
||||
result := PrepareForTestWithJavaDefaultModulesWithoutFakeDex2oatd.RunTestWithBp(t, `
|
||||
android_app {
|
||||
name: "app",
|
||||
static_libs: [
|
||||
"primary_android_lib",
|
||||
"primary_lib",
|
||||
],
|
||||
platform_apis: true,
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "primary_lib",
|
||||
optimize: {
|
||||
proguard_flags_files: ["primary.flags"],
|
||||
},
|
||||
}
|
||||
|
||||
android_library {
|
||||
name: "primary_android_lib",
|
||||
static_libs: ["secondary_lib"],
|
||||
optimize: {
|
||||
proguard_flags_files: ["primary_android.flags"],
|
||||
},
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "secondary_lib",
|
||||
static_libs: ["tertiary_lib"],
|
||||
optimize: {
|
||||
proguard_flags_files: ["secondary.flags"],
|
||||
},
|
||||
}
|
||||
|
||||
java_library {
|
||||
name: "tertiary_lib",
|
||||
optimize: {
|
||||
proguard_flags_files: ["tertiary.flags"],
|
||||
},
|
||||
}
|
||||
`)
|
||||
|
||||
app := result.ModuleForTests("app", "android_common")
|
||||
appR8 := app.Rule("r8")
|
||||
android.AssertStringDoesContain(t, "expected primary_lib's proguard flags from direct dep",
|
||||
appR8.Args["r8Flags"], "primary.flags")
|
||||
android.AssertStringDoesContain(t, "expected primary_android_lib's proguard flags from direct dep",
|
||||
appR8.Args["r8Flags"], "primary_android.flags")
|
||||
android.AssertStringDoesContain(t, "expected secondary_lib's proguard flags from inherited dep",
|
||||
appR8.Args["r8Flags"], "secondary.flags")
|
||||
android.AssertStringDoesContain(t, "expected tertiary_lib's proguard flags from inherited dep",
|
||||
appR8.Args["r8Flags"], "tertiary.flags")
|
||||
}
|
||||
|
|
22
java/java.go
22
java/java.go
|
@ -294,6 +294,11 @@ type UsesLibraryDependency interface {
|
|||
ClassLoaderContexts() dexpreopt.ClassLoaderContextMap
|
||||
}
|
||||
|
||||
// Provides transitive Proguard flag files to downstream DEX jars.
|
||||
type LibraryDependency interface {
|
||||
ExportedProguardFlagFiles() android.Paths
|
||||
}
|
||||
|
||||
// TODO(jungjw): Move this to kythe.go once it's created.
|
||||
type xref interface {
|
||||
XrefJavaFiles() android.Paths
|
||||
|
@ -596,9 +601,17 @@ func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) jav
|
|||
type Library struct {
|
||||
Module
|
||||
|
||||
exportedProguardFlagFiles android.Paths
|
||||
|
||||
InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.Paths)
|
||||
}
|
||||
|
||||
var _ LibraryDependency = (*Library)(nil)
|
||||
|
||||
func (j *Library) ExportedProguardFlagFiles() android.Paths {
|
||||
return j.exportedProguardFlagFiles
|
||||
}
|
||||
|
||||
var _ android.ApexModule = (*Library)(nil)
|
||||
|
||||
// Provides access to the list of permitted packages from apex boot jars.
|
||||
|
@ -694,6 +707,15 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
|
|||
}
|
||||
j.installFile = ctx.InstallFile(installDir, j.Stem()+".jar", j.outputFile, extraInstallDeps...)
|
||||
}
|
||||
|
||||
j.exportedProguardFlagFiles = append(j.exportedProguardFlagFiles,
|
||||
android.PathsForModuleSrc(ctx, j.dexProperties.Optimize.Proguard_flags_files)...)
|
||||
ctx.VisitDirectDeps(func(m android.Module) {
|
||||
if lib, ok := m.(LibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
|
||||
j.exportedProguardFlagFiles = append(j.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
|
||||
}
|
||||
})
|
||||
j.exportedProguardFlagFiles = android.FirstUniquePaths(j.exportedProguardFlagFiles)
|
||||
}
|
||||
|
||||
func (j *Library) DepsMutator(ctx android.BottomUpMutatorContext) {
|
||||
|
|
Loading…
Reference in a new issue