versioning macro is exported from prebuilt stubs as well

This change fixes a bug that the versioning macro (__LIBNAME_API__) is
omitted for prebuilts providing a stub.

Bug: 175166063
Test: m nothing

Change-Id: I1cce5ab58ef245622861200ec0d8b0f84e3178ed
This commit is contained in:
Jiyong Park 2020-12-14 09:20:00 +09:00
parent f7c3bbe433
commit 892a98f0a3
3 changed files with 22 additions and 3 deletions

View File

@ -6559,6 +6559,11 @@ func TestPrebuiltStubLibDep(t *testing.T) {
if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil { if entry.mkEntries.EntryMap["LOCAL_NOT_AVAILABLE_FOR_PLATFORM"] != nil {
t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries) t.Errorf("AndroidMk entry for \"stublib\" has LOCAL_NOT_AVAILABLE_FOR_PLATFORM set: %+v", entry.mkEntries)
} }
cflags := entry.mkEntries.EntryMap["LOCAL_EXPORT_CFLAGS"]
expected := "-D__STUBLIB_API__=1"
if !android.InList(expected, cflags) {
t.Errorf("LOCAL_EXPORT_CFLAGS expected to have %q, but got %q", expected, cflags)
}
} }
}) })
} }

View File

@ -1274,9 +1274,7 @@ func (library *libraryDecorator) link(ctx ModuleContext,
} }
// Add stub-related flags if this library is a stub library. // Add stub-related flags if this library is a stub library.
if library.buildStubs() && !library.skipAPIDefine { library.exportVersioningMacroIfNeeded(ctx)
library.reexportFlags("-D" + versioningMacroName(ctx.Module().(*Module).ImplementationModuleName(ctx)) + "=" + library.stubsVersion())
}
// Propagate a Provider containing information about exported flags, deps, and include paths. // Propagate a Provider containing information about exported flags, deps, and include paths.
library.flagExporter.setProvider(ctx) library.flagExporter.setProvider(ctx)
@ -1284,6 +1282,14 @@ func (library *libraryDecorator) link(ctx ModuleContext,
return out return out
} }
func (library *libraryDecorator) exportVersioningMacroIfNeeded(ctx android.BaseModuleContext) {
if library.buildStubs() && !library.skipAPIDefine {
name := versioningMacroName(ctx.Module().(*Module).ImplementationModuleName(ctx))
ver := library.stubsVersion()
library.reexportFlags("-D" + name + "=" + ver)
}
}
// buildStatic returns true if this library should be built as a static library. // buildStatic returns true if this library should be built as a static library.
func (library *libraryDecorator) buildStatic() bool { func (library *libraryDecorator) buildStatic() bool {
return library.MutatedProperties.BuildStatic && return library.MutatedProperties.BuildStatic &&

View File

@ -17,6 +17,7 @@ package cc
import ( import (
"android/soong/android" "android/soong/android"
"path/filepath" "path/filepath"
"strings"
) )
func init() { func init() {
@ -117,6 +118,8 @@ func (p *prebuiltLibraryLinker) link(ctx ModuleContext,
return nil return nil
} }
p.libraryDecorator.exportVersioningMacroIfNeeded(ctx)
in := android.PathForModuleSrc(ctx, srcs[0]) in := android.PathForModuleSrc(ctx, srcs[0])
if p.static() { if p.static() {
@ -220,6 +223,11 @@ func (p *prebuiltLibraryLinker) disablePrebuilt() {
p.properties.Srcs = nil p.properties.Srcs = nil
} }
// Implements versionedInterface
func (p *prebuiltLibraryLinker) implementationModuleName(name string) string {
return strings.TrimPrefix(name, "prebuilt_")
}
func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) { func NewPrebuiltLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
module, library := NewLibrary(hod) module, library := NewLibrary(hod)
module.compiler = nil module.compiler = nil