Merge "Check NDK API level link compatibility."
This commit is contained in:
commit
5c395b39b4
57
cc/cc.go
57
cc/cc.go
|
@ -20,6 +20,7 @@ package cc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/google/blueprint"
|
"github.com/google/blueprint"
|
||||||
|
@ -654,33 +655,69 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||||
|
|
||||||
// Whether a module can link to another module, taking into
|
// Whether a module can link to another module, taking into
|
||||||
// account NDK linking.
|
// account NDK linking.
|
||||||
linkTypeOk := func(from, to *Module) bool {
|
checkLinkType := func(from, to *Module) {
|
||||||
if from.Target().Os != android.Android {
|
if from.Target().Os != android.Android {
|
||||||
// Host code is not restricted
|
// Host code is not restricted
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
if from.Properties.Sdk_version == "" {
|
if from.Properties.Sdk_version == "" {
|
||||||
// Platform code can link to anything
|
// Platform code can link to anything
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
if _, ok := to.linker.(*toolchainLibraryLinker); ok {
|
if _, ok := to.linker.(*toolchainLibraryLinker); ok {
|
||||||
// These are always allowed
|
// These are always allowed
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
|
if _, ok := to.linker.(*ndkPrebuiltLibraryLinker); ok {
|
||||||
// These are allowed, but don't set sdk_version
|
// These are allowed, but don't set sdk_version
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
|
if _, ok := to.linker.(*ndkPrebuiltStlLinker); ok {
|
||||||
// These are allowed, but don't set sdk_version
|
// These are allowed, but don't set sdk_version
|
||||||
return true
|
return
|
||||||
}
|
}
|
||||||
if _, ok := to.linker.(*stubLinker); ok {
|
if _, ok := to.linker.(*stubLinker); ok {
|
||||||
// These aren't real libraries, but are the stub shared libraries that are included in
|
// These aren't real libraries, but are the stub shared libraries that are included in
|
||||||
// the NDK.
|
// the NDK.
|
||||||
return true
|
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))
|
||||||
|
}
|
||||||
|
|
||||||
|
// All 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)
|
||||||
}
|
}
|
||||||
return to.Properties.Sdk_version != ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
ctx.VisitDirectDeps(func(m blueprint.Module) {
|
||||||
|
@ -755,9 +792,7 @@ func (c *Module) depsToPaths(ctx android.ModuleContext) PathDeps {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !linkTypeOk(c, cc) {
|
checkLinkType(c, cc)
|
||||||
ctx.ModuleErrorf("depends on non-NDK-built library %q", name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var depPtr *android.Paths
|
var depPtr *android.Paths
|
||||||
|
|
Loading…
Reference in New Issue