diff --git a/android/androidmk.go b/android/androidmk.go index ddd51ffd5..cfd7c91de 100644 --- a/android/androidmk.go +++ b/android/androidmk.go @@ -72,6 +72,7 @@ type AndroidMkEntriesProvider interface { type AndroidMkEntries struct { Class string SubName string + OverrideName string DistFiles TaggedDistFiles OutputFile OptionalPath Disabled bool @@ -273,6 +274,9 @@ func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod bluep a.EntryMap = make(map[string][]string) amod := mod.(Module).base() name := amod.BaseModuleName() + if a.OverrideName != "" { + name = a.OverrideName + } if a.Include == "" { a.Include = "$(BUILD_PREBUILT)" diff --git a/apex/apex.go b/apex/apex.go index a9a58a66d..357c3b427 100644 --- a/apex/apex.go +++ b/apex/apex.go @@ -2383,11 +2383,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) { // system libraries. if !am.DirectlyInAnyApex() { // we need a module name for Make - name := cc.BaseModuleName() + cc.Properties.SubName - if proptools.Bool(a.properties.Use_vendor) { + name := cc.ImplementationModuleName(ctx) + + if !proptools.Bool(a.properties.Use_vendor) { // we don't use subName(.vendor) for a "use_vendor: true" apex // which is supposed to be installed in /system - name = cc.BaseModuleName() + name += cc.Properties.SubName } if !android.InList(name, a.requiredDeps) { a.requiredDeps = append(a.requiredDeps, name) diff --git a/apex/apex_test.go b/apex/apex_test.go index c52fd0452..d90dcc8d4 100644 --- a/apex/apex_test.go +++ b/apex/apex_test.go @@ -1270,10 +1270,11 @@ func TestApexDependsOnLLNDKTransitively(t *testing.T) { system_shared_libs: [], stl: "none", stubs: { versions: ["29","30"] }, + llndk_stubs: "libbar.llndk", } llndk_library { - name: "libbar", + name: "libbar.llndk", symbol_file: "", } `, func(fs map[string][]byte, config android.Config) { diff --git a/cc/androidmk.go b/cc/androidmk.go index e58a172b8..2c402c634 100644 --- a/cc/androidmk.go +++ b/cc/androidmk.go @@ -33,6 +33,7 @@ var ( ) type AndroidMkContext interface { + BaseModuleName() string Target() android.Target subAndroidMk(*android.AndroidMkEntries, interface{}) Arch() android.Arch @@ -462,6 +463,7 @@ func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android. func (c *llndkStubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { entries.Class = "SHARED_LIBRARIES" + entries.OverrideName = c.implementationModuleName(ctx.BaseModuleName()) entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) { c.libraryDecorator.androidMkWriteExportedFlags(entries) diff --git a/cc/cc.go b/cc/cc.go index dbe6346b7..be1ab8cb1 100644 --- a/cc/cc.go +++ b/cc/cc.go @@ -1040,6 +1040,16 @@ func (c *Module) HasStubsVariants() bool { return false } +// If this is a stubs library, ImplementationModuleName returns the name of the module that contains +// the implementation. If it is an implementation library it returns its own name. +func (c *Module) ImplementationModuleName(ctx android.BaseModuleContext) string { + name := ctx.OtherModuleName(c) + if versioned, ok := c.linker.(versionedInterface); ok { + name = versioned.implementationModuleName(name) + } + return name +} + func (c *Module) bootstrap() bool { return Bool(c.Properties.Bootstrap) } diff --git a/cc/cc_test.go b/cc/cc_test.go index d1780cd70..fef0c3412 100644 --- a/cc/cc_test.go +++ b/cc/cc_test.go @@ -846,10 +846,11 @@ func TestDoubleLoadbleDep(t *testing.T) { cc_library { name: "libllndk", shared_libs: ["libdoubleloadable"], + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } @@ -867,10 +868,11 @@ func TestDoubleLoadbleDep(t *testing.T) { cc_library { name: "libllndk", shared_libs: ["libvndksp"], + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } @@ -924,10 +926,11 @@ func TestDoubleLoadbleDep(t *testing.T) { cc_library { name: "libllndk", shared_libs: ["libcoreonly"], + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } @@ -1523,10 +1526,11 @@ func TestDoubleLoadableDepError(t *testing.T) { cc_library { name: "libllndk", shared_libs: ["libnondoubleloadable"], + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } @@ -1545,10 +1549,11 @@ func TestDoubleLoadableDepError(t *testing.T) { name: "libllndk", no_libcrt: true, shared_libs: ["libnondoubleloadable"], + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } @@ -1617,10 +1622,11 @@ func TestDoubleLoadableDepError(t *testing.T) { cc_library { name: "libllndk", shared_libs: ["libcoreonly"], + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } @@ -2361,9 +2367,10 @@ func TestEnforceProductVndkVersion(t *testing.T) { bp := ` cc_library { name: "libllndk", + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } cc_library { @@ -2564,16 +2571,18 @@ func TestMakeLinkType(t *testing.T) { } cc_library { name: "libllndk", + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", symbol_file: "", } cc_library { name: "libllndkprivate", + llndk_stubs: "libllndkprivate.llndk", } llndk_library { - name: "libllndkprivate", + name: "libllndkprivate.llndk", vendor_available: false, symbol_file: "", }` @@ -2987,9 +2996,10 @@ func TestLlndkLibrary(t *testing.T) { cc_library { name: "libllndk", stubs: { versions: ["1", "2"] }, + llndk_stubs: "libllndk.llndk", } llndk_library { - name: "libllndk", + name: "libllndk.llndk", } `) actual := ctx.ModuleVariantsForTests("libllndk.llndk") @@ -3017,9 +3027,14 @@ func TestLlndkHeaders(t *testing.T) { export_include_dirs: ["my_include"], } llndk_library { - name: "libllndk", + name: "libllndk.llndk", export_llndk_headers: ["libllndk_headers"], } + cc_library { + name: "libllndk", + llndk_stubs: "libllndk.llndk", + } + cc_library { name: "libvendor", shared_libs: ["libllndk"], diff --git a/cc/library.go b/cc/library.go index 090abf997..c2ebc49ad 100644 --- a/cc/library.go +++ b/cc/library.go @@ -110,6 +110,9 @@ type LibraryProperties struct { // Inject boringssl hash into the shared library. This is only intended for use by external/boringssl. Inject_bssl_hash *bool `android:"arch_variant"` + + // If this is an LLNDK library, the name of the equivalent llndk_library module. + Llndk_stubs *string } type StaticProperties struct { @@ -695,6 +698,8 @@ type versionedInterface interface { stubsVersions(ctx android.BaseMutatorContext) []string setAllStubsVersions([]string) allStubsVersions() []string + + implementationModuleName(name string) string } var _ libraryInterface = (*libraryDecorator)(nil) @@ -1205,7 +1210,7 @@ func (library *libraryDecorator) link(ctx ModuleContext, } if library.buildStubs() && !library.skipAPIDefine { - library.reexportFlags("-D" + versioningMacroName(ctx.baseModuleName()) + "=" + library.stubsVersion()) + library.reexportFlags("-D" + versioningMacroName(ctx.Module().(*Module).ImplementationModuleName(ctx)) + "=" + library.stubsVersion()) } library.flagExporter.setProvider(ctx) @@ -1358,6 +1363,10 @@ func (library *libraryDecorator) HeaderOnly() { library.MutatedProperties.BuildStatic = false } +func (library *libraryDecorator) implementationModuleName(name string) string { + return name +} + func (library *libraryDecorator) buildStubs() bool { return library.MutatedProperties.BuildStubs } diff --git a/cc/llndk_library.go b/cc/llndk_library.go index 4425a1040..9f4444d80 100644 --- a/cc/llndk_library.go +++ b/cc/llndk_library.go @@ -72,6 +72,8 @@ type llndkStubDecorator struct { movedToApex bool } +var _ versionedInterface = (*llndkStubDecorator)(nil) + func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { flags = stub.baseCompiler.compilerFlags(ctx, flags, deps) return addStubLibraryCompilerFlags(flags) @@ -101,12 +103,14 @@ func (stub *llndkStubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps { } func (stub *llndkStubDecorator) Name(name string) string { + if strings.HasSuffix(name, llndkLibrarySuffix) { + return name + } return name + llndkLibrarySuffix } func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { - stub.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), - llndkLibrarySuffix) + stub.libraryDecorator.libName = stub.implementationModuleName(ctx.ModuleName()) return stub.libraryDecorator.linkerFlags(ctx, flags) } @@ -133,7 +137,7 @@ func (stub *llndkStubDecorator) processHeaders(ctx ModuleContext, srcHeaderDir s func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps, objs Objects) android.Path { - impl := ctx.GetDirectDepWithTag(ctx.baseModuleName(), llndkImplDep) + impl := ctx.GetDirectDepWithTag(stub.implementationModuleName(ctx.ModuleName()), llndkImplDep) if implApexModule, ok := impl.(android.ApexModule); ok { stub.movedToApex = implApexModule.DirectlyInAnyApex() } @@ -167,6 +171,10 @@ func (stub *llndkStubDecorator) nativeCoverage() bool { return false } +func (stub *llndkStubDecorator) implementationModuleName(name string) string { + return strings.TrimSuffix(name, llndkLibrarySuffix) +} + func (stub *llndkStubDecorator) buildStubs() bool { return true } diff --git a/cc/ndk_library.go b/cc/ndk_library.go index f2ad652f3..02b38a60a 100644 --- a/cc/ndk_library.go +++ b/cc/ndk_library.go @@ -100,10 +100,16 @@ type stubDecorator struct { unversionedUntil android.ApiLevel } +var _ versionedInterface = (*stubDecorator)(nil) + func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool { return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil) } +func (stub *stubDecorator) implementationModuleName(name string) string { + return strings.TrimSuffix(name, ndkLibrarySuffix) +} + func ndkLibraryVersions(ctx android.BaseMutatorContext, from android.ApiLevel) []string { var versions []android.ApiLevel versionStrs := []string{} diff --git a/cc/testing.go b/cc/testing.go index 52f082990..019a18685 100644 --- a/cc/testing.go +++ b/cc/testing.go @@ -172,9 +172,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string { stubs: { versions: ["27", "28", "29"], }, - } + llndk_stubs: "libc.llndk", +} llndk_library { - name: "libc", + name: "libc.llndk", symbol_file: "", sdk_version: "current", } @@ -193,9 +194,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string { "//apex_available:platform", "myapex" ], + llndk_stubs: "libm.llndk", } llndk_library { - name: "libm", + name: "libm.llndk", symbol_file: "", sdk_version: "current", } @@ -253,9 +255,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string { "//apex_available:platform", "myapex" ], + llndk_stubs: "libdl.llndk", } llndk_library { - name: "libdl", + name: "libdl.llndk", symbol_file: "", sdk_version: "current", } @@ -265,9 +268,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string { nocrt: true, system_shared_libs: [], recovery_available: true, + llndk_stubs: "libft2.llndk", } llndk_library { - name: "libft2", + name: "libft2.llndk", symbol_file: "", vendor_available: false, sdk_version: "current", diff --git a/cc/vndk.go b/cc/vndk.go index 981e039ec..aeaec03fd 100644 --- a/cc/vndk.go +++ b/cc/vndk.go @@ -247,7 +247,7 @@ func vndkSpLibraries(config android.Config) map[string]string { } func isLlndkLibrary(baseModuleName string, config android.Config) bool { - _, ok := llndkLibraries(config)[baseModuleName] + _, ok := llndkLibraries(config)[strings.TrimSuffix(baseModuleName, llndkLibrarySuffix)] return ok } @@ -290,8 +290,8 @@ func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendor func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { lib := m.linker.(*llndkStubDecorator) - name := m.BaseModuleName() - filename := m.BaseModuleName() + ".so" + name := m.ImplementationModuleName(mctx) + filename := name + ".so" vndkLibrariesLock.Lock() defer vndkLibrariesLock.Unlock() @@ -834,8 +834,8 @@ func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) { if m, ok := module.(*Module); ok { if llndk, ok := m.linker.(*llndkStubDecorator); ok { // Skip bionic libs, they are handled in different manner - name := m.BaseModuleName() - if llndk.movedToApex && !isBionic(m.BaseModuleName()) { + name := llndk.implementationModuleName(m.BaseModuleName()) + if llndk.movedToApex && !isBionic(name) { movedToApexLlndkLibraries[name] = true } } diff --git a/sysprop/sysprop_test.go b/sysprop/sysprop_test.go index 711129c84..c8b16cb62 100644 --- a/sysprop/sysprop_test.go +++ b/sysprop/sysprop_test.go @@ -268,6 +268,7 @@ func TestSyspropLibrary(t *testing.T) { system_shared_libs: [], recovery_available: true, host_supported: true, + llndk_stubs: "liblog.llndk", } cc_binary_host { @@ -276,7 +277,7 @@ func TestSyspropLibrary(t *testing.T) { } llndk_library { - name: "liblog", + name: "liblog.llndk", symbol_file: "", }