Fix and test vendor public libraries for product modules

Vendor public libraries are checked for product modules, but never
reached because the VNDK check occurs first, and wouldn't work anyways
because vendor_public_library did not have the product_available
property.  Reorder the rewrite checks and add VendorProperties, and
add a test.

Bug: 178231622
Test: vendor_public_library_test.go
Change-Id: Idbd2802fbd134d22c30600762cb0465633703506
This commit is contained in:
Colin Cross 2021-04-26 14:35:38 -07:00
parent f12db530d0
commit b719c0194e
3 changed files with 22 additions and 3 deletions

View File

@ -2070,8 +2070,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
nonvariantLibs = append(nonvariantLibs, rewriteSnapshotLib(entry, getSnapshot().SharedLibs))
} else if ctx.useSdk() && inList(name, *getNDKKnownLibs(ctx.Config())) {
variantLibs = append(variantLibs, name+ndkLibrarySuffix)
} else if ctx.useVndk() {
nonvariantLibs = append(nonvariantLibs, rewriteSnapshotLib(entry, getSnapshot().SharedLibs))
} else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
vendorPublicLib := name + vendorPublicLibrarySuffix
if actx.OtherModuleExists(vendorPublicLib) {
@ -2082,6 +2080,8 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
// link to the original library.
nonvariantLibs = append(nonvariantLibs, name)
}
} else if ctx.useVndk() {
nonvariantLibs = append(nonvariantLibs, rewriteSnapshotLib(entry, getSnapshot().SharedLibs))
} else {
// put name#version back
nonvariantLibs = append(nonvariantLibs, entry)

View File

@ -155,6 +155,7 @@ func vendorPublicLibraryFactory() android.Module {
module.AddProperties(
&stub.Properties,
&module.VendorProperties,
&library.MutatedProperties,
&library.flagExporter.Properties)

View File

@ -23,10 +23,12 @@ func TestVendorPublicLibraries(t *testing.T) {
ctx := testCc(t, `
cc_library_headers {
name: "libvendorpublic_headers",
product_available: true,
export_include_dirs: ["my_include"],
}
vendor_public_library {
name: "libvendorpublic",
product_available: true,
symbol_file: "",
export_public_headers: ["libvendorpublic_headers"],
}
@ -46,6 +48,14 @@ func TestVendorPublicLibraries(t *testing.T) {
no_libcrt: true,
nocrt: true,
}
cc_library {
name: "libproduct",
shared_libs: ["libvendorpublic"],
product_specific: true,
srcs: ["foo.c"],
no_libcrt: true,
nocrt: true,
}
cc_library {
name: "libvendor",
shared_libs: ["libvendorpublic"],
@ -58,6 +68,7 @@ func TestVendorPublicLibraries(t *testing.T) {
coreVariant := "android_arm64_armv8-a_shared"
vendorVariant := "android_vendor.29_arm64_armv8-a_shared"
productVariant := "android_product.29_arm64_armv8-a_shared"
// test if header search paths are correctly added
// _static variant is used since _shared reuses *.o from the static variant
@ -75,6 +86,14 @@ func TestVendorPublicLibraries(t *testing.T) {
t.Errorf("libflags for libsystem must contain %#v, but was %#v", stubPaths[0], libflags)
}
// test if libsystem is linked to the stub
ld = ctx.ModuleForTests("libproduct", productVariant).Rule("ld")
libflags = ld.Args["libFlags"]
stubPaths = getOutputPaths(ctx, productVariant, []string{"libvendorpublic" + vendorPublicLibrarySuffix})
if !strings.Contains(libflags, stubPaths[0].String()) {
t.Errorf("libflags for libproduct must contain %#v, but was %#v", stubPaths[0], libflags)
}
// test if libvendor is linked to the real shared lib
ld = ctx.ModuleForTests("libvendor", vendorVariant).Rule("ld")
libflags = ld.Args["libFlags"]
@ -82,5 +101,4 @@ func TestVendorPublicLibraries(t *testing.T) {
if !strings.Contains(libflags, stubPaths[0].String()) {
t.Errorf("libflags for libvendor must contain %#v, but was %#v", stubPaths[0], libflags)
}
}