Merge "Attach global variables to Context" am: a1591ab08c

am: 66c5cac22b

Change-Id: Icaf7aa78580459fd76605ec66b5bbaac13a30c9e
This commit is contained in:
Inseob Kim 2019-05-09 19:42:18 -07:00 committed by android-build-merger
commit c012b19eb0
8 changed files with 130 additions and 68 deletions

View file

@ -86,7 +86,7 @@ func (c *Module) AndroidMk() android.AndroidMkData {
if len(c.Properties.AndroidMkWholeStaticLibs) > 0 {
fmt.Fprintln(w, "LOCAL_WHOLE_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkWholeStaticLibs, " "))
}
fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.getMakeLinkType())
fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.makeLinkType)
if c.useVndk() {
fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
}

View file

@ -246,14 +246,14 @@ type ModuleContextIntf interface {
sdkVersion() string
useVndk() bool
isNdk() bool
isLlndk() bool
isLlndkPublic() bool
isVndkPrivate() bool
isLlndk(config android.Config) bool
isLlndkPublic(config android.Config) bool
isVndkPrivate(config android.Config) bool
isVndk() bool
isVndkSp() bool
isVndkExt() bool
inRecovery() bool
shouldCreateVndkSourceAbiDump() bool
shouldCreateVndkSourceAbiDump(config android.Config) bool
selectedStl() string
baseModuleName() string
getVndkExtendsModuleName() string
@ -408,6 +408,8 @@ type Module struct {
// only non-nil when this is a shared library that reuses the objects of a static library
staticVariant *Module
makeLinkType string
}
func (c *Module) OutputFile() android.OptionalPath {
@ -510,19 +512,19 @@ func (c *Module) isNdk() bool {
return inList(c.Name(), ndkMigratedLibs)
}
func (c *Module) isLlndk() bool {
func (c *Module) isLlndk(config android.Config) bool {
// Returns true for both LLNDK (public) and LLNDK-private libs.
return inList(c.Name(), llndkLibraries)
return inList(c.Name(), *llndkLibraries(config))
}
func (c *Module) isLlndkPublic() bool {
func (c *Module) isLlndkPublic(config android.Config) bool {
// Returns true only for LLNDK (public) libs.
return c.isLlndk() && !c.isVndkPrivate()
return c.isLlndk(config) && !c.isVndkPrivate(config)
}
func (c *Module) isVndkPrivate() bool {
func (c *Module) isVndkPrivate(config android.Config) bool {
// Returns true for LLNDK-private, VNDK-SP-private, and VNDK-core-private.
return inList(c.Name(), vndkPrivateLibraries)
return inList(c.Name(), *vndkPrivateLibraries(config))
}
func (c *Module) isVndk() bool {
@ -687,16 +689,16 @@ func (ctx *moduleContextImpl) isNdk() bool {
return ctx.mod.isNdk()
}
func (ctx *moduleContextImpl) isLlndk() bool {
return ctx.mod.isLlndk()
func (ctx *moduleContextImpl) isLlndk(config android.Config) bool {
return ctx.mod.isLlndk(config)
}
func (ctx *moduleContextImpl) isLlndkPublic() bool {
return ctx.mod.isLlndkPublic()
func (ctx *moduleContextImpl) isLlndkPublic(config android.Config) bool {
return ctx.mod.isLlndkPublic(config)
}
func (ctx *moduleContextImpl) isVndkPrivate() bool {
return ctx.mod.isVndkPrivate()
func (ctx *moduleContextImpl) isVndkPrivate(config android.Config) bool {
return ctx.mod.isVndkPrivate(config)
}
func (ctx *moduleContextImpl) isVndk() bool {
@ -728,7 +730,7 @@ func (ctx *moduleContextImpl) inRecovery() bool {
}
// Check whether ABI dumps should be created for this module.
func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump(config android.Config) bool {
if ctx.ctx.Config().IsEnvTrue("SKIP_ABI_CHECKS") {
return false
}
@ -753,10 +755,10 @@ func (ctx *moduleContextImpl) shouldCreateVndkSourceAbiDump() bool {
if ctx.isNdk() {
return true
}
if ctx.isLlndkPublic() {
if ctx.isLlndkPublic(config) {
return true
}
if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate() {
if ctx.useVndk() && ctx.isVndk() && !ctx.isVndkPrivate(config) {
// Return true if this is VNDK-core, VNDK-SP, or VNDK-Ext and this is not
// VNDK-private.
return true
@ -907,6 +909,8 @@ func orderStaticModuleDeps(module *Module, staticDeps []*Module, sharedDeps []*M
}
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
c.makeLinkType = c.getMakeLinkType(actx.Config())
ctx := &moduleContext{
ModuleContext: actx,
moduleContextImpl: moduleContextImpl{
@ -1186,6 +1190,9 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
//
// The caller can then know to add the variantLibs dependencies differently from the
// nonvariantLibs
llndkLibraries := llndkLibraries(actx.Config())
vendorPublicLibraries := vendorPublicLibraries(actx.Config())
rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) {
variantLibs = []string{}
nonvariantLibs = []string{}
@ -1198,9 +1205,9 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
} else {
variantLibs = append(variantLibs, name+ndkLibrarySuffix)
}
} else if ctx.useVndk() && inList(name, llndkLibraries) {
} else if ctx.useVndk() && inList(name, *llndkLibraries) {
nonvariantLibs = append(nonvariantLibs, name+llndkLibrarySuffix)
} else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, vendorPublicLibraries) {
} else if (ctx.Platform() || ctx.ProductSpecific()) && inList(name, *vendorPublicLibraries) {
vendorPublicLib := name + vendorPublicLibrarySuffix
if actx.OtherModuleExists(vendorPublicLib) {
nonvariantLibs = append(nonvariantLibs, vendorPublicLib)
@ -1501,6 +1508,7 @@ func checkLinkType(ctx android.ModuleContext, from *Module, to *Module, tag depe
// it is subject to be double loaded. Such lib should be explicitly marked as double_loadable: true
// or as vndk-sp (vndk: { enabled: true, support_system_process: true}).
func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
llndkLibraries := llndkLibraries(ctx.Config())
check := func(child, parent android.Module) bool {
to, ok := child.(*Module)
if !ok {
@ -1517,7 +1525,7 @@ func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
return true
}
if to.isVndkSp() || inList(child.Name(), llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
if to.isVndkSp() || inList(child.Name(), *llndkLibraries) || Bool(to.VendorProperties.Double_loadable) {
return false
}
@ -1532,7 +1540,7 @@ func checkDoubleLoadableLibraries(ctx android.TopDownMutatorContext) {
}
if module, ok := ctx.Module().(*Module); ok {
if lib, ok := module.linker.(*libraryDecorator); ok && lib.shared() {
if inList(ctx.ModuleName(), llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
if inList(ctx.ModuleName(), *llndkLibraries) || Bool(module.VendorProperties.Double_loadable) {
ctx.WalkDeps(check)
}
}
@ -1546,6 +1554,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
directStaticDeps := []*Module{}
directSharedDeps := []*Module{}
llndkLibraries := llndkLibraries(ctx.Config())
vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
ctx.VisitDirectDeps(func(dep android.Module) {
depName := ctx.OtherModuleName(dep)
depTag := ctx.OtherModuleDependencyTag(dep)
@ -1788,8 +1799,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
libName := strings.TrimSuffix(depName, llndkLibrarySuffix)
libName = strings.TrimSuffix(libName, vendorPublicLibrarySuffix)
libName = strings.TrimPrefix(libName, "prebuilt_")
isLLndk := inList(libName, llndkLibraries)
isVendorPublicLib := inList(libName, vendorPublicLibraries)
isLLndk := inList(libName, *llndkLibraries)
isVendorPublicLib := inList(libName, *vendorPublicLibraries)
bothVendorAndCoreVariantsExist := ccDep.hasVendorVariant() || isLLndk
if ctx.DeviceConfig().VndkUseCoreVariant() && ccDep.isVndk() && !ccDep.mustUseVendorVariant() {
@ -1919,10 +1930,12 @@ func (c *Module) staticBinary() bool {
return false
}
func (c *Module) getMakeLinkType() string {
func (c *Module) getMakeLinkType(config android.Config) string {
if c.useVndk() {
if inList(c.Name(), vndkCoreLibraries) || inList(c.Name(), vndkSpLibraries) || inList(c.Name(), llndkLibraries) {
if inList(c.Name(), vndkPrivateLibraries) {
if inList(c.Name(), *vndkCoreLibraries(config)) ||
inList(c.Name(), *vndkSpLibraries(config)) ||
inList(c.Name(), *llndkLibraries(config)) {
if inList(c.Name(), *vndkPrivateLibraries(config)) {
return "native:vndk_private"
} else {
return "native:vndk"
@ -1937,7 +1950,7 @@ func (c *Module) getMakeLinkType() string {
// TODO(b/114741097): use the correct ndk stl once build errors have been fixed
//family, link := getNdkStlFamilyAndLinkType(c)
//return fmt.Sprintf("native:ndk:%s:%s", family, link)
} else if inList(c.Name(), vndkUsingCoreVariantLibraries) {
} else if inList(c.Name(), *vndkUsingCoreVariantLibraries(config)) {
return "native:platform_vndk"
} else {
return "native:platform"

View file

@ -429,7 +429,7 @@ func (library *libraryDecorator) shouldCreateVndkSourceAbiDump(ctx ModuleContext
if library.Properties.Header_abi_checker.Enabled != nil {
return Bool(library.Properties.Header_abi_checker.Enabled)
}
return ctx.shouldCreateVndkSourceAbiDump()
return ctx.shouldCreateVndkSourceAbiDump(ctx.Config())
}
func (library *libraryDecorator) compile(ctx ModuleContext, flags Flags, deps PathDeps) Objects {
@ -783,7 +783,7 @@ func (library *libraryDecorator) nativeCoverage() bool {
}
func getRefAbiDumpFile(ctx ModuleContext, vndkVersion, fileName string) android.Path {
isLlndkOrNdk := inList(ctx.baseModuleName(), llndkLibraries) || inList(ctx.baseModuleName(), ndkMigratedLibs)
isLlndkOrNdk := inList(ctx.baseModuleName(), *llndkLibraries(ctx.Config())) || inList(ctx.baseModuleName(), ndkMigratedLibs)
refAbiDumpTextFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isLlndkOrNdk, ctx.isVndk(), false)
refAbiDumpGzipFile := android.PathForVndkRefAbiDump(ctx, vndkVersion, fileName, isLlndkOrNdk, ctx.isVndk(), true)
@ -827,7 +827,7 @@ func (library *libraryDecorator) linkSAbiDumpFiles(ctx ModuleContext, objs Objec
refAbiDumpFile := getRefAbiDumpFile(ctx, vndkVersion, fileName)
if refAbiDumpFile != nil {
library.sAbiDiff = SourceAbiDiff(ctx, library.sAbiOutputFile.Path(),
refAbiDumpFile, fileName, exportedHeaderFlags, ctx.isLlndk(), ctx.isNdk(), ctx.isVndkExt())
refAbiDumpFile, fileName, exportedHeaderFlags, ctx.isLlndk(ctx.Config()), ctx.isNdk(), ctx.isVndkExt())
}
}
}

View file

@ -64,6 +64,8 @@ func makeStringOfWarningAllowedProjects() string {
}
func makeVarsProvider(ctx android.MakeVarsContext) {
vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
ctx.Strict("LLVM_RELEASE_VERSION", "${config.ClangShortVersion}")
ctx.Strict("LLVM_PREBUILTS_VERSION", "${config.ClangVersion}")
ctx.Strict("LLVM_PREBUILTS_BASE", "${config.ClangBase}")
@ -92,18 +94,18 @@ func makeVarsProvider(ctx android.MakeVarsContext) {
ctx.Strict("BOARD_VNDK_VERSION", ctx.DeviceConfig().VndkVersion())
ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(vndkCoreLibraries, " "))
ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(vndkSpLibraries, " "))
ctx.Strict("LLNDK_LIBRARIES", strings.Join(llndkLibraries, " "))
ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(vndkPrivateLibraries, " "))
ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(vndkUsingCoreVariantLibraries, " "))
ctx.Strict("VNDK_CORE_LIBRARIES", strings.Join(*vndkCoreLibraries(ctx.Config()), " "))
ctx.Strict("VNDK_SAMEPROCESS_LIBRARIES", strings.Join(*vndkSpLibraries(ctx.Config()), " "))
ctx.Strict("LLNDK_LIBRARIES", strings.Join(*llndkLibraries(ctx.Config()), " "))
ctx.Strict("VNDK_PRIVATE_LIBRARIES", strings.Join(*vndkPrivateLibraries(ctx.Config()), " "))
ctx.Strict("VNDK_USING_CORE_VARIANT_LIBRARIES", strings.Join(*vndkUsingCoreVariantLibraries(ctx.Config()), " "))
// Filter vendor_public_library that are exported to make
exportedVendorPublicLibraries := []string{}
ctx.VisitAllModules(func(module android.Module) {
if ccModule, ok := module.(*Module); ok {
baseName := ccModule.BaseModuleName()
if inList(baseName, vendorPublicLibraries) && module.ExportedToMake() {
if inList(baseName, *vendorPublicLibraries) && module.ExportedToMake() {
if !inList(baseName, exportedVendorPublicLibraries) {
exportedVendorPublicLibraries = append(exportedVendorPublicLibraries, baseName)
}

View file

@ -78,7 +78,7 @@ func (sabimod *sabi) flags(ctx ModuleContext, flags Flags) Flags {
func sabiDepsMutator(mctx android.TopDownMutatorContext) {
if c, ok := mctx.Module().(*Module); ok &&
((c.isVndk() && c.useVndk()) || inList(c.Name(), llndkLibraries) ||
((c.isVndk() && c.useVndk()) || inList(c.Name(), *llndkLibraries(mctx.Config())) ||
(c.sabi != nil && c.sabi.Properties.CreateSAbiDumps)) {
mctx.VisitDirectDeps(func(m android.Module) {
tag := mctx.OtherModuleDependencyTag(m)

View file

@ -817,7 +817,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
}
if mctx.Device() && runtimeLibrary != "" {
if inList(runtimeLibrary, llndkLibraries) && !c.static() && c.useVndk() {
if inList(runtimeLibrary, *llndkLibraries(mctx.Config())) && !c.static() && c.useVndk() {
runtimeLibrary = runtimeLibrary + llndkLibrarySuffix
}

View file

@ -24,10 +24,16 @@ import (
var (
vendorPublicLibrarySuffix = ".vendorpublic"
vendorPublicLibraries = []string{}
vendorPublicLibrariesKey = android.NewOnceKey("vendorPublicLibraries")
vendorPublicLibrariesLock sync.Mutex
)
func vendorPublicLibraries(config android.Config) *[]string {
return config.Once(vendorPublicLibrariesKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
// Creates a stub shared library for a vendor public library. Vendor public libraries
// are vendor libraries (owned by them and installed to /vendor partition) that are
// exposed to Android apps via JNI. The libraries are made public by being listed in
@ -82,12 +88,13 @@ func (stub *vendorPublicLibraryStubDecorator) compilerInit(ctx BaseModuleContext
vendorPublicLibrariesLock.Lock()
defer vendorPublicLibrariesLock.Unlock()
for _, lib := range vendorPublicLibraries {
vendorPublicLibraries := vendorPublicLibraries(ctx.Config())
for _, lib := range *vendorPublicLibraries {
if lib == name {
return
}
}
vendorPublicLibraries = append(vendorPublicLibraries, name)
*vendorPublicLibraries = append(*vendorPublicLibraries, name)
}
func (stub *vendorPublicLibraryStubDecorator) compilerFlags(ctx ModuleContext, flags Flags, deps PathDeps) Flags {

View file

@ -192,29 +192,63 @@ func vndkIsVndkDepAllowed(from *vndkdep, to *vndkdep) error {
}
var (
vndkCoreLibraries []string
vndkSpLibraries []string
llndkLibraries []string
vndkPrivateLibraries []string
vndkUsingCoreVariantLibraries []string
vndkLibrariesLock sync.Mutex
vndkCoreLibrariesKey = android.NewOnceKey("vndkCoreLibrarires")
vndkSpLibrariesKey = android.NewOnceKey("vndkSpLibrarires")
llndkLibrariesKey = android.NewOnceKey("llndkLibrarires")
vndkPrivateLibrariesKey = android.NewOnceKey("vndkPrivateLibrarires")
vndkUsingCoreVariantLibrariesKey = android.NewOnceKey("vndkUsingCoreVariantLibrarires")
vndkLibrariesLock sync.Mutex
)
func vndkCoreLibraries(config android.Config) *[]string {
return config.Once(vndkCoreLibrariesKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
func vndkSpLibraries(config android.Config) *[]string {
return config.Once(vndkSpLibrariesKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
func llndkLibraries(config android.Config) *[]string {
return config.Once(llndkLibrariesKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
func vndkPrivateLibraries(config android.Config) *[]string {
return config.Once(vndkPrivateLibrariesKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
func vndkUsingCoreVariantLibraries(config android.Config) *[]string {
return config.Once(vndkUsingCoreVariantLibrariesKey, func() interface{} {
return &[]string{}
}).(*[]string)
}
// gather list of vndk-core, vndk-sp, and ll-ndk libs
func VndkMutator(mctx android.BottomUpMutatorContext) {
if m, ok := mctx.Module().(*Module); ok && m.Enabled() {
if lib, ok := m.linker.(*llndkStubDecorator); ok {
vndkLibrariesLock.Lock()
defer vndkLibrariesLock.Unlock()
llndkLibraries := llndkLibraries(mctx.Config())
vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config())
name := strings.TrimSuffix(m.Name(), llndkLibrarySuffix)
if !inList(name, llndkLibraries) {
llndkLibraries = append(llndkLibraries, name)
sort.Strings(llndkLibraries)
if !inList(name, *llndkLibraries) {
*llndkLibraries = append(*llndkLibraries, name)
sort.Strings(*llndkLibraries)
}
if !Bool(lib.Properties.Vendor_available) {
if !inList(name, vndkPrivateLibraries) {
vndkPrivateLibraries = append(vndkPrivateLibraries, name)
sort.Strings(vndkPrivateLibraries)
if !inList(name, *vndkPrivateLibraries) {
*vndkPrivateLibraries = append(*vndkPrivateLibraries, name)
sort.Strings(*vndkPrivateLibraries)
}
}
} else {
@ -225,27 +259,33 @@ func VndkMutator(mctx android.BottomUpMutatorContext) {
if m.vndkdep.isVndk() && !m.vndkdep.isVndkExt() {
vndkLibrariesLock.Lock()
defer vndkLibrariesLock.Unlock()
vndkUsingCoreVariantLibraries := vndkUsingCoreVariantLibraries(mctx.Config())
vndkSpLibraries := vndkSpLibraries(mctx.Config())
vndkCoreLibraries := vndkCoreLibraries(mctx.Config())
vndkPrivateLibraries := vndkPrivateLibraries(mctx.Config())
if mctx.DeviceConfig().VndkUseCoreVariant() && !inList(name, config.VndkMustUseVendorVariantList) {
if !inList(name, vndkUsingCoreVariantLibraries) {
vndkUsingCoreVariantLibraries = append(vndkUsingCoreVariantLibraries, name)
sort.Strings(vndkUsingCoreVariantLibraries)
if !inList(name, *vndkUsingCoreVariantLibraries) {
*vndkUsingCoreVariantLibraries = append(*vndkUsingCoreVariantLibraries, name)
sort.Strings(*vndkUsingCoreVariantLibraries)
}
}
if m.vndkdep.isVndkSp() {
if !inList(name, vndkSpLibraries) {
vndkSpLibraries = append(vndkSpLibraries, name)
sort.Strings(vndkSpLibraries)
if !inList(name, *vndkSpLibraries) {
*vndkSpLibraries = append(*vndkSpLibraries, name)
sort.Strings(*vndkSpLibraries)
}
} else {
if !inList(name, vndkCoreLibraries) {
vndkCoreLibraries = append(vndkCoreLibraries, name)
sort.Strings(vndkCoreLibraries)
if !inList(name, *vndkCoreLibraries) {
*vndkCoreLibraries = append(*vndkCoreLibraries, name)
sort.Strings(*vndkCoreLibraries)
}
}
if !Bool(m.VendorProperties.Vendor_available) {
if !inList(name, vndkPrivateLibraries) {
vndkPrivateLibraries = append(vndkPrivateLibraries, name)
sort.Strings(vndkPrivateLibraries)
if !inList(name, *vndkPrivateLibraries) {
*vndkPrivateLibraries = append(*vndkPrivateLibraries, name)
sort.Strings(*vndkPrivateLibraries)
}
}
}