Include proguard flag files from transitive java_library deps

Ensure proguard flag files specified by java_library targets propagate
to downstream targets. This matches bazel behavior, as well as
behavior for transitive android_library deps.

Bug: 212623640
Test: m + presubmit
Change-Id: I61abaf1fd43d6f06bb610383751bb26e9a1bafd6
This commit is contained in:
Jared Duke
2022-05-11 15:41:34 -07:00
parent c34d91436a
commit 9c54f032b9
4 changed files with 87 additions and 13 deletions

View File

@@ -283,6 +283,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
@@ -585,9 +590,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.
@@ -683,6 +696,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) {