Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 26464230 authored by Jooyung Han's avatar Jooyung Han Committed by Gerrit Code Review
Browse files

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

* changes:
  Enable dup check for test apexes
  Add apex.unwanted_transitive_deps property
parents c012b631 912a6f35
Loading
Loading
Loading
Loading
+18 −6
Original line number Diff line number Diff line
@@ -135,6 +135,11 @@ type apexBundleProperties struct {
	// List of filesystem images that are embedded inside this APEX bundle.
	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 SDK version that the APEX was first introduced.
	Min_sdk_version *string
@@ -2003,11 +2008,21 @@ type visitorContext struct {

	// if true, raise error on duplicate apexFile
	checkDuplicate bool

	// visitor skips these from this list of module names
	unwantedTransitiveDeps []string
}

func (vctx *visitorContext) normalizeFileInfo(mctx android.ModuleContext) {
	encountered := make(map[string]apexFile)
	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())
		if e, ok := encountered[dest]; !ok {
			encountered[dest] = f
@@ -2371,10 +2386,6 @@ func (a *apexBundle) shouldCheckDuplicate(ctx android.ModuleContext) bool {
	if a.properties.IsCoverageVariant {
		return false
	}
	// TODO(b/263308515) remove this
	if a.testApex {
		return false
	}
	if ctx.DeviceConfig().DeviceArch() == "" {
		return false
	}
@@ -2403,6 +2414,7 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
	vctx := visitorContext{
		handleSpecialLibs:      !android.Bool(a.properties.Ignore_system_library_special_case),
		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) })
	vctx.normalizeFileInfo(ctx)
+36 −0
Original line number Diff line number Diff line
@@ -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) {
	testApexError(t, `"myjar" is not configured to be compiled into dex`, `
		apex {