Check NDK linking, expose SDK_VERSION to Make am: a96ff64527

am: e996f78112

Change-Id: I903231f0af81360e3674400da2fc09d741d86fe3
This commit is contained in:
Dan Willemsen 2016-06-08 19:59:16 +00:00 committed by android-build-merger
commit 4811b8c822
2 changed files with 52 additions and 15 deletions

View File

@ -35,6 +35,13 @@ func (c *Module) AndroidMk() (ret android.AndroidMkData, err error) {
if len(c.Properties.AndroidMkSharedLibs) > 0 {
fmt.Fprintln(w, "LOCAL_SHARED_LIBRARIES := "+strings.Join(c.Properties.AndroidMkSharedLibs, " "))
}
if c.Target().Os == android.Android && c.Properties.Sdk_version != "" {
fmt.Fprintln(w, "LOCAL_SDK_VERSION := "+c.Properties.Sdk_version)
fmt.Fprintln(w, "LOCAL_NDK_STL_VARIANT := none")
} else {
// These are already included in LOCAL_SHARED_LIBRARIES
fmt.Fprintln(w, "LOCAL_CXX_STL := none")
}
return nil
})
@ -85,8 +92,6 @@ func (library *libraryLinker) AndroidMk(ret *android.AndroidMkData) {
fmt.Fprintln(w, "LOCAL_MODULE_SUFFIX := "+outputFile.Ext())
// These are already included in LOCAL_SHARED_LIBRARIES
fmt.Fprintln(w, "LOCAL_CXX_STL := none")
fmt.Fprintln(w, "LOCAL_SYSTEM_SHARED_LIBRARIES :=")
return nil

View File

@ -636,11 +636,17 @@ func (ctx *moduleContextImpl) noDefaultCompilerFlags() bool {
}
func (ctx *moduleContextImpl) sdk() bool {
return ctx.mod.Properties.Sdk_version != ""
if ctx.ctx.Device() {
return ctx.mod.Properties.Sdk_version != ""
}
return false
}
func (ctx *moduleContextImpl) sdkVersion() string {
return ctx.mod.Properties.Sdk_version
if ctx.ctx.Device() {
return ctx.mod.Properties.Sdk_version
}
return ""
}
func (ctx *moduleContextImpl) selectedStl() string {
@ -901,6 +907,28 @@ func (c *Module) clang(ctx BaseModuleContext) bool {
func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
var depPaths PathDeps
// Whether a module can link to another module, taking into
// account NDK linking.
linkTypeOk := func(from, to *Module) bool {
if from.Target().Os != android.Android {
// Host code is not restricted
return true
}
if from.Properties.Sdk_version == "" {
// Platform code can link to anything
return true
}
if _, ok := to.linker.(*toolchainLibraryLinker); ok {
// These are always allowed
return true
}
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
// These are allowed, but don't set sdk_version
return true
}
return from.Properties.Sdk_version != ""
}
ctx.VisitDirectDeps(func(m blueprint.Module) {
name := ctx.OtherModuleName(m)
tag := ctx.OtherModuleDependencyTag(m)
@ -911,8 +939,8 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return
}
c, _ := m.(*Module)
if c == nil {
cc, _ := m.(*Module)
if cc == nil {
switch tag {
case android.DefaultsDepTag:
case genSourceDepTag:
@ -952,19 +980,19 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
return
}
if !c.outputFile.Valid() {
if !cc.outputFile.Valid() {
ctx.ModuleErrorf("module %q missing output file", name)
return
}
if tag == reuseObjTag {
depPaths.ObjFiles = append(depPaths.ObjFiles,
c.compiler.(*libraryCompiler).reuseObjFiles...)
cc.compiler.(*libraryCompiler).reuseObjFiles...)
return
}
if t, ok := tag.(dependencyTag); ok && t.library {
if i, ok := c.linker.(exportedFlagsProducer); ok {
if i, ok := cc.linker.(exportedFlagsProducer); ok {
cflags := i.exportedFlags()
depPaths.Cflags = append(depPaths.Cflags, cflags...)
@ -972,6 +1000,10 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPaths.ReexportedCflags = append(depPaths.ReexportedCflags, cflags...)
}
}
if !linkTypeOk(c, cc) {
ctx.ModuleErrorf("depends on non-NDK-built library %q", name)
}
}
var depPtr *android.Paths
@ -987,9 +1019,9 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
depPtr = &depPaths.LateStaticLibs
case wholeStaticDepTag:
depPtr = &depPaths.WholeStaticLibs
staticLib, _ := c.linker.(*libraryLinker)
staticLib, _ := cc.linker.(*libraryLinker)
if staticLib == nil || !staticLib.static() {
ctx.ModuleErrorf("module %q not a static library", ctx.OtherModuleName(m))
ctx.ModuleErrorf("module %q not a static library", name)
return
}
@ -1005,15 +1037,15 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
case objDepTag:
depPtr = &depPaths.ObjFiles
case crtBeginDepTag:
depPaths.CrtBegin = c.outputFile
depPaths.CrtBegin = cc.outputFile
case crtEndDepTag:
depPaths.CrtEnd = c.outputFile
depPaths.CrtEnd = cc.outputFile
default:
panic(fmt.Errorf("unknown dependency tag: %s", tag))
}
if depPtr != nil {
*depPtr = append(*depPtr, c.outputFile.Path())
*depPtr = append(*depPtr, cc.outputFile.Path())
}
})
@ -1266,7 +1298,7 @@ func (linker *baseLinker) deps(ctx BaseModuleContext, deps Deps) Deps {
deps.ReexportStaticLibHeaders = append(deps.ReexportStaticLibHeaders, linker.Properties.Export_static_lib_headers...)
deps.ReexportSharedLibHeaders = append(deps.ReexportSharedLibHeaders, linker.Properties.Export_shared_lib_headers...)
if ctx.ModuleName() != "libcompiler_rt-extras" {
if !ctx.sdk() && ctx.ModuleName() != "libcompiler_rt-extras" {
deps.StaticLibs = append(deps.StaticLibs, "libcompiler_rt-extras")
}