From de5aade0e800504095326b42ba6529aeb54f9a6b Mon Sep 17 00:00:00 2001 From: Dan Albert Date: Tue, 30 Jun 2020 12:32:51 -0700 Subject: [PATCH] Generate the known NDK libraries list. This doesn't need to be manually maintained. It briefly did need to be during the transition from the old prebuilts, but that's long gone. Test: treehugger Bug: http://b/113547923 Change-Id: If05633f3cf622ab39e560a3dfcc88f3eb50406bf --- cc/cc.go | 12 +++--------- cc/makevars.go | 11 ++++++++--- cc/ndk_library.go | 43 ++++++++----------------------------------- cc/testing.go | 29 +++++++++++++---------------- 4 files changed, 32 insertions(+), 63 deletions(-) diff --git a/cc/cc.go b/cc/cc.go index c3b0d88c3..62e367b09 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -873,7 +873,7 @@ func (c *Module) isCoverageVariant() bool { } func (c *Module) IsNdk() bool { - return inList(c.Name(), ndkMigratedLibs) + return inList(c.Name(), ndkKnownLibs) } func (c *Module) isLlndk(config android.Config) bool { @@ -1759,8 +1759,6 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { variantNdkLibs := []string{} variantLateNdkLibs := []string{} if ctx.Os() == android.Android { - version := ctx.sdkVersion() - // rewriteLibs takes a list of names of shared libraries and scans it for three types // of names: // @@ -1802,12 +1800,8 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) { for _, entry := range list { // strip #version suffix out name, _ := StubsLibNameAndVersion(entry) - if ctx.useSdk() && inList(name, ndkPrebuiltSharedLibraries) { - if !inList(name, ndkMigratedLibs) { - nonvariantLibs = append(nonvariantLibs, name+".ndk."+version) - } else { - variantLibs = append(variantLibs, name+ndkLibrarySuffix) - } + if ctx.useSdk() && inList(name, ndkKnownLibs) { + variantLibs = append(variantLibs, name+ndkLibrarySuffix) } else if ctx.useVndk() { nonvariantLibs = append(nonvariantLibs, rewriteVendorLibs(entry)) } else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) { diff --git a/cc/makevars.go b/cc/makevars.go index 0f9f4c1e1..4cb414e1f 100644 --- a/cc/makevars.go +++ b/cc/makevars.go @@ -97,7 +97,12 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.Strict("CLANG_EXTERNAL_CFLAGS", "${config.ClangExternalCflags}") ctx.Strict("GLOBAL_CLANG_CFLAGS_NO_OVERRIDE", "${config.NoOverrideClangGlobalCflags}") ctx.Strict("GLOBAL_CLANG_CPPFLAGS_NO_OVERRIDE", "") - ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkPrebuiltSharedLibs, " ")) + ndkLibNames := []string{} + for _, lib := range ndkKnownLibs { + ndkLibNames = append(ndkLibNames, strings.TrimPrefix(lib, "lib")) + } + sort.Strings(ndkLibNames) + ctx.Strict("NDK_PREBUILT_SHARED_LIBRARIES", strings.Join(ndkLibNames, " ")) ctx.Strict("BOARD_VNDK_VERSION", ctx.DeviceConfig().VndkVersion()) @@ -174,8 +179,8 @@ func makeVarsProvider(ctx android.MakeVarsContext) { ctx.StrictRaw("SRC_HEADERS", strings.Join(includes, " ")) ctx.StrictRaw("SRC_SYSTEM_HEADERS", strings.Join(systemIncludes, " ")) - sort.Strings(ndkMigratedLibs) - ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkMigratedLibs, " ")) + sort.Strings(ndkKnownLibs) + ctx.Strict("NDK_MIGRATED_LIBS", strings.Join(ndkKnownLibs, " ")) hostTargets := ctx.Config().Targets[android.BuildOs] makeVarsToolchain(ctx, "", hostTargets[0]) diff --git a/cc/ndk_library.go b/cc/ndk_library.go index 5ef9a7838..6299b009e 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -47,37 +47,10 @@ var ( ndkLibrarySuffix = ".ndk" - ndkPrebuiltSharedLibs = []string{ - "aaudio", - "amidi", - "android", - "binder_ndk", - "c", - "camera2ndk", - "dl", - "EGL", - "GLESv1_CM", - "GLESv2", - "GLESv3", - "jnigraphics", - "log", - "mediandk", - "nativewindow", - "m", - "neuralnetworks", - "OpenMAXAL", - "OpenSLES", - "stdc++", - "sync", - "vulkan", - "z", - } - ndkPrebuiltSharedLibraries = addPrefix(append([]string(nil), ndkPrebuiltSharedLibs...), "lib") - - // These libraries have migrated over to the new ndk_library, which is added - // as a variation dependency via depsMutator. - ndkMigratedLibs = []string{} - ndkMigratedLibsLock sync.Mutex // protects ndkMigratedLibs writes during parallel BeginMutator + // Added as a variation dependency via depsMutator. + ndkKnownLibs = []string{} + // protects ndkKnownLibs writes during parallel BeginMutator. + ndkKnownLibsLock sync.Mutex ) // Creates a stub shared library based on the provided version file. @@ -257,14 +230,14 @@ func (c *stubDecorator) compilerInit(ctx BaseModuleContext) { ctx.PropertyErrorf("name", "Do not append %q manually, just use the base name", ndkLibrarySuffix) } - ndkMigratedLibsLock.Lock() - defer ndkMigratedLibsLock.Unlock() - for _, lib := range ndkMigratedLibs { + ndkKnownLibsLock.Lock() + defer ndkKnownLibsLock.Unlock() + for _, lib := range ndkKnownLibs { if lib == name { return } } - ndkMigratedLibs = append(ndkMigratedLibs, name) + ndkKnownLibs = append(ndkKnownLibs, name) } func addStubLibraryCompilerFlags(flags Flags) Flags { diff --git a/cc/testing.go b/cc/testing.go index b5cf45c55..b0c3c162a 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -32,6 +32,7 @@ func RegisterRequiredBuildComponentsForTest(ctx android.RegistrationContext) { ctx.RegisterModuleType("cc_object", ObjectFactory) ctx.RegisterModuleType("ndk_prebuilt_shared_stl", NdkPrebuiltSharedStlFactory) ctx.RegisterModuleType("ndk_prebuilt_object", NdkPrebuiltObjectFactory) + ctx.RegisterModuleType("ndk_library", NdkLibraryFactory) } func GatherRequiredDepsForTest(oses ...android.OsType) string { @@ -393,25 +394,22 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string { system_shared_libs: [], } - cc_library { - name: "libc.ndk.current", - sdk_version: "current", - stl: "none", - system_shared_libs: [], + ndk_library { + name: "libc", + first_version: "minimum", + symbol_file: "libc.map.txt", } - cc_library { - name: "libm.ndk.current", - sdk_version: "current", - stl: "none", - system_shared_libs: [], + ndk_library { + name: "libm", + first_version: "minimum", + symbol_file: "libm.map.txt", } - cc_library { - name: "libdl.ndk.current", - sdk_version: "current", - stl: "none", - system_shared_libs: [], + ndk_library { + name: "libdl", + first_version: "minimum", + symbol_file: "libdl.map.txt", } ndk_prebuilt_object { @@ -503,7 +501,6 @@ func CreateTestContext() *android.TestContext { ctx.RegisterModuleType("cc_fuzz", FuzzFactory) ctx.RegisterModuleType("cc_test", TestFactory) ctx.RegisterModuleType("llndk_headers", llndkHeadersFactory) - ctx.RegisterModuleType("ndk_library", NdkLibraryFactory) ctx.RegisterModuleType("vendor_public_library", vendorPublicLibraryFactory) ctx.RegisterModuleType("filegroup", android.FileGroupFactory) ctx.RegisterModuleType("vndk_prebuilt_shared", VndkPrebuiltSharedFactory)