Merge changes from topic "unwanted-transitive-deps" into main

* changes:
  Enable dup check for test apexes
  Add apex.unwanted_transitive_deps property
This commit is contained in:
Jooyung Han 2023-11-02 23:05:14 +00:00 committed by Gerrit Code Review
commit 26464230a1
2 changed files with 54 additions and 6 deletions

View file

@ -135,6 +135,11 @@ type apexBundleProperties struct {
// List of filesystem images that are embedded inside this APEX bundle. // List of filesystem images that are embedded inside this APEX bundle.
Filesystems []string Filesystems []string
// List of module names which we don't want to add as transitive deps. This can be used as
// a workaround when the current implementation collects more than necessary. For example,
// Rust binaries with prefer_rlib:true add unnecessary dependencies.
Unwanted_transitive_deps []string
// The minimum SDK version that this APEX must support at minimum. This is usually set to // The minimum SDK version that this APEX must support at minimum. This is usually set to
// the SDK version that the APEX was first introduced. // the SDK version that the APEX was first introduced.
Min_sdk_version *string Min_sdk_version *string
@ -2003,11 +2008,21 @@ type visitorContext struct {
// if true, raise error on duplicate apexFile // if true, raise error on duplicate apexFile
checkDuplicate bool checkDuplicate bool
// visitor skips these from this list of module names
unwantedTransitiveDeps []string
} }
func (vctx *visitorContext) normalizeFileInfo(mctx android.ModuleContext) { func (vctx *visitorContext) normalizeFileInfo(mctx android.ModuleContext) {
encountered := make(map[string]apexFile) encountered := make(map[string]apexFile)
for _, f := range vctx.filesInfo { for _, f := range vctx.filesInfo {
// Skips unwanted transitive deps. This happens, for example, with Rust binaries with prefer_rlib:true.
// TODO(b/295593640)
// Needs additional verification for the resulting APEX to ensure that skipped artifacts don't make problems.
// For example, DT_NEEDED modules should be found within the APEX unless they are marked in `requiredNativeLibs`.
if f.transitiveDep && f.module != nil && android.InList(mctx.OtherModuleName(f.module), vctx.unwantedTransitiveDeps) {
continue
}
dest := filepath.Join(f.installDir, f.builtFile.Base()) dest := filepath.Join(f.installDir, f.builtFile.Base())
if e, ok := encountered[dest]; !ok { if e, ok := encountered[dest]; !ok {
encountered[dest] = f encountered[dest] = f
@ -2371,10 +2386,6 @@ func (a *apexBundle) shouldCheckDuplicate(ctx android.ModuleContext) bool {
if a.properties.IsCoverageVariant { if a.properties.IsCoverageVariant {
return false return false
} }
// TODO(b/263308515) remove this
if a.testApex {
return false
}
if ctx.DeviceConfig().DeviceArch() == "" { if ctx.DeviceConfig().DeviceArch() == "" {
return false return false
} }
@ -2403,6 +2414,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
vctx := visitorContext{ vctx := visitorContext{
handleSpecialLibs: !android.Bool(a.properties.Ignore_system_library_special_case), handleSpecialLibs: !android.Bool(a.properties.Ignore_system_library_special_case),
checkDuplicate: a.shouldCheckDuplicate(ctx), checkDuplicate: a.shouldCheckDuplicate(ctx),
unwantedTransitiveDeps: a.properties.Unwanted_transitive_deps,
} }
ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { return a.depVisitor(&vctx, ctx, child, parent) }) ctx.WalkDepsBlueprint(func(child, parent blueprint.Module) bool { return a.depVisitor(&vctx, ctx, child, parent) })
vctx.normalizeFileInfo(ctx) vctx.normalizeFileInfo(ctx)

View file

@ -7709,6 +7709,42 @@ func TestNoDupeApexFiles(t *testing.T) {
`) `)
} }
func TestApexUnwantedTransitiveDeps(t *testing.T) {
bp := `
apex {
name: "myapex",
key: "myapex.key",
native_shared_libs: ["libfoo"],
updatable: false,
unwanted_transitive_deps: ["libbar"],
}
apex_key {
name: "myapex.key",
public_key: "testkey.avbpubkey",
private_key: "testkey.pem",
}
cc_library {
name: "libfoo",
srcs: ["foo.cpp"],
shared_libs: ["libbar"],
apex_available: ["myapex"],
}
cc_library {
name: "libbar",
srcs: ["bar.cpp"],
apex_available: ["myapex"],
}`
ctx := testApex(t, bp)
ensureExactContents(t, ctx, "myapex", "android_common_myapex", []string{
"*/libc++.so",
"*/libfoo.so",
// not libbar.so
})
}
func TestRejectNonInstallableJavaLibrary(t *testing.T) { func TestRejectNonInstallableJavaLibrary(t *testing.T) {
testApexError(t, `"myjar" is not configured to be compiled into dex`, ` testApexError(t, `"myjar" is not configured to be compiled into dex`, `
apex { apex {