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

Commit 479ca17b authored by Jooyung Han's avatar Jooyung Han
Browse files

run vndk-sp closure check before double-loadable

If vndk-sp closure fails, the error message mentions it instead of
double-loadable error. It would be more helpful since vndk-sp is more
straightforward to fix.

Bug: 171080110
Test: m (soong test added)
Change-Id: Icc762a4ffb4a8d7d6b31ef1daac17f13383518bf
parent 1e611b85
Loading
Loading
Loading
Loading
+17 −6
Original line number Diff line number Diff line
@@ -84,6 +84,7 @@ func RegisterCCBuildComponents(ctx android.RegistrationContext) {
		ctx.TopDown("lto_deps", ltoDepsMutator)
		ctx.BottomUp("lto", ltoMutator).Parallel()

		ctx.BottomUp("check_linktype", checkLinkTypeMutator).Parallel()
		ctx.TopDown("double_loadable", checkDoubleLoadableLibraries).Parallel()
	})

@@ -2004,7 +2005,7 @@ func BeginMutator(ctx android.BottomUpMutatorContext) {

// Whether a module can link to another module, taking into
// account NDK linking.
func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to LinkableInterface,
func checkLinkType(ctx android.BaseModuleContext, from LinkableInterface, to LinkableInterface,
	tag blueprint.DependencyTag) {

	switch t := tag.(type) {
@@ -2124,6 +2125,18 @@ func checkLinkType(ctx android.ModuleContext, from LinkableInterface, to Linkabl
	}
}

func checkLinkTypeMutator(ctx android.BottomUpMutatorContext) {
	if c, ok := ctx.Module().(*Module); ok {
		ctx.VisitDirectDeps(func(dep android.Module) {
			depTag := ctx.OtherModuleDependencyTag(dep)
			ccDep, ok := dep.(LinkableInterface)
			if ok {
				checkLinkType(ctx, c, ccDep, depTag)
			}
		})
	}
}

// Tests whether the dependent library is okay to be double loaded inside a single process.
// If a library has a vendor variant and is a (transitive) dependency of an LLNDK library,
// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
@@ -2132,15 +2145,15 @@ func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
	check := func(child, parent android.Module) bool {
		to, ok := child.(*Module)
		if !ok {
			// follow thru cc.Defaults, etc.
			return true
			return false
		}

		if lib, ok := to.linker.(*libraryDecorator); !ok || !lib.shared() {
			return false
		}

		// if target lib has no vendor variant, keep checking dependency graph
		// Even if target lib has no vendor variant, keep checking dependency graph
		// in case it depends on vendor_available but not double_loadable transtively.
		if !to.HasVendorVariant() {
			return true
		}
@@ -2304,8 +2317,6 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
			return
		}

		checkLinkType(ctx, c, ccDep, depTag)

		linkFile := ccDep.OutputFile()

		if libDepTag, ok := depTag.(libraryDependencyTag); ok {
+31 −0
Original line number Diff line number Diff line
@@ -103,6 +103,7 @@ func testCcErrorWithConfig(t *testing.T, pattern string, config android.Config)
}

func testCcError(t *testing.T, pattern string, bp string) {
	t.Helper()
	config := TestConfig(buildDir, android.Android, nil, bp, nil)
	config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
	config.TestProductVariables.Platform_vndk_version = StringPtr("VER")
@@ -111,6 +112,7 @@ func testCcError(t *testing.T, pattern string, bp string) {
}

func testCcErrorProductVndk(t *testing.T, pattern string, bp string) {
	t.Helper()
	config := TestConfig(buildDir, android.Android, nil, bp, nil)
	config.TestProductVariables.DeviceVndkVersion = StringPtr("current")
	config.TestProductVariables.ProductVndkVersion = StringPtr("current")
@@ -1637,6 +1639,35 @@ func TestDoubleLoadableDepError(t *testing.T) {
	`)
}

func TestCheckVndkMembershipBeforeDoubleLoadable(t *testing.T) {
	testCcError(t, "module \"libvndksp\" variant .*: .*: VNDK-SP must only depend on VNDK-SP", `
		cc_library {
			name: "libvndksp",
			shared_libs: ["libanothervndksp"],
			vendor_available: true,
			vndk: {
				enabled: true,
				support_system_process: true,
			}
		}

		cc_library {
			name: "libllndk",
			shared_libs: ["libanothervndksp"],
		}

		llndk_library {
			name: "libllndk",
			symbol_file: "",
		}

		cc_library {
			name: "libanothervndksp",
			vendor_available: true,
		}
	`)
}

func TestVndkExt(t *testing.T) {
	// This test checks the VNDK-Ext properties.
	bp := `
+1 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ func (vndk *vndkdep) typeName() string {
	return "native:vendor:vndkspext"
}

func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag blueprint.DependencyTag) {
func (vndk *vndkdep) vndkCheckLinkType(ctx android.BaseModuleContext, to *Module, tag blueprint.DependencyTag) {
	if to.linker == nil {
		return
	}