Merge "Revert "Some clarifications in preparation to automatically order linker dependencies""

This commit is contained in:
Jeff Gaston
2017-10-04 21:09:29 +00:00
committed by Gerrit Code Review
12 changed files with 189 additions and 197 deletions

View File

@@ -99,11 +99,7 @@ type ModuleContext interface {
type Module interface { type Module interface {
blueprint.Module blueprint.Module
// GenerateAndroidBuildActions is analogous to Blueprints' GenerateBuildActions,
// but GenerateAndroidBuildActions also has access to Android-specific information.
// For more information, see Module.GenerateBuildActions within Blueprint's module_ctx.go
GenerateAndroidBuildActions(ModuleContext) GenerateAndroidBuildActions(ModuleContext)
DepsMutator(BottomUpMutatorContext) DepsMutator(BottomUpMutatorContext)
base() *ModuleBase base() *ModuleBase

View File

@@ -18,13 +18,12 @@ import (
"github.com/google/blueprint" "github.com/google/blueprint"
) )
// Phases: // Mutator phases:
// run Pre-arch mutators // Pre-arch
// run archMutator // Arch
// run Pre-deps mutators // Pre-deps
// run depsMutator // Deps
// run PostDeps mutators // PostDeps
// continue on to GenerateAndroidBuildActions
func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) { func registerMutatorsToContext(ctx *blueprint.Context, mutators []*mutator) {
for _, t := range mutators { for _, t := range mutators {

View File

@@ -30,7 +30,7 @@ var (
type AndroidMkContext interface { type AndroidMkContext interface {
Target() android.Target Target() android.Target
subAndroidMk(*android.AndroidMkData, interface{}) subAndroidMk(*android.AndroidMkData, interface{})
useVndk() bool vndk() bool
} }
type subAndroidMkProvider interface { type subAndroidMkProvider interface {
@@ -64,14 +64,14 @@ func (c *Module) AndroidMk() android.AndroidMkData {
if len(c.Properties.AndroidMkSharedLibs) > 0 { if len(c.Properties.AndroidMkSharedLibs) > 0 {
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " ")) fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
} }
if c.Target().Os == android.Android && c.Properties.Sdk_version != "" && !c.useVndk() { if c.Target().Os == android.Android && c.Properties.Sdk_version != "" && !c.vndk() {
fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+c.Properties.Sdk_version) fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+c.Properties.Sdk_version)
fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none") fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none")
} else { } else {
// These are already included in LOCAL_SHARED_LIBRARIES // These are already included in LOCAL_SHARED_LIBRARIES
fmt.Fprintln(w, "LOCAL_CXX_STL := none") fmt.Fprintln(w, "LOCAL_CXX_STL := none")
} }
if c.useVndk() { if c.vndk() {
fmt.Fprintln(w, "LOCAL_USE_VNDK := true") fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
} }
}, },
@@ -89,7 +89,7 @@ func (c *Module) AndroidMk() android.AndroidMkData {
} }
c.subAndroidMk(&ret, c.installer) c.subAndroidMk(&ret, c.installer)
if c.useVndk() && Bool(c.VendorProperties.Vendor_available) { if c.vndk() && Bool(c.VendorProperties.Vendor_available) {
// .vendor suffix is added only when we will have two variants: core and vendor. // .vendor suffix is added only when we will have two variants: core and vendor.
// The suffix is not added for vendor-only module. // The suffix is not added for vendor-only module.
ret.SubName += vendorSuffix ret.SubName += vendorSuffix
@@ -161,7 +161,7 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
} }
fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs) fmt.Fprintln(w, "LOCAL_MODULE_HOST_OS :=", makeOs)
fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true") fmt.Fprintln(w, "LOCAL_IS_HOST_MODULE := true")
} else if ctx.useVndk() { } else if ctx.vndk() {
fmt.Fprintln(w, "LOCAL_USE_VNDK := true") fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
} }

View File

@@ -219,7 +219,7 @@ type builderFlags struct {
arFlags string arFlags string
asFlags string asFlags string
cFlags string cFlags string
toolingCFlags string // A separate set of Cflags for clang LibTooling tools toolingCFlags string // Seperate set of Cflags for clang LibTooling tools
conlyFlags string conlyFlags string
cppFlags string cppFlags string
ldFlags string ldFlags string
@@ -584,7 +584,7 @@ func transformDarwinObjToStaticLib(ctx android.ModuleContext, objFiles android.P
} }
// Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries, // Generate a rule for compiling multiple .o files, plus static libraries, whole static libraries,
// and shared libraries, to a shared library (.so) or dynamic executable // and shared libraires, to a shared library (.so) or dynamic executable
func TransformObjToDynamicBinary(ctx android.ModuleContext, func TransformObjToDynamicBinary(ctx android.ModuleContext,
objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths, objFiles, sharedLibs, staticLibs, lateStaticLibs, wholeStaticLibs, deps android.Paths,
crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath) { crtBegin, crtEnd android.OptionalPath, groupLate bool, flags builderFlags, outputFile android.WritablePath) {
@@ -714,8 +714,8 @@ func SourceAbiDiff(ctx android.ModuleContext, inputDump android.Path, referenceD
return android.OptionalPathForPath(outputFile) return android.OptionalPathForPath(outputFile)
} }
// Generate a rule for extracting a table of contents from a shared library (.so) // Generate a rule for extract a table of contents from a shared library (.so)
func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.Path, func TransformSharedObjectToToc(ctx android.ModuleContext, inputFile android.WritablePath,
outputFile android.WritablePath, flags builderFlags) { outputFile android.WritablePath, flags builderFlags) {
crossCompile := gccCmd(flags.toolchain, "") crossCompile := gccCmd(flags.toolchain, "")

327
cc/cc.go
View File

@@ -194,7 +194,7 @@ type ModuleContextIntf interface {
noDefaultCompilerFlags() bool noDefaultCompilerFlags() bool
sdk() bool sdk() bool
sdkVersion() string sdkVersion() string
useVndk() bool vndk() bool
isVndk() bool isVndk() bool
isVndkSp() bool isVndkSp() bool
createVndkSourceAbiDump() bool createVndkSourceAbiDump() bool
@@ -377,7 +377,7 @@ func (c *Module) isDependencyRoot() bool {
return false return false
} }
func (c *Module) useVndk() bool { func (c *Module) vndk() bool {
return c.Properties.UseVndk return c.Properties.UseVndk
} }
@@ -403,8 +403,10 @@ type moduleContext struct {
moduleContextImpl moduleContextImpl
} }
func (ctx *moduleContext) InstallOnVendorPartition() bool { // Vendor returns true for vendor modules excluding VNDK libraries so that
return ctx.ModuleContext.Vendor() || (ctx.mod.useVndk() && !ctx.mod.isVndk()) // they get installed onto the correct partition
func (ctx *moduleContext) Vendor() bool {
return ctx.ModuleContext.Vendor() || (ctx.mod.vndk() && !ctx.mod.isVndk())
} }
type moduleContextImpl struct { type moduleContextImpl struct {
@@ -443,7 +445,7 @@ func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
} }
func (ctx *moduleContextImpl) sdk() bool { func (ctx *moduleContextImpl) sdk() bool {
if ctx.ctx.Device() && !ctx.useVndk() { if ctx.ctx.Device() && !ctx.vndk() {
return ctx.mod.Properties.Sdk_version != "" return ctx.mod.Properties.Sdk_version != ""
} }
return false return false
@@ -451,7 +453,7 @@ func (ctx *moduleContextImpl) sdk() bool {
func (ctx *moduleContextImpl) sdkVersion() string { func (ctx *moduleContextImpl) sdkVersion() string {
if ctx.ctx.Device() { if ctx.ctx.Device() {
if ctx.useVndk() { if ctx.vndk() {
return "current" return "current"
} else { } else {
return ctx.mod.Properties.Sdk_version return ctx.mod.Properties.Sdk_version
@@ -460,12 +462,13 @@ func (ctx *moduleContextImpl) sdkVersion() string {
return "" return ""
} }
func (ctx *moduleContextImpl) vndk() bool {
return ctx.mod.vndk()
}
func (ctx *moduleContextImpl) isVndk() bool { func (ctx *moduleContextImpl) isVndk() bool {
return ctx.mod.isVndk() return ctx.mod.isVndk()
} }
func (ctx *moduleContextImpl) useVndk() bool {
return ctx.mod.useVndk()
}
func (ctx *moduleContextImpl) isVndkSp() bool { func (ctx *moduleContextImpl) isVndkSp() bool {
if vndk := ctx.mod.vndkdep; vndk != nil { if vndk := ctx.mod.vndkdep; vndk != nil {
@@ -476,7 +479,7 @@ func (ctx *moduleContextImpl) isVndkSp() bool {
// Create source abi dumps if the module belongs to the list of VndkLibraries. // Create source abi dumps if the module belongs to the list of VndkLibraries.
func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool { func (ctx *moduleContextImpl) createVndkSourceAbiDump() bool {
return ctx.ctx.Device() && ((ctx.useVndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries)) return ctx.ctx.Device() && ((ctx.vndk() && ctx.isVndk()) || inList(ctx.baseModuleName(), llndkLibraries))
} }
func (ctx *moduleContextImpl) selectedStl() string { func (ctx *moduleContextImpl) selectedStl() string {
@@ -530,7 +533,6 @@ func (c *Module) Name() string {
} }
func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) { func (c *Module) GenerateAndroidBuildActions(actx android.ModuleContext) {
ctx := &moduleContext{ ctx := &moduleContext{
ModuleContext: actx, ModuleContext: actx,
moduleContextImpl: moduleContextImpl{ moduleContextImpl: moduleContextImpl{
@@ -762,23 +764,19 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
if ctx.Os() == android.Android { if ctx.Os() == android.Android {
version := ctx.sdkVersion() version := ctx.sdkVersion()
// rewriteNdkLibs takes a list of names of shared libraries and scans it for three types // Rewrites the names of shared libraries into the names of the NDK
// of names: // libraries where appropriate. This returns two slices.
// //
// 1. Name of an NDK library that refers to a prebuilt module. // The first is a list of non-variant shared libraries (either rewritten
// For each of these, it adds the name of the prebuilt module (which will be in // NDK libraries to the modules in prebuilts/ndk, or not rewritten
// prebuilts/ndk) to the list of nonvariant libs. // because they are not NDK libraries).
// 2. Name of an NDK library that refers to an ndk_library module.
// For each of these, it adds the name of the ndk_library module to the list of
// variant libs.
// 3. Anything else (so anything that isn't an NDK library).
// It adds these to the nonvariantLibs list.
// //
// The caller can then know to add the variantLibs dependencies differently from the // The second is a list of ndk_library modules. These need to be
// nonvariantLibs // separated because they are a variation dependency and must be added
rewriteNdkLibs := func(list []string) (nonvariantLibs []string, variantLibs []string) { // in a different manner.
variantLibs = []string{} rewriteNdkLibs := func(list []string) ([]string, []string) {
nonvariantLibs = []string{} variantLibs := []string{}
nonvariantLibs := []string{}
for _, entry := range list { for _, entry := range list {
if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) { if ctx.sdk() && inList(entry, ndkPrebuiltSharedLibraries) {
if !inList(entry, ndkMigratedLibs) { if !inList(entry, ndkMigratedLibs) {
@@ -786,7 +784,7 @@ func (c *Module) DepsMutator(actx android.BottomUpMutatorContext) {
} else { } else {
variantLibs = append(variantLibs, entry+ndkLibrarySuffix) variantLibs = append(variantLibs, entry+ndkLibrarySuffix)
} }
} else if ctx.useVndk() && inList(entry, llndkLibraries) { } else if ctx.vndk() && inList(entry, llndkLibraries) {
nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix) nonvariantLibs = append(nonvariantLibs, entry+llndkLibrarySuffix)
} else { } else {
nonvariantLibs = append(nonvariantLibs, entry) nonvariantLibs = append(nonvariantLibs, entry)
@@ -888,118 +886,117 @@ func (c *Module) clang(ctx BaseModuleContext) bool {
return clang return clang
} }
// Whether a module can link to another module, taking into
// account NDK linking.
func checkLinkType(ctx android.ModuleContext, from *Module, to *Module) {
if from.Target().Os != android.Android {
// Host code is not restricted
return
}
if from.Properties.UseVndk {
// Though vendor code is limited by the vendor mutator,
// each vendor-available module needs to check
// link-type for VNDK.
if from.vndkdep != nil {
from.vndkdep.vndkCheckLinkType(ctx, to)
}
return
}
if from.Properties.Sdk_version == "" {
// Platform code can link to anything
return
}
if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
// These are always allowed
return
}
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
// These are allowed, but they don't set sdk_version
return
}
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
// These are allowed, but they don't set sdk_version
return
}
if _, ok := to.linker.(*stubDecorator); ok {
// These aren't real libraries, but are the stub shared libraries that are included in
// the NDK.
return
}
if to.Properties.Sdk_version == "" {
// NDK code linking to platform code is never okay.
ctx.ModuleErrorf("depends on non-NDK-built library %q",
ctx.OtherModuleName(to))
}
// At this point we know we have two NDK libraries, but we need to
// check that we're not linking against anything built against a higher
// API level, as it is only valid to link against older or equivalent
// APIs.
if from.Properties.Sdk_version == "current" {
// Current can link against anything.
return
} else if to.Properties.Sdk_version == "current" {
// Current can't be linked against by anything else.
ctx.ModuleErrorf("links %q built against newer API version %q",
ctx.OtherModuleName(to), "current")
}
fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
if err != nil {
ctx.PropertyErrorf("sdk_version",
"Invalid sdk_version value (must be int): %q",
from.Properties.Sdk_version)
}
toApi, err := strconv.Atoi(to.Properties.Sdk_version)
if err != nil {
ctx.PropertyErrorf("sdk_version",
"Invalid sdk_version value (must be int): %q",
to.Properties.Sdk_version)
}
if toApi > fromApi {
ctx.ModuleErrorf("links %q built against newer API version %q",
ctx.OtherModuleName(to), to.Properties.Sdk_version)
}
}
// Convert dependencies to paths. Returns a PathDeps containing paths // Convert dependencies to paths. Returns a PathDeps containing paths
func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps { func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps var depPaths PathDeps
ctx.VisitDirectDeps(func(dep blueprint.Module) { // Whether a module can link to another module, taking into
depName := ctx.OtherModuleName(dep) // account NDK linking.
depTag := ctx.OtherModuleDependencyTag(dep) checkLinkType := func(from, to *Module) {
if from.Target().Os != android.Android {
// Host code is not restricted
return
}
if from.Properties.UseVndk {
// Though vendor code is limited by the vendor mutator,
// each vendor-available module needs to check
// link-type for VNDK.
if from.vndkdep != nil {
from.vndkdep.vndkCheckLinkType(ctx, to)
}
return
}
if from.Properties.Sdk_version == "" {
// Platform code can link to anything
return
}
if _, ok := to.linker.(*toolchainLibraryDecorator); ok {
// These are always allowed
return
}
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
// These are allowed, but don't set sdk_version
return
}
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
// These are allowed, but don't set sdk_version
return
}
if _, ok := to.linker.(*stubDecorator); ok {
// These aren't real libraries, but are the stub shared libraries that are included in
// the NDK.
return
}
if to.Properties.Sdk_version == "" {
// NDK code linking to platform code is never okay.
ctx.ModuleErrorf("depends on non-NDK-built library %q",
ctx.OtherModuleName(to))
}
aDep, _ := dep.(android.Module) // All this point we know we have two NDK libraries, but we need to
if aDep == nil { // check that we're not linking against anything built against a higher
ctx.ModuleErrorf("module %q not an android module", depName) // API level, as it is only valid to link against older or equivalent
// APIs.
if from.Properties.Sdk_version == "current" {
// Current can link against anything.
return
} else if to.Properties.Sdk_version == "current" {
// Current can't be linked against by anything else.
ctx.ModuleErrorf("links %q built against newer API version %q",
ctx.OtherModuleName(to), "current")
}
fromApi, err := strconv.Atoi(from.Properties.Sdk_version)
if err != nil {
ctx.PropertyErrorf("sdk_version",
"Invalid sdk_version value (must be int): %q",
from.Properties.Sdk_version)
}
toApi, err := strconv.Atoi(to.Properties.Sdk_version)
if err != nil {
ctx.PropertyErrorf("sdk_version",
"Invalid sdk_version value (must be int): %q",
to.Properties.Sdk_version)
}
if toApi > fromApi {
ctx.ModuleErrorf("links %q built against newer API version %q",
ctx.OtherModuleName(to), to.Properties.Sdk_version)
}
}
ctx.VisitDirectDeps(func(m blueprint.Module) {
name := ctx.OtherModuleName(m)
tag := ctx.OtherModuleDependencyTag(m)
a, _ := m.(android.Module)
if a == nil {
ctx.ModuleErrorf("module %q not an android module", name)
return return
} }
ccDep, _ := dep.(*Module) cc, _ := m.(*Module)
if ccDep == nil { if cc == nil {
// handling for a few module types that aren't cc Module but that are also supported switch tag {
switch depTag {
case android.DefaultsDepTag, android.SourceDepTag: case android.DefaultsDepTag, android.SourceDepTag:
// Nothing to do // Nothing to do
case genSourceDepTag: case genSourceDepTag:
if genRule, ok := dep.(genrule.SourceFileGenerator); ok { if genRule, ok := m.(genrule.SourceFileGenerator); ok {
depPaths.GeneratedSources = append(depPaths.GeneratedSources, depPaths.GeneratedSources = append(depPaths.GeneratedSources,
genRule.GeneratedSourceFiles()...) genRule.GeneratedSourceFiles()...)
} else { } else {
ctx.ModuleErrorf("module %q is not a gensrcs or genrule", depName) ctx.ModuleErrorf("module %q is not a gensrcs or genrule", name)
} }
// Support exported headers from a generated_sources dependency // Support exported headers from a generated_sources dependency
fallthrough fallthrough
case genHeaderDepTag, genHeaderExportDepTag: case genHeaderDepTag, genHeaderExportDepTag:
if genRule, ok := dep.(genrule.SourceFileGenerator); ok { if genRule, ok := m.(genrule.SourceFileGenerator); ok {
depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders, depPaths.GeneratedHeaders = append(depPaths.GeneratedHeaders,
genRule.GeneratedSourceFiles()...) genRule.GeneratedSourceFiles()...)
flags := includeDirsToFlags(genRule.GeneratedHeaderDirs()) flags := includeDirsToFlags(genRule.GeneratedHeaderDirs())
depPaths.Flags = append(depPaths.Flags, flags) depPaths.Flags = append(depPaths.Flags, flags)
if depTag == genHeaderExportDepTag { if tag == genHeaderExportDepTag {
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags) depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags)
depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps, depPaths.ReexportedFlagsDeps = append(depPaths.ReexportedFlagsDeps,
genRule.GeneratedSourceFiles()...) genRule.GeneratedSourceFiles()...)
@@ -1008,46 +1005,46 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} }
} else { } else {
ctx.ModuleErrorf("module %q is not a genrule", depName) ctx.ModuleErrorf("module %q is not a genrule", name)
} }
case linkerScriptDepTag: case linkerScriptDepTag:
if genRule, ok := dep.(genrule.SourceFileGenerator); ok { if genRule, ok := m.(genrule.SourceFileGenerator); ok {
files := genRule.GeneratedSourceFiles() files := genRule.GeneratedSourceFiles()
if len(files) == 1 { if len(files) == 1 {
depPaths.LinkerScript = android.OptionalPathForPath(files[0]) depPaths.LinkerScript = android.OptionalPathForPath(files[0])
} else if len(files) > 1 { } else if len(files) > 1 {
ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", depName) ctx.ModuleErrorf("module %q can only generate a single file if used for a linker script", name)
} }
} else { } else {
ctx.ModuleErrorf("module %q is not a genrule", depName) ctx.ModuleErrorf("module %q is not a genrule", name)
} }
default: default:
ctx.ModuleErrorf("depends on non-cc module %q", depName) ctx.ModuleErrorf("depends on non-cc module %q", name)
} }
return return
} }
// some validation if !a.Enabled() {
if !aDep.Enabled() {
if ctx.AConfig().AllowMissingDependencies() { if ctx.AConfig().AllowMissingDependencies() {
ctx.AddMissingDependencies([]string{depName}) ctx.AddMissingDependencies([]string{name})
} else { } else {
ctx.ModuleErrorf("depends on disabled module %q", depName) ctx.ModuleErrorf("depends on disabled module %q", name)
} }
return return
} }
if aDep.Target().Os != ctx.Os() {
ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), depName) if a.Target().Os != ctx.Os() {
return ctx.ModuleErrorf("OS mismatch between %q and %q", ctx.ModuleName(), name)
}
if aDep.Target().Arch.ArchType != ctx.Arch().ArchType {
ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), depName)
return return
} }
// re-exporting flags if a.Target().Arch.ArchType != ctx.Arch().ArchType {
if depTag == reuseObjTag { ctx.ModuleErrorf("Arch mismatch between %q and %q", ctx.ModuleName(), name)
if l, ok := ccDep.compiler.(libraryInterface); ok { return
}
if tag == reuseObjTag {
if l, ok := cc.compiler.(libraryInterface); ok {
objs, flags, deps := l.reuseObjs() objs, flags, deps := l.reuseObjs()
depPaths.Objs = depPaths.Objs.Append(objs) depPaths.Objs = depPaths.Objs.Append(objs)
depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...) depPaths.ReexportedFlags = append(depPaths.ReexportedFlags, flags...)
@@ -1055,8 +1052,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return return
} }
} }
if t, ok := depTag.(dependencyTag); ok && t.library {
if i, ok := ccDep.linker.(exportedFlagsProducer); ok { if t, ok := tag.(dependencyTag); ok && t.library {
if i, ok := cc.linker.(exportedFlagsProducer); ok {
flags := i.exportedFlags() flags := i.exportedFlags()
deps := i.exportedFlagsDeps() deps := i.exportedFlagsDeps()
depPaths.Flags = append(depPaths.Flags, flags...) depPaths.Flags = append(depPaths.Flags, flags...)
@@ -1072,38 +1070,38 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
} }
} }
checkLinkType(ctx, c, ccDep) checkLinkType(c, cc)
} }
var ptr *android.Paths var ptr *android.Paths
var depPtr *android.Paths var depPtr *android.Paths
linkFile := ccDep.outputFile linkFile := cc.outputFile
depFile := android.OptionalPath{} depFile := android.OptionalPath{}
switch depTag { switch tag {
case ndkStubDepTag, sharedDepTag, sharedExportDepTag: case ndkStubDepTag, sharedDepTag, sharedExportDepTag:
ptr = &depPaths.SharedLibs ptr = &depPaths.SharedLibs
depPtr = &depPaths.SharedLibsDeps depPtr = &depPaths.SharedLibsDeps
depFile = ccDep.linker.(libraryInterface).toc() depFile = cc.linker.(libraryInterface).toc()
case lateSharedDepTag, ndkLateStubDepTag: case lateSharedDepTag, ndkLateStubDepTag:
ptr = &depPaths.LateSharedLibs ptr = &depPaths.LateSharedLibs
depPtr = &depPaths.LateSharedLibsDeps depPtr = &depPaths.LateSharedLibsDeps
depFile = ccDep.linker.(libraryInterface).toc() depFile = cc.linker.(libraryInterface).toc()
case staticDepTag, staticExportDepTag: case staticDepTag, staticExportDepTag:
ptr = &depPaths.StaticLibs ptr = &depPaths.StaticLibs
case lateStaticDepTag: case lateStaticDepTag:
ptr = &depPaths.LateStaticLibs ptr = &depPaths.LateStaticLibs
case wholeStaticDepTag: case wholeStaticDepTag:
ptr = &depPaths.WholeStaticLibs ptr = &depPaths.WholeStaticLibs
staticLib, ok := ccDep.linker.(libraryInterface) staticLib, ok := cc.linker.(libraryInterface)
if !ok || !staticLib.static() { if !ok || !staticLib.static() {
ctx.ModuleErrorf("module %q not a static library", depName) ctx.ModuleErrorf("module %q not a static library", name)
return return
} }
if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil { if missingDeps := staticLib.getWholeStaticMissingDeps(); missingDeps != nil {
postfix := " (required by " + ctx.OtherModuleName(dep) + ")" postfix := " (required by " + ctx.OtherModuleName(m) + ")"
for i := range missingDeps { for i := range missingDeps {
missingDeps[i] += postfix missingDeps[i] += postfix
} }
@@ -1120,11 +1118,11 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.CrtEnd = linkFile depPaths.CrtEnd = linkFile
} }
switch depTag { switch tag {
case staticDepTag, staticExportDepTag, lateStaticDepTag: case staticDepTag, staticExportDepTag, lateStaticDepTag:
staticLib, ok := ccDep.linker.(libraryInterface) staticLib, ok := cc.linker.(libraryInterface)
if !ok || !staticLib.static() { if !ok || !staticLib.static() {
ctx.ModuleErrorf("module %q not a static library", depName) ctx.ModuleErrorf("module %q not a static library", name)
return return
} }
@@ -1135,12 +1133,11 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
staticLib.objs().coverageFiles...) staticLib.objs().coverageFiles...)
depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles, depPaths.StaticLibObjs.sAbiDumpFiles = append(depPaths.StaticLibObjs.sAbiDumpFiles,
staticLib.objs().sAbiDumpFiles...) staticLib.objs().sAbiDumpFiles...)
} }
if ptr != nil { if ptr != nil {
if !linkFile.Valid() { if !linkFile.Valid() {
ctx.ModuleErrorf("module %q missing output file", depName) ctx.ModuleErrorf("module %q missing output file", name)
return return
} }
*ptr = append(*ptr, linkFile.Path()) *ptr = append(*ptr, linkFile.Path())
@@ -1154,24 +1151,24 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
*depPtr = append(*depPtr, dep.Path()) *depPtr = append(*depPtr, dep.Path())
} }
// Export the shared libs to Make. // Export the shared libs to the make world. In doing so, .vendor suffix
switch depTag { // is added if the lib has both core and vendor variants and this module
// is building against vndk. This is because the vendor variant will be
// have .vendor suffix in its name in the make world. However, if the
// lib is a vendor-only lib or this lib is not building against vndk,
// then the suffix is not added.
switch tag {
case sharedDepTag, sharedExportDepTag, lateSharedDepTag: case sharedDepTag, sharedExportDepTag, lateSharedDepTag:
libName := strings.TrimSuffix(depName, llndkLibrarySuffix) libName := strings.TrimSuffix(name, llndkLibrarySuffix)
libName = strings.TrimPrefix(libName, "prebuilt_") libName = strings.TrimPrefix(libName, "prebuilt_")
isLLndk := inList(libName, llndkLibraries) isLLndk := inList(libName, llndkLibraries)
var makeLibName string if c.vndk() && (Bool(cc.VendorProperties.Vendor_available) || isLLndk) {
bothVendorAndCoreVariantsExist := Bool(ccDep.VendorProperties.Vendor_available) || isLLndk libName += vendorSuffix
if c.useVndk() && bothVendorAndCoreVariantsExist {
// The vendor module in Make will have been renamed to not conflict with the core
// module, so update the dependency name here accordingly.
makeLibName = libName + vendorSuffix
} else {
makeLibName = libName
} }
// Note: the order of libs in this list is not important because // Note: the order of libs in this list is not important because
// they merely serve as Make dependencies and do not affect this lib itself. // they merely serve as dependencies in the make world and do not
c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, makeLibName) // affect this lib itself.
c.Properties.AndroidMkSharedLibs = append(c.Properties.AndroidMkSharedLibs, libName)
} }
}) })
@@ -1368,8 +1365,8 @@ outer:
return list[:k] return list[:k]
} }
// lastUniqueElements returns all unique elements of a slice, keeping the last copy of each. // lastUniqueElements returns all unique elements of a slice, keeping the last copy of each
// It modifies the slice contents in place, and returns a subslice of the original slice // modifies the slice contents in place, and returns a subslice of the original slice
func lastUniqueElements(list []string) []string { func lastUniqueElements(list []string) []string {
totalSkip := 0 totalSkip := 0
for i := len(list) - 1; i >= totalSkip; i-- { for i := len(list) - 1; i >= totalSkip; i-- {

View File

@@ -236,7 +236,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String()) flags.GlobalFlags = append(flags.GlobalFlags, "-I"+android.PathForModuleSrc(ctx).String())
flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String()) flags.YasmFlags = append(flags.YasmFlags, "-I"+android.PathForModuleSrc(ctx).String())
if !(ctx.sdk() || ctx.useVndk()) || ctx.Host() { if !(ctx.sdk() || ctx.vndk()) || ctx.Host() {
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, flags.SystemIncludeFlags = append(flags.SystemIncludeFlags,
"${config.CommonGlobalIncludes}", "${config.CommonGlobalIncludes}",
tc.IncludeFlags(), tc.IncludeFlags(),
@@ -272,7 +272,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, "-isystem "+legacyIncludes) flags.SystemIncludeFlags = append(flags.SystemIncludeFlags, "-isystem "+legacyIncludes)
} }
if ctx.useVndk() { if ctx.vndk() {
flags.GlobalFlags = append(flags.GlobalFlags, flags.GlobalFlags = append(flags.GlobalFlags,
"-D__ANDROID_API__=__ANDROID_API_FUTURE__", "-D__ANDROID_VNDK__") "-D__ANDROID_API__=__ANDROID_API_FUTURE__", "-D__ANDROID_VNDK__")
} }
@@ -405,7 +405,7 @@ func (compiler *baseCompiler) compilerFlags(ctx ModuleContext, flags Flags) Flag
flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...) flags.CppFlags = append([]string{"-std=" + cppStd}, flags.CppFlags...)
} }
if ctx.useVndk() { if ctx.vndk() {
flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...) flags.CFlags = append(flags.CFlags, esc(compiler.Properties.Target.Vendor.Cflags)...)
} }
@@ -490,7 +490,7 @@ func (compiler *baseCompiler) compile(ctx ModuleContext, flags Flags, deps PathD
pathDeps := deps.GeneratedHeaders pathDeps := deps.GeneratedHeaders
pathDeps = append(pathDeps, ndkPathDeps(ctx)...) pathDeps = append(pathDeps, ndkPathDeps(ctx)...)
if ctx.useVndk() { if ctx.vndk() {
compiler.Properties.Srcs = append(compiler.Properties.Srcs, compiler.Properties.Srcs = append(compiler.Properties.Srcs,
compiler.Properties.Target.Vendor.Srcs...) compiler.Properties.Target.Vendor.Srcs...)

View File

@@ -69,7 +69,7 @@ func (installer *baseInstaller) installDir(ctx ModuleContext) android.OutputPath
if !ctx.Host() && !ctx.Arch().Native { if !ctx.Host() && !ctx.Arch().Native {
dir = filepath.Join(dir, ctx.Arch().ArchType.String()) dir = filepath.Join(dir, ctx.Arch().ArchType.String())
} }
if installer.location == InstallInData && ctx.useVndk() { if installer.location == InstallInData && ctx.vndk() {
dir = filepath.Join(dir, "vendor") dir = filepath.Join(dir, "vendor")
} }
return android.PathForModuleInstall(ctx, dir, installer.subDir, installer.Properties.Relative_install_path, installer.relative) return android.PathForModuleInstall(ctx, dir, installer.subDir, installer.Properties.Relative_install_path, installer.relative)

View File

@@ -155,7 +155,7 @@ type flagExporter struct {
} }
func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths { func (f *flagExporter) exportedIncludes(ctx ModuleContext) android.Paths {
if ctx.useVndk() && f.Properties.Target.Vendor.Export_include_dirs != nil { if ctx.vndk() && f.Properties.Target.Vendor.Export_include_dirs != nil {
return android.PathsForModuleSrc(ctx, f.Properties.Target.Vendor.Export_include_dirs) return android.PathsForModuleSrc(ctx, f.Properties.Target.Vendor.Export_include_dirs)
} else { } else {
return android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs) return android.PathsForModuleSrc(ctx, f.Properties.Export_include_dirs)
@@ -697,7 +697,7 @@ func (library *libraryDecorator) toc() android.OptionalPath {
func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) { func (library *libraryDecorator) install(ctx ModuleContext, file android.Path) {
if library.shared() { if library.shared() {
if ctx.Device() { if ctx.Device() {
if ctx.useVndk() { if ctx.vndk() {
if ctx.isVndkSp() { if ctx.isVndkSp() {
library.baseInstaller.subDir = "vndk-sp" library.baseInstaller.subDir = "vndk-sp"
} else if ctx.isVndk() { } else if ctx.isVndk() {

View File

@@ -132,7 +132,7 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...) deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...) deps.ReexportGeneratedHeaders = append(deps.ReexportGeneratedHeaders, linker.Properties.Export_generated_headers...)
if ctx.useVndk() { if ctx.vndk() {
deps.SharedLibs = removeListFromList(deps.SharedLibs, linker.Properties.Target.Vendor.Exclude_shared_libs) deps.SharedLibs = removeListFromList(deps.SharedLibs, linker.Properties.Target.Vendor.Exclude_shared_libs)
deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, linker.Properties.Target.Vendor.Exclude_shared_libs) deps.ReexportSharedLibHeaders = removeListFromList(deps.ReexportSharedLibHeaders, linker.Properties.Target.Vendor.Exclude_shared_libs)
} }
@@ -174,7 +174,7 @@ func (linker *baseLinker) linkerDeps(ctx BaseModuleContext, deps Deps) Deps {
} }
deps.LateSharedLibs = append(deps.LateSharedLibs, systemSharedLibs...) deps.LateSharedLibs = append(deps.LateSharedLibs, systemSharedLibs...)
} else if ctx.sdk() || ctx.useVndk() { } else if ctx.sdk() || ctx.vndk() {
deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm", "libdl") deps.LateSharedLibs = append(deps.LateSharedLibs, "libc", "libm", "libdl")
} }
} }

View File

@@ -43,7 +43,7 @@ func objectFactory() android.Module {
} }
func (object *objectLinker) appendLdflags(flags []string) { func (object *objectLinker) appendLdflags(flags []string) {
panic(fmt.Errorf("appendLdflags on objectLinker not supported")) panic(fmt.Errorf("appendLdflags on object Linker not supported"))
} }
func (object *objectLinker) linkerProps() []interface{} { func (object *objectLinker) linkerProps() []interface{} {

View File

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

View File

@@ -421,7 +421,7 @@ func (sanitize *sanitize) flags(ctx ModuleContext, flags Flags) Flags {
// When linking against VNDK, use the vendor variant of the runtime lib // When linking against VNDK, use the vendor variant of the runtime lib
sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary
if ctx.useVndk() { if ctx.vndk() {
sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary + vendorSuffix sanitize.androidMkRuntimeLibrary = sanitize.runtimeLibrary + vendorSuffix
} }
} }