Merge "Set __<libname>_API__ macro when building against stubs"
am: 1a583e7eef
Change-Id: I05d4d003af70ac7dffcadfe5d72c0b89c45f52ab
This commit is contained in:
@@ -1738,13 +1738,16 @@ func TestVersionedStubs(t *testing.T) {
|
|||||||
ctx := testCc(t, `
|
ctx := testCc(t, `
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "libFoo",
|
name: "libFoo",
|
||||||
|
srcs: ["foo.c"],
|
||||||
stubs: {
|
stubs: {
|
||||||
symbol_file: "foo.map.txt",
|
symbol_file: "foo.map.txt",
|
||||||
versions: ["1", "2", "3"],
|
versions: ["1", "2", "3"],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cc_library_shared {
|
cc_library_shared {
|
||||||
name: "libBar",
|
name: "libBar",
|
||||||
|
srcs: ["bar.c"],
|
||||||
shared_libs: ["libFoo#1"],
|
shared_libs: ["libFoo#1"],
|
||||||
}`)
|
}`)
|
||||||
|
|
||||||
@@ -1786,4 +1789,11 @@ func TestVersionedStubs(t *testing.T) {
|
|||||||
if !strings.Contains(libFlags, libFoo1StubPath) {
|
if !strings.Contains(libFlags, libFoo1StubPath) {
|
||||||
t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
|
t.Errorf("%q is not found in %q", libFoo1StubPath, libFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
libBarCompileRule := ctx.ModuleForTests("libBar", "android_arm64_armv8-a_core_shared").Rule("cc")
|
||||||
|
cFlags := libBarCompileRule.Args["cFlags"]
|
||||||
|
libFoo1VersioningMacro := "-D__LIBFOO_API__=1"
|
||||||
|
if !strings.Contains(cFlags, libFoo1VersioningMacro) {
|
||||||
|
t.Errorf("%q is not found in %q", libFoo1VersioningMacro, cFlags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -15,7 +15,9 @@
|
|||||||
package cc
|
package cc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
"github.com/google/blueprint/pathtools"
|
"github.com/google/blueprint/pathtools"
|
||||||
@@ -443,6 +445,8 @@ func (library *libraryDecorator) getLibName(ctx ModuleContext) string {
|
|||||||
return name + library.MutatedProperties.VariantName
|
return name + library.MutatedProperties.VariantName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var versioningMacroNamesListMutex sync.Mutex
|
||||||
|
|
||||||
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
||||||
location := InstallInSystem
|
location := InstallInSystem
|
||||||
if library.baseLinker.sanitize.inSanitizerDir() {
|
if library.baseLinker.sanitize.inSanitizerDir() {
|
||||||
@@ -453,6 +457,18 @@ func (library *libraryDecorator) linkerInit(ctx BaseModuleContext) {
|
|||||||
// Let baseLinker know whether this variant is for stubs or not, so that
|
// Let baseLinker know whether this variant is for stubs or not, so that
|
||||||
// it can omit things that are not required for linking stubs.
|
// it can omit things that are not required for linking stubs.
|
||||||
library.baseLinker.dynamicProperties.BuildStubs = library.buildStubs()
|
library.baseLinker.dynamicProperties.BuildStubs = library.buildStubs()
|
||||||
|
|
||||||
|
if library.buildStubs() {
|
||||||
|
macroNames := versioningMacroNamesList(ctx.Config())
|
||||||
|
myName := versioningMacroName(ctx.ModuleName())
|
||||||
|
versioningMacroNamesListMutex.Lock()
|
||||||
|
defer versioningMacroNamesListMutex.Unlock()
|
||||||
|
if (*macroNames)[myName] == "" {
|
||||||
|
(*macroNames)[myName] = ctx.ModuleName()
|
||||||
|
} else if (*macroNames)[myName] != ctx.ModuleName() {
|
||||||
|
ctx.ModuleErrorf("Macro name %q for versioning conflicts with macro name from module %q ", myName, (*macroNames)[myName])
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
func (library *libraryDecorator) linkerDeps(ctx DepsContext, deps Deps) Deps {
|
||||||
@@ -715,6 +731,10 @@ func (library *libraryDecorator) link(ctx ModuleContext,
|
|||||||
library.reuseExportedFlags = append(library.reuseExportedFlags, flags...)
|
library.reuseExportedFlags = append(library.reuseExportedFlags, flags...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if library.buildStubs() {
|
||||||
|
library.reexportFlags([]string{"-D" + versioningMacroName(ctx.ModuleName()) + "=" + library.stubsVersion()})
|
||||||
|
}
|
||||||
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -823,6 +843,23 @@ func (library *libraryDecorator) stubsVersion() string {
|
|||||||
return library.MutatedProperties.StubsVersion
|
return library.MutatedProperties.StubsVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func versioningMacroNamesList(config android.Config) *map[string]string {
|
||||||
|
return config.Once("versioningMacroNamesList", func() interface{} {
|
||||||
|
m := make(map[string]string)
|
||||||
|
return &m
|
||||||
|
}).(*map[string]string)
|
||||||
|
}
|
||||||
|
|
||||||
|
// alphanumeric and _ characters are preserved.
|
||||||
|
// other characters are all converted to _
|
||||||
|
var charsNotForMacro = regexp.MustCompile("[^a-zA-Z0-9_]+")
|
||||||
|
|
||||||
|
func versioningMacroName(moduleName string) string {
|
||||||
|
macroName := charsNotForMacro.ReplaceAllString(moduleName, "_")
|
||||||
|
macroName = strings.ToUpper(moduleName)
|
||||||
|
return "__" + macroName + "_API__"
|
||||||
|
}
|
||||||
|
|
||||||
func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
func NewLibrary(hod android.HostOrDeviceSupported) (*Module, *libraryDecorator) {
|
||||||
module := newModule(hod, android.MultilibBoth)
|
module := newModule(hod, android.MultilibBoth)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user