Merge "Add llndk_stubs property" am: ed5dee0a8f am: b078a156c3

Original change: https://android-review.googlesource.com/c/platform/build/soong/+/1466665

Change-Id: Idde55e7bc5f4f44f602f46fce6b495905d5d0e18
This commit is contained in:
Colin Cross
2020-10-23 19:24:44 +00:00
committed by Automerger Merge Worker
12 changed files with 91 additions and 30 deletions

View File

@@ -72,6 +72,7 @@ type AndroidMkEntriesProvider interface {
type AndroidMkEntries struct { type AndroidMkEntries struct {
Class string Class string
SubName string SubName string
OverrideName string
DistFiles TaggedDistFiles DistFiles TaggedDistFiles
OutputFile OptionalPath OutputFile OptionalPath
Disabled bool Disabled bool
@@ -273,6 +274,9 @@ func (a *AndroidMkEntries) fillInEntries(config Config, bpPath string, mod bluep
a.EntryMap = make(map[string][]string) a.EntryMap = make(map[string][]string)
amod := mod.(Module).base() amod := mod.(Module).base()
name := amod.BaseModuleName() name := amod.BaseModuleName()
if a.OverrideName != "" {
name = a.OverrideName
}
if a.Include == "" { if a.Include == "" {
a.Include = "$(BUILD_PREBUILT)" a.Include = "$(BUILD_PREBUILT)"

View File

@@ -2383,11 +2383,12 @@ func (a *apexBundle) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// system libraries. // system libraries.
if !am.DirectlyInAnyApex() { if !am.DirectlyInAnyApex() {
// we need a module name for Make // we need a module name for Make
name := cc.BaseModuleName() + cc.Properties.SubName name := cc.ImplementationModuleName(ctx)
if proptools.Bool(a.properties.Use_vendor) {
if !proptools.Bool(a.properties.Use_vendor) {
// we don't use subName(.vendor) for a "use_vendor: true" apex // we don't use subName(.vendor) for a "use_vendor: true" apex
// which is supposed to be installed in /system // which is supposed to be installed in /system
name = cc.BaseModuleName() name += cc.Properties.SubName
} }
if !android.InList(name, a.requiredDeps) { if !android.InList(name, a.requiredDeps) {
a.requiredDeps = append(a.requiredDeps, name) a.requiredDeps = append(a.requiredDeps, name)

View File

@@ -1270,10 +1270,11 @@ func TestApexDependsOnLLNDKTransitively(t *testing.T) {
system_shared_libs: [], system_shared_libs: [],
stl: "none", stl: "none",
stubs: { versions: ["29","30"] }, stubs: { versions: ["29","30"] },
llndk_stubs: "libbar.llndk",
} }
llndk_library { llndk_library {
name: "libbar", name: "libbar.llndk",
symbol_file: "", symbol_file: "",
} }
`, func(fs map[string][]byte, config android.Config) { `, func(fs map[string][]byte, config android.Config) {

View File

@@ -33,6 +33,7 @@ var (
) )
type AndroidMkContext interface { type AndroidMkContext interface {
BaseModuleName() string
Target() android.Target Target() android.Target
subAndroidMk(*android.AndroidMkEntries, interface{}) subAndroidMk(*android.AndroidMkEntries, interface{})
Arch() android.Arch Arch() android.Arch
@@ -463,6 +464,7 @@ func (c *stubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.
func (c *llndkStubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) { func (c *llndkStubDecorator) AndroidMkEntries(ctx AndroidMkContext, entries *android.AndroidMkEntries) {
entries.Class = "SHARED_LIBRARIES" entries.Class = "SHARED_LIBRARIES"
entries.OverrideName = c.implementationModuleName(ctx.BaseModuleName())
entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) { entries.ExtraEntries = append(entries.ExtraEntries, func(entries *android.AndroidMkEntries) {
c.libraryDecorator.androidMkWriteExportedFlags(entries) c.libraryDecorator.androidMkWriteExportedFlags(entries)

View File

@@ -1041,6 +1041,16 @@ func (c *Module) HasStubsVariants() bool {
return false 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 { func (c *Module) bootstrap() bool {
return Bool(c.Properties.Bootstrap) return Bool(c.Properties.Bootstrap)
} }

View File

@@ -850,10 +850,11 @@ func TestDoubleLoadbleDep(t *testing.T) {
cc_library { cc_library {
name: "libllndk", name: "libllndk",
shared_libs: ["libdoubleloadable"], shared_libs: ["libdoubleloadable"],
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
@@ -871,10 +872,11 @@ func TestDoubleLoadbleDep(t *testing.T) {
cc_library { cc_library {
name: "libllndk", name: "libllndk",
shared_libs: ["libvndksp"], shared_libs: ["libvndksp"],
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
@@ -928,10 +930,11 @@ func TestDoubleLoadbleDep(t *testing.T) {
cc_library { cc_library {
name: "libllndk", name: "libllndk",
shared_libs: ["libcoreonly"], shared_libs: ["libcoreonly"],
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
@@ -1552,10 +1555,11 @@ func TestDoubleLoadableDepError(t *testing.T) {
cc_library { cc_library {
name: "libllndk", name: "libllndk",
shared_libs: ["libnondoubleloadable"], shared_libs: ["libnondoubleloadable"],
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
@@ -1574,10 +1578,11 @@ func TestDoubleLoadableDepError(t *testing.T) {
name: "libllndk", name: "libllndk",
no_libcrt: true, no_libcrt: true,
shared_libs: ["libnondoubleloadable"], shared_libs: ["libnondoubleloadable"],
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
@@ -1646,10 +1651,11 @@ func TestDoubleLoadableDepError(t *testing.T) {
cc_library { cc_library {
name: "libllndk", name: "libllndk",
shared_libs: ["libcoreonly"], shared_libs: ["libcoreonly"],
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
@@ -2419,9 +2425,10 @@ func TestEnforceProductVndkVersion(t *testing.T) {
bp := ` bp := `
cc_library { cc_library {
name: "libllndk", name: "libllndk",
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
cc_library { cc_library {
@@ -2622,16 +2629,18 @@ func TestMakeLinkType(t *testing.T) {
} }
cc_library { cc_library {
name: "libllndk", name: "libllndk",
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
symbol_file: "", symbol_file: "",
} }
cc_library { cc_library {
name: "libllndkprivate", name: "libllndkprivate",
llndk_stubs: "libllndkprivate.llndk",
} }
llndk_library { llndk_library {
name: "libllndkprivate", name: "libllndkprivate.llndk",
vendor_available: false, vendor_available: false,
symbol_file: "", symbol_file: "",
}` }`
@@ -3045,9 +3054,10 @@ func TestLlndkLibrary(t *testing.T) {
cc_library { cc_library {
name: "libllndk", name: "libllndk",
stubs: { versions: ["1", "2"] }, stubs: { versions: ["1", "2"] },
llndk_stubs: "libllndk.llndk",
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
} }
`) `)
actual := ctx.ModuleVariantsForTests("libllndk.llndk") actual := ctx.ModuleVariantsForTests("libllndk.llndk")
@@ -3075,9 +3085,14 @@ func TestLlndkHeaders(t *testing.T) {
export_include_dirs: ["my_include"], export_include_dirs: ["my_include"],
} }
llndk_library { llndk_library {
name: "libllndk", name: "libllndk.llndk",
export_llndk_headers: ["libllndk_headers"], export_llndk_headers: ["libllndk_headers"],
} }
cc_library {
name: "libllndk",
llndk_stubs: "libllndk.llndk",
}
cc_library { cc_library {
name: "libvendor", name: "libvendor",
shared_libs: ["libllndk"], shared_libs: ["libllndk"],

View File

@@ -110,6 +110,9 @@ type LibraryProperties struct {
// Inject boringssl hash into the shared library. This is only intended for use by external/boringssl. // Inject boringssl hash into the shared library. This is only intended for use by external/boringssl.
Inject_bssl_hash *bool `android:"arch_variant"` 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 { type StaticProperties struct {
@@ -695,6 +698,8 @@ type versionedInterface interface {
stubsVersions(ctx android.BaseMutatorContext) []string stubsVersions(ctx android.BaseMutatorContext) []string
setAllStubsVersions([]string) setAllStubsVersions([]string)
allStubsVersions() []string allStubsVersions() []string
implementationModuleName(name string) string
} }
var _ libraryInterface = (*libraryDecorator)(nil) var _ libraryInterface = (*libraryDecorator)(nil)
@@ -1205,7 +1210,7 @@ func (library *libraryDecorator) link(ctx ModuleContext,
} }
if library.buildStubs() && !library.skipAPIDefine { 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) library.flagExporter.setProvider(ctx)
@@ -1359,6 +1364,10 @@ func (library *libraryDecorator) HeaderOnly() {
library.MutatedProperties.BuildStatic = false library.MutatedProperties.BuildStatic = false
} }
func (library *libraryDecorator) implementationModuleName(name string) string {
return name
}
func (library *libraryDecorator) buildStubs() bool { func (library *libraryDecorator) buildStubs() bool {
return library.MutatedProperties.BuildStubs return library.MutatedProperties.BuildStubs
} }

View File

@@ -72,6 +72,8 @@ type llndkStubDecorator struct {
movedToApex bool movedToApex bool
} }
var _ versionedInterface = (*llndkStubDecorator)(nil)
func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags { func (stub *llndkStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {
flags = stub.baseCompiler.compilerFlags(ctx, flags, deps) flags = stub.baseCompiler.compilerFlags(ctx, flags, deps)
return addStubLibraryCompilerFlags(flags) return addStubLibraryCompilerFlags(flags)
@@ -101,12 +103,14 @@ func (stub *llndkStubDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
} }
func (stub *llndkStubDecorator) Name(name string) string { func (stub *llndkStubDecorator) Name(name string) string {
if strings.HasSuffix(name, llndkLibrarySuffix) {
return name
}
return name + llndkLibrarySuffix return name + llndkLibrarySuffix
} }
func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags { func (stub *llndkStubDecorator) linkerFlags(ctx ModuleContext, flags Flags) Flags {
stub.libraryDecorator.libName = strings.TrimSuffix(ctx.ModuleName(), stub.libraryDecorator.libName = stub.implementationModuleName(ctx.ModuleName())
llndkLibrarySuffix)
return stub.libraryDecorator.linkerFlags(ctx, flags) 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, func (stub *llndkStubDecorator) link(ctx ModuleContext, flags Flags, deps PathDeps,
objs Objects) android.Path { 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 { if implApexModule, ok := impl.(android.ApexModule); ok {
stub.movedToApex = implApexModule.DirectlyInAnyApex() stub.movedToApex = implApexModule.DirectlyInAnyApex()
} }
@@ -167,6 +171,10 @@ func (stub *llndkStubDecorator) nativeCoverage() bool {
return false return false
} }
func (stub *llndkStubDecorator) implementationModuleName(name string) string {
return strings.TrimSuffix(name, llndkLibrarySuffix)
}
func (stub *llndkStubDecorator) buildStubs() bool { func (stub *llndkStubDecorator) buildStubs() bool {
return true return true
} }

View File

@@ -100,10 +100,16 @@ type stubDecorator struct {
unversionedUntil android.ApiLevel unversionedUntil android.ApiLevel
} }
var _ versionedInterface = (*stubDecorator)(nil)
func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool { func shouldUseVersionScript(ctx BaseModuleContext, stub *stubDecorator) bool {
return stub.apiLevel.GreaterThanOrEqualTo(stub.unversionedUntil) 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 { func ndkLibraryVersions(ctx android.BaseMutatorContext, from android.ApiLevel) []string {
var versions []android.ApiLevel var versions []android.ApiLevel
versionStrs := []string{} versionStrs := []string{}

View File

@@ -172,9 +172,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string {
stubs: { stubs: {
versions: ["27", "28", "29"], versions: ["27", "28", "29"],
}, },
} llndk_stubs: "libc.llndk",
}
llndk_library { llndk_library {
name: "libc", name: "libc.llndk",
symbol_file: "", symbol_file: "",
sdk_version: "current", sdk_version: "current",
} }
@@ -193,9 +194,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string {
"//apex_available:platform", "//apex_available:platform",
"myapex" "myapex"
], ],
llndk_stubs: "libm.llndk",
} }
llndk_library { llndk_library {
name: "libm", name: "libm.llndk",
symbol_file: "", symbol_file: "",
sdk_version: "current", sdk_version: "current",
} }
@@ -253,9 +255,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string {
"//apex_available:platform", "//apex_available:platform",
"myapex" "myapex"
], ],
llndk_stubs: "libdl.llndk",
} }
llndk_library { llndk_library {
name: "libdl", name: "libdl.llndk",
symbol_file: "", symbol_file: "",
sdk_version: "current", sdk_version: "current",
} }
@@ -265,9 +268,10 @@ func GatherRequiredDepsForTest(oses ...android.OsType) string {
nocrt: true, nocrt: true,
system_shared_libs: [], system_shared_libs: [],
recovery_available: true, recovery_available: true,
llndk_stubs: "libft2.llndk",
} }
llndk_library { llndk_library {
name: "libft2", name: "libft2.llndk",
symbol_file: "", symbol_file: "",
vendor_available: false, vendor_available: false,
sdk_version: "current", sdk_version: "current",

View File

@@ -247,7 +247,7 @@ func vndkSpLibraries(config android.Config) map[string]string {
} }
func isLlndkLibrary(baseModuleName string, config android.Config) bool { func isLlndkLibrary(baseModuleName string, config android.Config) bool {
_, ok := llndkLibraries(config)[baseModuleName] _, ok := llndkLibraries(config)[strings.TrimSuffix(baseModuleName, llndkLibrarySuffix)]
return ok return ok
} }
@@ -290,8 +290,8 @@ func setVndkMustUseVendorVariantListForTest(config android.Config, mustUseVendor
func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) { func processLlndkLibrary(mctx android.BottomUpMutatorContext, m *Module) {
lib := m.linker.(*llndkStubDecorator) lib := m.linker.(*llndkStubDecorator)
name := m.BaseModuleName() name := m.ImplementationModuleName(mctx)
filename := m.BaseModuleName() + ".so" filename := name + ".so"
vndkLibrariesLock.Lock() vndkLibrariesLock.Lock()
defer vndkLibrariesLock.Unlock() defer vndkLibrariesLock.Unlock()
@@ -837,8 +837,8 @@ func (c *vndkSnapshotSingleton) MakeVars(ctx android.MakeVarsContext) {
if m, ok := module.(*Module); ok { if m, ok := module.(*Module); ok {
if llndk, ok := m.linker.(*llndkStubDecorator); ok { if llndk, ok := m.linker.(*llndkStubDecorator); ok {
// Skip bionic libs, they are handled in different manner // Skip bionic libs, they are handled in different manner
name := m.BaseModuleName() name := llndk.implementationModuleName(m.BaseModuleName())
if llndk.movedToApex && !isBionic(m.BaseModuleName()) { if llndk.movedToApex && !isBionic(name) {
movedToApexLlndkLibraries[name] = true movedToApexLlndkLibraries[name] = true
} }
} }

View File

@@ -277,6 +277,7 @@ func TestSyspropLibrary(t *testing.T) {
system_shared_libs: [], system_shared_libs: [],
recovery_available: true, recovery_available: true,
host_supported: true, host_supported: true,
llndk_stubs: "liblog.llndk",
} }
cc_binary_host { cc_binary_host {
@@ -285,7 +286,7 @@ func TestSyspropLibrary(t *testing.T) {
} }
llndk_library { llndk_library {
name: "liblog", name: "liblog.llndk",
symbol_file: "", symbol_file: "",
} }