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

Commit ea91a175 authored by Colin Cross's avatar Colin Cross
Browse files

Don't magically use implementations for modules in the same apex

To reduce the complexity of the apex logic, remove the apex top down
mutator, and make the build system more understandable, remove the
logic that automatically uses implementations of modules that have
stubs but are in the same apex.  Modules in an apex that want to
depend on the implementations of another module should depend on it
using <dep>#impl.  Misuse of the #impl syntax to depend on a module
that is not in the same will be detected and reported as an error
by the apex when it sees a transitive dependency linked against an
implementation library that is not in the apex.

Bug: 372543712
Test: all apex tests pass
Test: builds
Change-Id: I28a1bb0ca71d5cfeaae145e951c436315aadf5ca
parent cc27a84f
Loading
Loading
Loading
Loading
+8 −9
Original line number Diff line number Diff line
@@ -929,7 +929,7 @@ func TestApexWithStubs(t *testing.T) {
		cc_library {
			name: "mylib",
			srcs: ["mylib.cpp"],
			shared_libs: ["mylib2", "mylib3", "my_prebuilt_platform_lib", "my_prebuilt_platform_stub_only_lib"],
			shared_libs: ["mylib2", "mylib3#impl", "my_prebuilt_platform_lib", "my_prebuilt_platform_stub_only_lib"],
			system_shared_libs: [],
			stl: "none",
			apex_available: [ "myapex" ],
@@ -1025,7 +1025,7 @@ func TestApexWithStubs(t *testing.T) {
	// ... and not linking to the non-stub (impl) variant of mylib2
	ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")

	// Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
	// Ensure that mylib is linking with the non-stub (impl) of mylib3 (because the dependency is added with mylib3#impl)
	ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex10000/mylib3.so")
	// .. and not linking to the stubs variant of mylib3
	ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_12/mylib3.so")
@@ -1201,7 +1201,7 @@ func TestApexWithStubsWithMinSdkVersion(t *testing.T) {
		cc_library {
			name: "mylib",
			srcs: ["mylib.cpp"],
			shared_libs: ["mylib2", "mylib3"],
			shared_libs: ["mylib2", "mylib3#impl"],
			system_shared_libs: [],
			stl: "none",
			apex_available: [ "myapex" ],
@@ -1264,7 +1264,7 @@ func TestApexWithStubsWithMinSdkVersion(t *testing.T) {
	// ... and not linking to the non-stub (impl) variant of mylib2
	ensureNotContains(t, mylibLdFlags, "mylib2/android_arm64_armv8-a_shared/mylib2.so")

	// Ensure that mylib is linking with the non-stub (impl) of mylib3 (because mylib3 is in the same apex)
	// Ensure that mylib is linking with the non-stub (impl) of mylib3 (because the dependency is added with mylib3#impl)
	ensureContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_apex29/mylib3.so")
	// .. and not linking to the stubs variant of mylib3
	ensureNotContains(t, mylibLdFlags, "mylib3/android_arm64_armv8-a_shared_29/mylib3.so")
@@ -1797,8 +1797,8 @@ func TestApexWithSystemLibsStubs(t *testing.T) {
		cc_library {
			name: "mylib",
			srcs: ["mylib.cpp"],
			system_shared_libs: ["libc", "libm"],
			shared_libs: ["libdl#27"],
			system_shared_libs: ["libc"],
			shared_libs: ["libdl#27", "libm#impl"],
			stl: "none",
			apex_available: [ "myapex" ],
		}
@@ -2962,8 +2962,7 @@ func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion
			private_key: "testkey.pem",
		}

		// mylib in myapex will link to mylib2#current
		// mylib in otherapex will link to mylib2(non-stub) in otherapex as well
		// mylib will link to mylib2#current
		cc_library {
			name: "mylib",
			srcs: ["mylib.cpp"],
@@ -2997,7 +2996,7 @@ func TestApexMinSdkVersion_OkayEvenWhenDepIsNewer_IfItSatisfiesApexMinSdkVersion
		ensureContains(t, libFlags, "android_arm64_armv8-a_"+to_variant+"/"+to+".so")
	}
	expectLink("mylib", "shared_apex29", "mylib2", "shared_current")
	expectLink("mylib", "shared_apex30", "mylib2", "shared_apex30")
	expectLink("mylib", "shared_apex30", "mylib2", "shared_current")
}

func TestApexMinSdkVersion_WorksWithSdkCodename(t *testing.T) {
+2 −5
Original line number Diff line number Diff line
@@ -3316,8 +3316,6 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
}

func ShouldUseStubForApex(ctx android.ModuleContext, dep android.Module) bool {
	depName := ctx.OtherModuleName(dep)

	inVendorOrProduct := false
	bootstrap := false
	if linkable, ok := ctx.Module().(LinkableInterface); !ok {
@@ -3347,9 +3345,8 @@ func ShouldUseStubForApex(ctx android.ModuleContext, dep android.Module) bool {

		useStubs = isNotInPlatform && !bootstrap
	} else {
		// If building for APEX, use stubs when the parent is in any APEX that
		// the child is not in.
		useStubs = !android.DirectlyInAllApexes(apexInfo, depName)
		// If building for APEX, always use stubs (can be bypassed by depending on <dep>#impl)
		useStubs = true
	}

	return useStubs