Merge changes Ia7deed13,I7378a46f

* changes:
  Add support for Rust C libraries.
  Add a common interface for cc linkable libraries.
This commit is contained in:
Ivan Lozano
2019-10-29 21:47:14 +00:00
committed by Gerrit Code Review
20 changed files with 1021 additions and 346 deletions

View File

@@ -36,10 +36,10 @@ type AndroidMkContext interface {
Arch() android.Arch
Os() android.OsType
Host() bool
useVndk() bool
UseVndk() bool
vndkVersion() string
static() bool
inRecovery() bool
InRecovery() bool
}
type subAndroidMkProvider interface {
@@ -89,9 +89,9 @@ func (c *Module) AndroidMk() android.AndroidMkData {
fmt.Fprintln(w, "LOCAL_WHOLE_STATIC_LIBRARIES := "+strings.Join(c.Properties.AndroidMkWholeStaticLibs, " "))
}
fmt.Fprintln(w, "LOCAL_SOONG_LINK_TYPE :=", c.makeLinkType)
if c.useVndk() {
if c.UseVndk() {
fmt.Fprintln(w, "LOCAL_USE_VNDK := true")
if c.isVndk() && !c.static() {
if c.IsVndk() && !c.static() {
fmt.Fprintln(w, "LOCAL_SOONG_VNDK_VERSION := "+c.vndkVersion())
}
}
@@ -224,7 +224,7 @@ func (library *libraryDecorator) AndroidMk(ctx AndroidMkContext, ret *android.An
})
}
if len(library.Properties.Stubs.Versions) > 0 &&
android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.inRecovery() && !ctx.useVndk() &&
android.DirectlyInAnyApex(ctx, ctx.Name()) && !ctx.InRecovery() && !ctx.UseVndk() &&
!ctx.static() {
if !library.buildStubs() {
ret.SubName = ".bootstrap"

583
cc/cc.go

File diff suppressed because it is too large Load Diff

View File

@@ -213,7 +213,7 @@ func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string
t.Helper()
mod := ctx.ModuleForTests(name, vendorVariant).Module().(*Module)
if !mod.hasVendorVariant() {
if !mod.HasVendorVariant() {
t.Errorf("%q must have vendor variant", name)
}
@@ -230,8 +230,8 @@ func checkVndkModule(t *testing.T, ctx *android.TestContext, name, subDir string
if mod.vndkdep == nil {
t.Fatalf("%q must have `vndkdep`", name)
}
if !mod.isVndk() {
t.Errorf("%q isVndk() must equal to true", name)
if !mod.IsVndk() {
t.Errorf("%q IsVndk() must equal to true", name)
}
if mod.isVndkSp() != isVndkSp {
t.Errorf("%q isVndkSp() must equal to %t", name, isVndkSp)

View File

@@ -245,7 +245,7 @@ func (s *fuzzPackager) GenerateBuildActions(ctx android.SingletonContext) {
// Discard vendor-NDK-linked modules, they're duplicates of fuzz targets
// we're going to package anyway.
if ccModule.useVndk() || !ccModule.Enabled() {
if ccModule.UseVndk() || !ccModule.Enabled() {
return
}

View File

@@ -1227,45 +1227,59 @@ func reuseStaticLibrary(mctx android.BottomUpMutatorContext, static, shared *Mod
}
func LinkageMutator(mctx android.BottomUpMutatorContext) {
cc_prebuilt := false
if m, ok := mctx.Module().(*Module); ok && m.linker != nil {
switch library := m.linker.(type) {
case prebuiltLibraryInterface:
// Always create both the static and shared variants for prebuilt libraries, and then disable the one
// that is not being used. This allows them to share the name of a cc_library module, which requires that
// all the variants of the cc_library also exist on the prebuilt.
modules := mctx.CreateLocalVariations("static", "shared")
static := modules[0].(*Module)
shared := modules[1].(*Module)
_, cc_prebuilt = m.linker.(prebuiltLibraryInterface)
}
if cc_prebuilt {
library := mctx.Module().(*Module).linker.(prebuiltLibraryInterface)
static.linker.(prebuiltLibraryInterface).setStatic()
shared.linker.(prebuiltLibraryInterface).setShared()
// Always create both the static and shared variants for prebuilt libraries, and then disable the one
// that is not being used. This allows them to share the name of a cc_library module, which requires that
// all the variants of the cc_library also exist on the prebuilt.
modules := mctx.CreateLocalVariations("static", "shared")
static := modules[0].(*Module)
shared := modules[1].(*Module)
if !library.buildStatic() {
static.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
if !library.buildShared() {
shared.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
static.linker.(prebuiltLibraryInterface).setStatic()
shared.linker.(prebuiltLibraryInterface).setShared()
case libraryInterface:
if library.buildStatic() && library.buildShared() {
modules := mctx.CreateLocalVariations("static", "shared")
static := modules[0].(*Module)
shared := modules[1].(*Module)
static.linker.(libraryInterface).setStatic()
shared.linker.(libraryInterface).setShared()
reuseStaticLibrary(mctx, static, shared)
} else if library.buildStatic() {
modules := mctx.CreateLocalVariations("static")
modules[0].(*Module).linker.(libraryInterface).setStatic()
} else if library.buildShared() {
modules := mctx.CreateLocalVariations("shared")
modules[0].(*Module).linker.(libraryInterface).setShared()
}
if !library.buildStatic() {
static.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
if !library.buildShared() {
shared.linker.(prebuiltLibraryInterface).disablePrebuilt()
}
} else if library, ok := mctx.Module().(LinkableInterface); ok && library.CcLibraryInterface() {
if library.BuildStaticVariant() && library.BuildSharedVariant() {
variations := []string{"static", "shared"}
// Non-cc.Modules need an empty variant for their mutators.
if _, ok := mctx.Module().(*Module); !ok {
variations = append(variations, "")
}
modules := mctx.CreateLocalVariations(variations...)
static := modules[0].(LinkableInterface)
shared := modules[1].(LinkableInterface)
static.SetStatic()
shared.SetShared()
if _, ok := library.(*Module); ok {
reuseStaticLibrary(mctx, static.(*Module), shared.(*Module))
}
} else if library.BuildStaticVariant() {
modules := mctx.CreateLocalVariations("static")
modules[0].(LinkableInterface).SetStatic()
} else if library.BuildSharedVariant() {
modules := mctx.CreateLocalVariations("shared")
modules[0].(LinkableInterface).SetShared()
} else if _, ok := mctx.Module().(*Module); !ok {
// Non-cc.Modules need an empty variant for their mutators.
mctx.CreateLocalVariations("")
}
}
}
@@ -1292,11 +1306,10 @@ func latestStubsVersionFor(config android.Config, name string) string {
// Version mutator splits a module into the mandatory non-stubs variant
// (which is unnamed) and zero or more stubs variants.
func VersionMutator(mctx android.BottomUpMutatorContext) {
if m, ok := mctx.Module().(*Module); ok && !m.inRecovery() && m.linker != nil {
if library, ok := m.linker.(*libraryDecorator); ok && library.buildShared() &&
len(library.Properties.Stubs.Versions) > 0 {
if library, ok := mctx.Module().(LinkableInterface); ok && !library.InRecovery() {
if library.CcLibrary() && library.BuildSharedVariant() && len(library.StubsVersions()) > 0 {
versions := []string{}
for _, v := range library.Properties.Stubs.Versions {
for _, v := range library.StubsVersions() {
if _, err := strconv.Atoi(v); err != nil {
mctx.PropertyErrorf("versions", "%q is not a number", v)
}
@@ -1320,14 +1333,9 @@ func VersionMutator(mctx android.BottomUpMutatorContext) {
modules := mctx.CreateVariations(versions...)
for i, m := range modules {
l := m.(*Module).linker.(*libraryDecorator)
if versions[i] != "" {
l.MutatedProperties.BuildStubs = true
l.MutatedProperties.StubsVersion = versions[i]
m.(*Module).Properties.HideFromMake = true
m.(*Module).sanitize = nil
m.(*Module).stl = nil
m.(*Module).Properties.PreventInstall = true
m.(LinkableInterface).SetBuildStubs()
m.(LinkableInterface).SetStubsVersions(versions[i])
}
}
} else {
@@ -1353,7 +1361,7 @@ func maybeInjectBoringSSLHash(ctx android.ModuleContext, outputFile android.Modu
injectBoringSSLHash := Bool(inject)
ctx.VisitDirectDeps(func(dep android.Module) {
tag := ctx.OtherModuleDependencyTag(dep)
if tag == staticDepTag || tag == staticExportDepTag || tag == wholeStaticDepTag || tag == lateStaticDepTag {
if tag == StaticDepTag || tag == staticExportDepTag || tag == wholeStaticDepTag || tag == lateStaticDepTag {
if cc, ok := dep.(*Module); ok {
if library, ok := cc.linker.(*libraryDecorator); ok {
if Bool(library.Properties.Inject_bssl_hash) {

71
cc/linkable.go Normal file
View File

@@ -0,0 +1,71 @@
package cc
import (
"github.com/google/blueprint"
"android/soong/android"
)
type LinkableInterface interface {
Module() android.Module
CcLibrary() bool
CcLibraryInterface() bool
OutputFile() android.OptionalPath
IncludeDirs(ctx android.BaseModuleContext) android.Paths
SetDepsInLinkOrder([]android.Path)
GetDepsInLinkOrder() []android.Path
HasStaticVariant() bool
GetStaticVariant() LinkableInterface
StubsVersions() []string
BuildStubs() bool
SetBuildStubs()
SetStubsVersions(string)
HasStubsVariants() bool
SelectedStl() string
ApiLevel() string
BuildStaticVariant() bool
BuildSharedVariant() bool
SetStatic()
SetShared()
Static() bool
Shared() bool
Toc() android.OptionalPath
InRecovery() bool
OnlyInRecovery() bool
UseVndk() bool
MustUseVendorVariant() bool
IsVndk() bool
HasVendorVariant() bool
SdkVersion() string
ToolchainLibrary() bool
NdkPrebuiltStl() bool
StubDecorator() bool
}
type DependencyTag struct {
blueprint.BaseDependencyTag
Name string
Library bool
Shared bool
ReexportFlags bool
ExplicitlyVersioned bool
}
var (
SharedDepTag = DependencyTag{Name: "shared", Library: true, Shared: true}
StaticDepTag = DependencyTag{Name: "static", Library: true}
CrtBeginDepTag = DependencyTag{Name: "crtbegin"}
CrtEndDepTag = DependencyTag{Name: "crtend"}
)

View File

@@ -148,7 +148,7 @@ func ltoDepsMutator(mctx android.TopDownMutatorContext) {
mctx.WalkDeps(func(dep android.Module, parent android.Module) bool {
tag := mctx.OtherModuleDependencyTag(dep)
switch tag {
case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag, objDepTag, reuseObjTag:
case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag, objDepTag, reuseObjTag:
if dep, ok := dep.(*Module); ok && dep.lto != nil &&
!dep.lto.Disabled() {
if full && !Bool(dep.lto.Properties.Lto.Full) {

View File

@@ -78,12 +78,12 @@ 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(mctx.Config())) ||
((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)
switch tag {
case staticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
case StaticDepTag, staticExportDepTag, lateStaticDepTag, wholeStaticDepTag:
cc, _ := m.(*Module)
if cc == nil {

View File

@@ -678,8 +678,8 @@ func (sanitize *sanitize) isSanitizerEnabled(t sanitizerType) bool {
}
func isSanitizableDependencyTag(tag blueprint.DependencyTag) bool {
t, ok := tag.(dependencyTag)
return ok && t.library || t == reuseObjTag || t == objDepTag
t, ok := tag.(DependencyTag)
return ok && t.Library || t == reuseObjTag || t == objDepTag
}
// Propagate sanitizer requirements down from binaries
@@ -873,7 +873,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
}
if mctx.Device() && runtimeLibrary != "" {
if inList(runtimeLibrary, *llndkLibraries(mctx.Config())) && !c.static() && c.useVndk() {
if inList(runtimeLibrary, *llndkLibraries(mctx.Config())) && !c.static() && c.UseVndk() {
runtimeLibrary = runtimeLibrary + llndkLibrarySuffix
}
@@ -889,7 +889,7 @@ func sanitizerRuntimeMutator(mctx android.BottomUpMutatorContext) {
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
{Mutator: "link", Variation: "static"},
{Mutator: "image", Variation: c.imageVariation()},
}...), staticDepTag, append([]string{runtimeLibrary}, extraStaticDeps...)...)
}...), StaticDepTag, append([]string{runtimeLibrary}, extraStaticDeps...)...)
} else if !c.static() && !c.header() {
// dynamic executable and shared libs get shared runtime libs
mctx.AddFarVariationDependencies(append(mctx.Target().Variations(), []blueprint.Variation{
@@ -963,7 +963,7 @@ func sanitizerMutator(t sanitizerType) func(android.BottomUpMutatorContext) {
if t == cfi {
appendStringSync(c.Name(), cfiStaticLibs(mctx.Config()), &cfiStaticLibsMutex)
} else if t == hwasan {
if c.useVndk() {
if c.UseVndk() {
appendStringSync(c.Name(), hwasanVendorStaticLibs(mctx.Config()),
&hwasanStaticLibsMutex)
} else {

View File

@@ -20,13 +20,13 @@ import (
"strconv"
)
func getNdkStlFamily(m *Module) string {
func getNdkStlFamily(m LinkableInterface) string {
family, _ := getNdkStlFamilyAndLinkType(m)
return family
}
func getNdkStlFamilyAndLinkType(m *Module) (string, string) {
stl := m.stl.Properties.SelectedStl
func getNdkStlFamilyAndLinkType(m LinkableInterface) (string, string) {
stl := m.SelectedStl()
switch stl {
case "ndk_libc++_shared":
return "libc++", "shared"

View File

@@ -98,7 +98,7 @@ func (vndk *vndkdep) typeName() string {
return "native:vendor:vndkspext"
}
func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag dependencyTag) {
func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, tag DependencyTag) {
if to.linker == nil {
return
}
@@ -125,7 +125,7 @@ func (vndk *vndkdep) vndkCheckLinkType(ctx android.ModuleContext, to *Module, ta
// Other (static and LL-NDK) libraries are allowed to link.
return
}
if !to.useVndk() {
if !to.UseVndk() {
ctx.ModuleErrorf("(%s) should not link to %q which is not a vendor-available library",
vndk.typeName(), to.Name())
return
@@ -352,7 +352,7 @@ func IsForVndkApex(mctx android.BottomUpMutatorContext, m *Module) bool {
useCoreVariant := m.vndkVersion() == mctx.DeviceConfig().PlatformVndkVersion() &&
mctx.DeviceConfig().VndkUseCoreVariant() &&
!inList(m.BaseModuleName(), config.VndkMustUseVendorVariantList)
return lib.shared() && m.useVndk() && m.isVndk() && !m.isVndkExt() && !useCoreVariant
return lib.shared() && m.UseVndk() && m.IsVndk() && !m.isVndkExt() && !useCoreVariant
}
return false
}
@@ -536,7 +536,7 @@ func (c *vndkSnapshotSingleton) GenerateBuildActions(ctx android.SingletonContex
if m.Target().NativeBridge == android.NativeBridgeEnabled {
return nil, "", false
}
if !m.useVndk() || !m.IsForPlatform() || !m.installable() {
if !m.UseVndk() || !m.IsForPlatform() || !m.installable() {
return nil, "", false
}
l, ok := m.linker.(vndkSnapshotLibraryInterface)
@@ -699,7 +699,7 @@ func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.Singleton
if c.isVndkPrivate(config) {
vndkprivate = append(vndkprivate, filename)
}
} else if c.vndkVersion() == vndkVersion && c.isVndk() && !c.isVndkExt() {
} else if c.vndkVersion() == vndkVersion && c.IsVndk() && !c.isVndkExt() {
if c.isVndkSp() {
vndksp = append(vndksp, filename)
} else {
@@ -708,7 +708,7 @@ func (c *vndkSnapshotSingleton) buildVndkLibrariesTxtFiles(ctx android.Singleton
if c.isVndkPrivate(config) {
vndkprivate = append(vndkprivate, filename)
}
if ctx.DeviceConfig().VndkUseCoreVariant() && !c.mustUseVendorVariant() {
if ctx.DeviceConfig().VndkUseCoreVariant() && !c.MustUseVendorVariant() {
vndkcorevariant = append(vndkcorevariant, filename)
}
}