Allow compile_multilib to be specified on module exports

This is needed to allow the art-host-module-exports to restrict itself
to just managing the linux 64 bit version of the host tools as that is
the only variant that is currently supported by all host tools. This
greatly simplifies that process and allows us to make progress on the
unbundling.

Bug: 142935992
Test: m nothing
Change-Id: I62d016d97c2df73e5feecf912638f477fedd97c9
This commit is contained in:
Paul Duffin 2020-02-19 16:19:27 +00:00
parent a0d58893fc
commit 13ad94fce2
3 changed files with 145 additions and 5 deletions

View File

@ -16,6 +16,7 @@ package cc
import ( import (
"path/filepath" "path/filepath"
"strings"
"android/soong/android" "android/soong/android"
"github.com/google/blueprint" "github.com/google/blueprint"
@ -98,7 +99,23 @@ func (mt *binarySdkMemberType) organizeVariants(member android.SdkMember) *nativ
func buildSharedNativeBinarySnapshot(info *nativeBinaryInfo, builder android.SnapshotBuilder, member android.SdkMember) { func buildSharedNativeBinarySnapshot(info *nativeBinaryInfo, builder android.SnapshotBuilder, member android.SdkMember) {
pbm := builder.AddPrebuiltModule(member, "cc_prebuilt_binary") pbm := builder.AddPrebuiltModule(member, "cc_prebuilt_binary")
pbm.AddProperty("compile_multilib", "both") archVariantCount := len(info.archVariantProperties)
// Choose setting for compile_multilib that is appropriate for the arch variants supplied.
var multilib string
if archVariantCount == 2 {
multilib = "both"
} else if archVariantCount == 1 {
if strings.HasSuffix(info.archVariantProperties[0].archType, "64") {
multilib = "64"
} else {
multilib = "32"
}
}
if multilib != "" {
pbm.AddProperty("compile_multilib", multilib)
}
archProperties := pbm.AddPropertySet("arch") archProperties := pbm.AddPropertySet("arch")
for _, av := range info.archVariantProperties { for _, av := range info.archVariantProperties {
archTypeProperties := archProperties.AddPropertySet(av.archType) archTypeProperties := archProperties.AddPropertySet(av.archType)

View File

@ -749,3 +749,94 @@ include/Test.h -> include/include/Test.h
`), `),
) )
} }
func TestHostSnapshotWithMultiLib64(t *testing.T) {
// b/145598135 - Generating host snapshots for anything other than linux is not supported.
SkipIfNotLinux(t)
result := testSdkWithCc(t, `
module_exports {
name: "myexports",
device_supported: false,
host_supported: true,
target: {
host: {
compile_multilib: "64",
},
},
native_static_libs: ["mynativelib"],
}
cc_library_static {
name: "mynativelib",
device_supported: false,
host_supported: true,
srcs: [
"Test.cpp",
"aidl/foo/bar/Test.aidl",
],
export_include_dirs: ["include"],
aidl: {
export_aidl_headers: true,
},
system_shared_libs: [],
stl: "none",
}
`)
result.CheckSnapshot("myexports", "linux_glibc_common", "",
checkAndroidBpContents(`
// This is auto-generated. DO NOT EDIT.
cc_prebuilt_library_static {
name: "myexports_mynativelib@current",
sdk_member_name: "mynativelib",
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
},
stl: "none",
system_shared_libs: [],
}
cc_prebuilt_library_static {
name: "mynativelib",
prefer: false,
device_supported: false,
host_supported: true,
export_include_dirs: ["include/include"],
arch: {
x86_64: {
srcs: ["x86_64/lib/mynativelib.a"],
export_include_dirs: ["x86_64/include_gen/mynativelib"],
},
},
stl: "none",
system_shared_libs: [],
}
module_exports_snapshot {
name: "myexports@current",
device_supported: false,
host_supported: true,
target: {
host: {
compile_multilib: "64",
},
},
native_static_libs: ["myexports_mynativelib@current"],
}`),
checkAllCopyRules(`
include/Test.h -> include/include/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_static/mynativelib.a -> x86_64/lib/mynativelib.a
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/Test.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/Test.h
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BnTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BnTest.h
.intermediates/mynativelib/linux_glibc_x86_64_static/gen/aidl/aidl/foo/bar/BpTest.h -> x86_64/include_gen/mynativelib/aidl/foo/bar/BpTest.h
`),
)
}

View File

@ -107,10 +107,15 @@ func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderC
// The members are first grouped by type and then grouped by name. The order of // The members are first grouped by type and then grouped by name. The order of
// the types is the order they are referenced in android.SdkMemberTypesRegistry. // the types is the order they are referenced in android.SdkMemberTypesRegistry.
// The names are in the order in which the dependencies were added. // The names are in the order in which the dependencies were added.
func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember { //
// Returns the members as well as the multilib setting to use.
func (s *sdk) collectMembers(ctx android.ModuleContext) ([]*sdkMember, string) {
byType := make(map[android.SdkMemberType][]*sdkMember) byType := make(map[android.SdkMemberType][]*sdkMember)
byName := make(map[string]*sdkMember) byName := make(map[string]*sdkMember)
lib32 := false // True if any of the members have 32 bit version.
lib64 := false // True if any of the members have 64 bit version.
ctx.WalkDeps(func(child android.Module, parent android.Module) bool { ctx.WalkDeps(func(child android.Module, parent android.Module) bool {
tag := ctx.OtherModuleDependencyTag(child) tag := ctx.OtherModuleDependencyTag(child)
if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok { if memberTag, ok := tag.(android.SdkMemberTypeDependencyTag); ok {
@ -122,7 +127,6 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
} }
name := ctx.OtherModuleName(child) name := ctx.OtherModuleName(child)
member := byName[name] member := byName[name]
if member == nil { if member == nil {
member = &sdkMember{memberType: memberType, name: name} member = &sdkMember{memberType: memberType, name: name}
@ -130,6 +134,13 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
byType[memberType] = append(byType[memberType], member) byType[memberType] = append(byType[memberType], member)
} }
multilib := child.Target().Arch.ArchType.Multilib
if multilib == "lib32" {
lib32 = true
} else if multilib == "lib64" {
lib64 = true
}
// Only append new variants to the list. This is needed because a member can be both // Only append new variants to the list. This is needed because a member can be both
// exported by the sdk and also be a transitive sdk member. // exported by the sdk and also be a transitive sdk member.
member.variants = appendUniqueVariants(member.variants, child.(android.SdkAware)) member.variants = appendUniqueVariants(member.variants, child.(android.SdkAware))
@ -148,7 +159,17 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []*sdkMember {
members = append(members, membersOfType...) members = append(members, membersOfType...)
} }
return members // Compute the setting of multilib.
var multilib string
if lib32 && lib64 {
multilib = "both"
} else if lib32 {
multilib = "32"
} else if lib64 {
multilib = "64"
}
return members, multilib
} }
func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware { func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware {
@ -207,7 +228,8 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
} }
s.builderForTests = builder s.builderForTests = builder
for _, member := range s.collectMembers(ctx) { members, multilib := s.collectMembers(ctx)
for _, member := range members {
member.memberType.BuildSnapshot(ctx, builder, member) member.memberType.BuildSnapshot(ctx, builder, member)
} }
@ -249,6 +271,16 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext) android.OutputPath {
} }
addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule) addHostDeviceSupportedProperties(&s.ModuleBase, snapshotModule)
// Compile_multilib defaults to both and must always be set to both on the
// device and so only needs to be set when targeted at the host and is neither
// unspecified or both.
if s.HostSupported() && multilib != "" && multilib != "both" {
targetSet := snapshotModule.AddPropertySet("target")
hostSet := targetSet.AddPropertySet("host")
hostSet.AddProperty("compile_multilib", multilib)
}
for _, memberListProperty := range s.memberListProperties() { for _, memberListProperty := range s.memberListProperties() {
names := memberListProperty.getter(s.dynamicMemberTypeListProperties) names := memberListProperty.getter(s.dynamicMemberTypeListProperties)
if len(names) > 0 { if len(names) > 0 {