Use and export proguard flags from static dependencies

Export proguard flags from Android library modules, and use them
from static dependencies in Android apps when running proguard.
Also export them to Make.

Unlike Make, which concatentates all the exported flags from
dependencies, Soong dedups exported flags files.

Bug: 73724997
Test: m checkbuild
Change-Id: I8f86fecb09cbc591832ce67e8ecef551a6600349
Merged-In: I8f86fecb09cbc591832ce67e8ecef551a6600349
(cherry picked from commit 89c31581a5)
This commit is contained in:
Colin Cross 2018-04-30 15:55:11 -07:00
parent d53eb96ca8
commit 5507bc7fc8
3 changed files with 36 additions and 3 deletions

View File

@ -25,6 +25,7 @@ import (
type AndroidLibraryDependency interface {
Dependency
ExportPackage() android.Path
ExportedProguardFlagFiles() android.Paths
}
func init() {
@ -247,6 +248,12 @@ type AndroidLibrary struct {
androidLibraryProperties androidLibraryProperties
aarFile android.WritablePath
exportedProguardFlagFiles android.Paths
}
func (a *AndroidLibrary) ExportedProguardFlagFiles() android.Paths {
return a.exportedProguardFlagFiles
}
var _ AndroidLibraryDependency = (*AndroidLibrary)(nil)
@ -279,6 +286,14 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
BuildAAR(ctx, a.aarFile, a.outputFile, a.manifestPath, a.rTxt, res)
ctx.CheckbuildFile(a.aarFile)
}
ctx.VisitDirectDeps(func(m android.Module) {
if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
a.exportedProguardFlagFiles = append(a.exportedProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
}
})
a.exportedProguardFlagFiles = android.FirstUniquePaths(a.exportedProguardFlagFiles)
}
func AndroidLibraryFactory() android.Module {
@ -327,6 +342,10 @@ func (a *AARImport) ExportPackage() android.Path {
return a.exportPackage
}
func (a *AARImport) ExportedProguardFlagFiles() android.Paths {
return android.Paths{a.proguardFlags}
}
func (a *AARImport) Prebuilt() *android.Prebuilt {
return &a.prebuilt
}

View File

@ -233,7 +233,8 @@ func (a *AndroidLibrary) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE :=", a.exportPackage.String())
fmt.Fprintln(w, "LOCAL_FULL_MANIFEST_FILE :=", a.manifestPath.String())
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=", a.proguardOptionsFile.String())
fmt.Fprintln(w, "LOCAL_SOONG_EXPORT_PROGUARD_FLAGS :=",
strings.Join(a.exportedProguardFlagFiles.Strings(), " "))
fmt.Fprintln(w, "LOCAL_UNINSTALLABLE_MODULE := true")
fmt.Fprintln(w, "LOCAL_DEX_PREOPT := false")
})

View File

@ -63,6 +63,10 @@ type AndroidApp struct {
appProperties appProperties
}
func (a *AndroidApp) ExportedProguardFlagFiles() android.Paths {
return nil
}
var _ AndroidLibraryDependency = (*AndroidApp)(nil)
type certificate struct {
@ -116,8 +120,17 @@ func (a *AndroidApp) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// apps manifests are handled by aapt, don't let Module see them
a.properties.Manifest = nil
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles,
a.proguardOptionsFile)
var staticLibProguardFlagFiles android.Paths
ctx.VisitDirectDeps(func(m android.Module) {
if lib, ok := m.(AndroidLibraryDependency); ok && ctx.OtherModuleDependencyTag(m) == staticLibTag {
staticLibProguardFlagFiles = append(staticLibProguardFlagFiles, lib.ExportedProguardFlagFiles()...)
}
})
staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
if ctx.ModuleName() != "framework-res" {
a.Module.compile(ctx, a.aaptSrcJar)