Don't write transitive dependencies to Android-${TARGET_PRODUCT}.mk

Java libraries were writing lists of files that changed whenever
transitive dependencies changed to Android-${TARGET_PRODUCT}.mk, causing
Kati analysis to rerun whenever a dependency was changed in Soong.
In both cases, Make would immediately use the list to write a single
output file.  Write the files in Soong and pass the path to the file
to Make instead, which will both reduce the size of
Android-${TARGET_PRODUCT}.mk and skip Kati analysis more often.

Bug: 309006256
Test: m checkbuild
Change-Id: I5dff16c6fb7cca8c6da927b37c612c7b1d0954e6
This commit is contained in:
Colin Cross 2023-11-21 15:13:56 -08:00
parent 80117e6c4f
commit 312634eb0f
7 changed files with 91 additions and 50 deletions

View file

@ -17,6 +17,7 @@ package java
import (
"fmt"
"path/filepath"
"slices"
"strconv"
"strings"
@ -108,26 +109,26 @@ type aaptProperties struct {
}
type aapt struct {
aaptSrcJar android.Path
transitiveAaptRJars android.Paths
transitiveAaptResourcePackages android.Paths
exportPackage android.Path
manifestPath android.Path
proguardOptionsFile android.Path
rTxt android.Path
rJar android.Path
extraAaptPackagesFile android.Path
mergedManifestFile android.Path
noticeFile android.OptionalPath
assetPackage android.OptionalPath
isLibrary bool
defaultManifestVersion string
useEmbeddedNativeLibs bool
useEmbeddedDex bool
usesNonSdkApis bool
hasNoCode bool
LoggingParent string
resourceFiles android.Paths
aaptSrcJar android.Path
transitiveAaptRJars android.Paths
transitiveAaptResourcePackagesFile android.Path
exportPackage android.Path
manifestPath android.Path
proguardOptionsFile android.Path
rTxt android.Path
rJar android.Path
extraAaptPackagesFile android.Path
mergedManifestFile android.Path
noticeFile android.OptionalPath
assetPackage android.OptionalPath
isLibrary bool
defaultManifestVersion string
useEmbeddedNativeLibs bool
useEmbeddedDex bool
usesNonSdkApis bool
hasNoCode bool
LoggingParent string
resourceFiles android.Paths
splitNames []string
splits []split
@ -552,9 +553,16 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
aapt2ExtractExtraPackages(ctx, extraPackages, srcJar)
}
transitiveAaptResourcePackages := staticDeps.resPackages().Strings()
transitiveAaptResourcePackages = slices.DeleteFunc(transitiveAaptResourcePackages, func(p string) bool {
return p == packageRes.String()
})
transitiveAaptResourcePackagesFile := android.PathForModuleOut(ctx, "transitive-res-packages")
android.WriteFileRule(ctx, transitiveAaptResourcePackagesFile, strings.Join(transitiveAaptResourcePackages, "\n"))
a.aaptSrcJar = srcJar
a.transitiveAaptRJars = transitiveRJars
a.transitiveAaptResourcePackages = staticDeps.resPackages()
a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile
a.exportPackage = packageRes
a.manifestPath = manifestPath
a.proguardOptionsFile = proguardOptionsFile
@ -820,9 +828,13 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
proguardSpecInfo := a.collectProguardSpecInfo(ctx)
ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo)
a.exportedProguardFlagFiles = proguardSpecInfo.ProguardFlagsFiles.ToList()
a.extraProguardFlagFiles = append(a.extraProguardFlagFiles, a.exportedProguardFlagFiles...)
a.extraProguardFlagFiles = append(a.extraProguardFlagFiles, a.proguardOptionsFile)
exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList()
a.extraProguardFlagsFiles = append(a.extraProguardFlagsFiles, exportedProguardFlagsFiles...)
a.extraProguardFlagsFiles = append(a.extraProguardFlagsFiles, a.proguardOptionsFile)
combinedExportedProguardFlagFile := android.PathForModuleOut(ctx, "export_proguard_flags")
writeCombinedProguardFlagsFile(ctx, combinedExportedProguardFlagFile, exportedProguardFlagsFiles)
a.combinedExportedProguardFlagsFile = combinedExportedProguardFlagFile
var extraSrcJars android.Paths
var extraCombinedJars android.Paths
@ -940,15 +952,15 @@ type AARImport struct {
properties AARImportProperties
classpathFile android.WritablePath
proguardFlags android.WritablePath
exportPackage android.WritablePath
transitiveAaptResourcePackages android.Paths
extraAaptPackagesFile android.WritablePath
manifest android.WritablePath
assetsPackage android.WritablePath
rTxt android.WritablePath
rJar android.WritablePath
classpathFile android.WritablePath
proguardFlags android.WritablePath
exportPackage android.WritablePath
transitiveAaptResourcePackagesFile android.Path
extraAaptPackagesFile android.WritablePath
manifest android.WritablePath
assetsPackage android.WritablePath
rTxt android.WritablePath
rJar android.WritablePath
resourcesNodesDepSet *android.DepSet[*resourcesNode]
manifestsDepSet *android.DepSet[android.Path]
@ -1211,7 +1223,13 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
_ = staticManifestsDepSet
a.manifestsDepSet = manifestDepSetBuilder.Build()
a.transitiveAaptResourcePackages = staticDeps.resPackages()
transitiveAaptResourcePackages := staticDeps.resPackages().Strings()
transitiveAaptResourcePackages = slices.DeleteFunc(transitiveAaptResourcePackages, func(p string) bool {
return p == a.exportPackage.String()
})
transitiveAaptResourcePackagesFile := android.PathForModuleOut(ctx, "transitive-res-packages")
android.WriteFileRule(ctx, transitiveAaptResourcePackagesFile, strings.Join(transitiveAaptResourcePackages, "\n"))
a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile
a.collectTransitiveHeaderJars(ctx)
ctx.SetProvider(JavaInfoProvider, JavaInfo{

View file

@ -274,7 +274,7 @@ func (prebuilt *AARImport) AndroidMkEntries() []android.AndroidMkEntries {
entries.SetPath("LOCAL_SOONG_HEADER_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage)
entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackages)
entries.SetPath("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", prebuilt.transitiveAaptResourcePackagesFile)
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest)
@ -532,10 +532,10 @@ func (a *AndroidLibrary) AndroidMkEntries() []android.AndroidMkEntries {
}
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", a.exportPackage)
entries.SetPaths("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", a.transitiveAaptResourcePackages)
entries.SetPath("LOCAL_SOONG_TRANSITIVE_RES_PACKAGES", a.transitiveAaptResourcePackagesFile)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile)
entries.AddStrings("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.exportedProguardFlagFiles.Strings()...)
entries.SetPath("LOCAL_SOONG_EXPORT_PROGUARD_FLAGS", a.combinedExportedProguardFlagsFile)
entries.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", a.getTransitiveAconfigFiles().ToList())
})

View file

@ -526,8 +526,8 @@ func (a *AndroidApp) proguardBuildActions(ctx android.ModuleContext) {
staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile)
a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, staticLibProguardFlagFiles...)
a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, a.proguardOptionsFile)
}
func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath {

View file

@ -1615,7 +1615,7 @@ func (j *Module) compile(ctx android.ModuleContext, extraSrcJars, extraClasspath
if ctx.Device() && (Bool(j.properties.Installable) || Bool(compileDex)) {
if j.hasCode(ctx) {
if j.shouldInstrumentStatic(ctx) {
j.dexer.extraProguardFlagFiles = append(j.dexer.extraProguardFlagFiles,
j.dexer.extraProguardFlagsFiles = append(j.dexer.extraProguardFlagsFiles,
android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
}
// Dex compilation

View file

@ -264,6 +264,16 @@ var (
Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} -x 'META-INF/services/**/*'`,
CommandDeps: []string{"${config.Zip2ZipCmd}"},
})
writeCombinedProguardFlagsFileRule = pctx.AndroidStaticRule("writeCombinedProguardFlagsFileRule",
blueprint.RuleParams{
Command: `rm -f $out && ` +
`for f in $in; do ` +
` echo && ` +
` echo "# including $$f" && ` +
` cat $$f; ` +
`done > $out`,
})
)
func init() {
@ -686,6 +696,15 @@ func TransformZipAlign(ctx android.ModuleContext, outputFile android.WritablePat
})
}
func writeCombinedProguardFlagsFile(ctx android.ModuleContext, outputFile android.WritablePath, files android.Paths) {
ctx.Build(pctx, android.BuildParams{
Rule: writeCombinedProguardFlagsFileRule,
Description: "write combined proguard flags file",
Inputs: files,
Output: outputFile,
})
}
type classpath android.Paths
func (x *classpath) formJoinedClassPath(optName string, sep string) string {

View file

@ -91,12 +91,12 @@ type dexer struct {
dexProperties DexProperties
// list of extra proguard flag files
extraProguardFlagFiles android.Paths
proguardDictionary android.OptionalPath
proguardConfiguration android.OptionalPath
proguardUsageZip android.OptionalPath
resourcesInput android.OptionalPath
resourcesOutput android.OptionalPath
extraProguardFlagsFiles android.Paths
proguardDictionary android.OptionalPath
proguardConfiguration android.OptionalPath
proguardUsageZip android.OptionalPath
resourcesInput android.OptionalPath
resourcesOutput android.OptionalPath
providesTransitiveHeaderJars
}
@ -301,7 +301,7 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl
android.PathForSource(ctx, "build/make/core/proguard.flags"),
}
flagFiles = append(flagFiles, d.extraProguardFlagFiles...)
flagFiles = append(flagFiles, d.extraProguardFlagsFiles...)
// TODO(ccross): static android library proguard files
flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_files)...)

View file

@ -639,7 +639,7 @@ func normalizeJavaVersion(ctx android.BaseModuleContext, javaVersion string) jav
type Library struct {
Module
exportedProguardFlagFiles android.Paths
combinedExportedProguardFlagsFile android.Path
InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths)
}
@ -700,8 +700,12 @@ func (j *Library) GenerateAndroidBuildActions(ctx android.ModuleContext) {
proguardSpecInfo := j.collectProguardSpecInfo(ctx)
ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo)
j.exportedProguardFlagFiles = proguardSpecInfo.ProguardFlagsFiles.ToList()
j.extraProguardFlagFiles = append(j.extraProguardFlagFiles, j.exportedProguardFlagFiles...)
exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList()
j.extraProguardFlagsFiles = append(j.extraProguardFlagsFiles, exportedProguardFlagsFiles...)
combinedExportedProguardFlagFile := android.PathForModuleOut(ctx, "export_proguard_flags")
writeCombinedProguardFlagsFile(ctx, combinedExportedProguardFlagFile, exportedProguardFlagsFiles)
j.combinedExportedProguardFlagsFile = combinedExportedProguardFlagFile
apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() {