Merge "Don't write transitive dependencies to Android-${TARGET_PRODUCT}.mk" into main am: 556ba81849

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/2842060

Change-Id: I854bc7c67d7d4525fef42b031ad0b9a9c9080643
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Colin Cross
2023-11-30 01:26:48 +00:00
committed by Automerger Merge Worker
7 changed files with 91 additions and 50 deletions

View File

@@ -17,6 +17,7 @@ package java
import ( import (
"fmt" "fmt"
"path/filepath" "path/filepath"
"slices"
"strconv" "strconv"
"strings" "strings"
@@ -108,26 +109,26 @@ type aaptProperties struct {
} }
type aapt struct { type aapt struct {
aaptSrcJar android.Path aaptSrcJar android.Path
transitiveAaptRJars android.Paths transitiveAaptRJars android.Paths
transitiveAaptResourcePackages android.Paths transitiveAaptResourcePackagesFile android.Path
exportPackage android.Path exportPackage android.Path
manifestPath android.Path manifestPath android.Path
proguardOptionsFile android.Path proguardOptionsFile android.Path
rTxt android.Path rTxt android.Path
rJar android.Path rJar android.Path
extraAaptPackagesFile android.Path extraAaptPackagesFile android.Path
mergedManifestFile android.Path mergedManifestFile android.Path
noticeFile android.OptionalPath noticeFile android.OptionalPath
assetPackage android.OptionalPath assetPackage android.OptionalPath
isLibrary bool isLibrary bool
defaultManifestVersion string defaultManifestVersion string
useEmbeddedNativeLibs bool useEmbeddedNativeLibs bool
useEmbeddedDex bool useEmbeddedDex bool
usesNonSdkApis bool usesNonSdkApis bool
hasNoCode bool hasNoCode bool
LoggingParent string LoggingParent string
resourceFiles android.Paths resourceFiles android.Paths
splitNames []string splitNames []string
splits []split splits []split
@@ -552,9 +553,16 @@ func (a *aapt) buildActions(ctx android.ModuleContext, opts aaptBuildActionOptio
aapt2ExtractExtraPackages(ctx, extraPackages, srcJar) 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.aaptSrcJar = srcJar
a.transitiveAaptRJars = transitiveRJars a.transitiveAaptRJars = transitiveRJars
a.transitiveAaptResourcePackages = staticDeps.resPackages() a.transitiveAaptResourcePackagesFile = transitiveAaptResourcePackagesFile
a.exportPackage = packageRes a.exportPackage = packageRes
a.manifestPath = manifestPath a.manifestPath = manifestPath
a.proguardOptionsFile = proguardOptionsFile a.proguardOptionsFile = proguardOptionsFile
@@ -820,9 +828,13 @@ func (a *AndroidLibrary) GenerateAndroidBuildActions(ctx android.ModuleContext)
proguardSpecInfo := a.collectProguardSpecInfo(ctx) proguardSpecInfo := a.collectProguardSpecInfo(ctx)
ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo) ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo)
a.exportedProguardFlagFiles = proguardSpecInfo.ProguardFlagsFiles.ToList() exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList()
a.extraProguardFlagFiles = append(a.extraProguardFlagFiles, a.exportedProguardFlagFiles...) a.extraProguardFlagsFiles = append(a.extraProguardFlagsFiles, exportedProguardFlagsFiles...)
a.extraProguardFlagFiles = append(a.extraProguardFlagFiles, a.proguardOptionsFile) 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 extraSrcJars android.Paths
var extraCombinedJars android.Paths var extraCombinedJars android.Paths
@@ -940,15 +952,15 @@ type AARImport struct {
properties AARImportProperties properties AARImportProperties
classpathFile android.WritablePath classpathFile android.WritablePath
proguardFlags android.WritablePath proguardFlags android.WritablePath
exportPackage android.WritablePath exportPackage android.WritablePath
transitiveAaptResourcePackages android.Paths transitiveAaptResourcePackagesFile android.Path
extraAaptPackagesFile android.WritablePath extraAaptPackagesFile android.WritablePath
manifest android.WritablePath manifest android.WritablePath
assetsPackage android.WritablePath assetsPackage android.WritablePath
rTxt android.WritablePath rTxt android.WritablePath
rJar android.WritablePath rJar android.WritablePath
resourcesNodesDepSet *android.DepSet[*resourcesNode] resourcesNodesDepSet *android.DepSet[*resourcesNode]
manifestsDepSet *android.DepSet[android.Path] manifestsDepSet *android.DepSet[android.Path]
@@ -1211,7 +1223,13 @@ func (a *AARImport) GenerateAndroidBuildActions(ctx android.ModuleContext) {
_ = staticManifestsDepSet _ = staticManifestsDepSet
a.manifestsDepSet = manifestDepSetBuilder.Build() 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) a.collectTransitiveHeaderJars(ctx)
ctx.SetProvider(JavaInfoProvider, JavaInfo{ 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_HEADER_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile) entries.SetPath("LOCAL_SOONG_CLASSES_JAR", prebuilt.classpathFile)
entries.SetPath("LOCAL_SOONG_RESOURCE_EXPORT_PACKAGE", prebuilt.exportPackage) 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_EXPORT_PROGUARD_FLAGS", prebuilt.proguardFlags)
entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile) entries.SetPath("LOCAL_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", prebuilt.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", prebuilt.manifest) 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.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_SOONG_STATIC_LIBRARY_EXTRA_PACKAGES", a.extraAaptPackagesFile)
entries.SetPath("LOCAL_FULL_MANIFEST_FILE", a.mergedManifestFile) 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.SetBoolIfTrue("LOCAL_UNINSTALLABLE_MODULE", true)
entries.SetOptionalPaths("LOCAL_ACONFIG_FILES", a.getTransitiveAconfigFiles().ToList()) 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) staticLibProguardFlagFiles = android.FirstUniquePaths(staticLibProguardFlagFiles)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, staticLibProguardFlagFiles...) a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, staticLibProguardFlagFiles...)
a.Module.extraProguardFlagFiles = append(a.Module.extraProguardFlagFiles, a.proguardOptionsFile) a.Module.extraProguardFlagsFiles = append(a.Module.extraProguardFlagsFiles, a.proguardOptionsFile)
} }
func (a *AndroidApp) installPath(ctx android.ModuleContext) android.InstallPath { 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 ctx.Device() && (Bool(j.properties.Installable) || Bool(compileDex)) {
if j.hasCode(ctx) { if j.hasCode(ctx) {
if j.shouldInstrumentStatic(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")) android.PathForSource(ctx, "build/make/core/proguard.jacoco.flags"))
} }
// Dex compilation // Dex compilation

View File

@@ -264,6 +264,16 @@ var (
Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} -x 'META-INF/services/**/*'`, Command: `${config.Zip2ZipCmd} -i ${in} -o ${out} -x 'META-INF/services/**/*'`,
CommandDeps: []string{"${config.Zip2ZipCmd}"}, 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() { 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 type classpath android.Paths
func (x *classpath) formJoinedClassPath(optName string, sep string) string { func (x *classpath) formJoinedClassPath(optName string, sep string) string {

View File

@@ -91,12 +91,12 @@ type dexer struct {
dexProperties DexProperties dexProperties DexProperties
// list of extra proguard flag files // list of extra proguard flag files
extraProguardFlagFiles android.Paths extraProguardFlagsFiles android.Paths
proguardDictionary android.OptionalPath proguardDictionary android.OptionalPath
proguardConfiguration android.OptionalPath proguardConfiguration android.OptionalPath
proguardUsageZip android.OptionalPath proguardUsageZip android.OptionalPath
resourcesInput android.OptionalPath resourcesInput android.OptionalPath
resourcesOutput android.OptionalPath resourcesOutput android.OptionalPath
providesTransitiveHeaderJars providesTransitiveHeaderJars
} }
@@ -296,7 +296,7 @@ func (d *dexer) r8Flags(ctx android.ModuleContext, flags javaBuilderFlags) (r8Fl
android.PathForSource(ctx, "build/make/core/proguard.flags"), 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 // TODO(ccross): static android library proguard files
flagFiles = append(flagFiles, android.PathsForModuleSrc(ctx, opt.Proguard_flags_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 { type Library struct {
Module Module
exportedProguardFlagFiles android.Paths combinedExportedProguardFlagsFile android.Path
InstallMixin func(ctx android.ModuleContext, installPath android.Path) (extraInstallDeps android.InstallPaths) 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) proguardSpecInfo := j.collectProguardSpecInfo(ctx)
ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo) ctx.SetProvider(ProguardSpecInfoProvider, proguardSpecInfo)
j.exportedProguardFlagFiles = proguardSpecInfo.ProguardFlagsFiles.ToList() exportedProguardFlagsFiles := proguardSpecInfo.ProguardFlagsFiles.ToList()
j.extraProguardFlagFiles = append(j.extraProguardFlagFiles, j.exportedProguardFlagFiles...) 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) apexInfo := ctx.Provider(android.ApexInfoProvider).(android.ApexInfo)
if !apexInfo.IsForPlatform() { if !apexInfo.IsForPlatform() {