Sdk snapshot set compile_multilib per OsType

Previously, when an sdk snapshot only supported a single os type the
compile_multilib was set based on the multilib usages by the members
of that variant. After the change to support multiple os types per
snapshot the multilib setting was based on the multilib usages across
all the members of all sdk variants. That meant that if one os type
used only "64" and the other used "both" then they would both be
treated as "both" leading to missing variants when the snapshot was
unpacked.

This change tracks the multilib usages per os type and adds a property
for each one.

It intentionally changes a couple of tests:
1) Either by adding compile_multilib that is missing.
2) By targeting it at a specific os type instead of host.

The latter change is important to prevent the snapshot from being
used on a host platform (which will match the host target section)
but which is a different os type to the ones supported by the
snapshot.

Bug: 142935992
Bug: 153306490
Test: m nothing
Merged-In: I883919b644292c3d019db223bb4fd5c11b39591f
Change-Id: I883919b644292c3d019db223bb4fd5c11b39591f
This commit is contained in:
Paul Duffin
2020-03-20 17:50:07 +00:00
parent 93520edca2
commit 2b5887a8f9
3 changed files with 43 additions and 28 deletions

View File

@@ -496,6 +496,11 @@ module_exports_snapshot {
device_supported: false, device_supported: false,
host_supported: true, host_supported: true,
native_binaries: ["myexports_mynativebinary@current"], native_binaries: ["myexports_mynativebinary@current"],
target: {
windows: {
compile_multilib: "64",
},
},
} }
`), `),
checkAllCopyRules(` checkAllCopyRules(`
@@ -956,6 +961,11 @@ sdk_snapshot {
device_supported: false, device_supported: false,
host_supported: true, host_supported: true,
native_shared_libs: ["mysdk_mynativelib@current"], native_shared_libs: ["mysdk_mynativelib@current"],
target: {
windows: {
compile_multilib: "64",
},
},
} }
`), `),
checkAllCopyRules(` checkAllCopyRules(`
@@ -1301,7 +1311,7 @@ module_exports_snapshot {
host_supported: true, host_supported: true,
native_static_libs: ["myexports_mynativelib@current"], native_static_libs: ["myexports_mynativelib@current"],
target: { target: {
host: { linux_glibc: {
compile_multilib: "64", compile_multilib: "64",
}, },
}, },

View File

@@ -52,11 +52,16 @@ type sdk struct {
// Information about the OsType specific member variants associated with this variant. // Information about the OsType specific member variants associated with this variant.
// //
// Set by OsType specific variants when their GenerateAndroidBuildActions is invoked // Set by OsType specific variants in the collectMembers() method and used by the
// and used by the CommonOS variant when its GenerateAndroidBuildActions is invoked, which // CommonOS variant when building the snapshot. That work is all done on separate
// is guaranteed to occur afterwards. // calls to the sdk.GenerateAndroidBuildActions method which is guaranteed to be
// called for the OsType specific variants before the CommonOS variant (because
// the latter depends on the former).
memberRefs []sdkMemberRef memberRefs []sdkMemberRef
// The multilib variants that are used by this sdk variant.
multilibUsages multilibUsage
properties sdkProperties properties sdkProperties
snapshotFile android.OptionalPath snapshotFile android.OptionalPath
@@ -259,8 +264,8 @@ func (s *sdk) GenerateAndroidBuildActions(ctx android.ModuleContext) {
// This method is guaranteed to be called on OsType specific variants before it is called // This method is guaranteed to be called on OsType specific variants before it is called
// on their corresponding CommonOS variant. // on their corresponding CommonOS variant.
if !s.IsCommonOSVariant() { if !s.IsCommonOSVariant() {
// Collect the OsType specific members are add them to the OsType specific variant. // Update the OsType specific sdk variant with information about its members.
s.memberRefs = s.collectMembers(ctx) s.collectMembers(ctx)
} else { } else {
// Get the OsType specific variants on which the CommonOS depends. // Get the OsType specific variants on which the CommonOS depends.
osSpecificVariants := android.GetOsSpecificVariantsOfCommonOSVariant(ctx) osSpecificVariants := android.GetOsSpecificVariantsOfCommonOSVariant(ctx)

View File

@@ -107,9 +107,10 @@ func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderC
// Collect all the members. // Collect all the members.
// //
// Returns a list containing type (extracted from the dependency tag) and the variant. // Returns a list containing type (extracted from the dependency tag) and the variant
func (s *sdk) collectMembers(ctx android.ModuleContext) []sdkMemberRef { // plus the multilib usages.
var memberRefs []sdkMemberRef func (s *sdk) collectMembers(ctx android.ModuleContext) {
s.multilibUsages = multilibNone
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 {
@@ -120,7 +121,10 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []sdkMemberRef {
ctx.ModuleErrorf("module %q is not valid in property %s", ctx.OtherModuleName(child), memberType.SdkPropertyName()) ctx.ModuleErrorf("module %q is not valid in property %s", ctx.OtherModuleName(child), memberType.SdkPropertyName())
} }
memberRefs = append(memberRefs, sdkMemberRef{memberType, child.(android.SdkAware)}) // Keep track of which multilib variants are used by the sdk.
s.multilibUsages = s.multilibUsages.addArchType(child.Target().Arch.ArchType)
s.memberRefs = append(s.memberRefs, sdkMemberRef{memberType, child.(android.SdkAware)})
// If the member type supports transitive sdk members then recurse down into // If the member type supports transitive sdk members then recurse down into
// its dependencies, otherwise exit traversal. // its dependencies, otherwise exit traversal.
@@ -129,8 +133,6 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []sdkMemberRef {
return false return false
}) })
return memberRefs
} }
// Organize the members. // Organize the members.
@@ -140,12 +142,10 @@ func (s *sdk) collectMembers(ctx android.ModuleContext) []sdkMemberRef {
// The names are in the order in which the dependencies were added. // The names are in the order in which the dependencies were added.
// //
// Returns the members as well as the multilib setting to use. // Returns the members as well as the multilib setting to use.
func (s *sdk) organizeMembers(ctx android.ModuleContext, memberRefs []sdkMemberRef) ([]*sdkMember, string) { func (s *sdk) organizeMembers(ctx android.ModuleContext, memberRefs []sdkMemberRef) []*sdkMember {
byType := make(map[android.SdkMemberType][]*sdkMember) byType := make(map[android.SdkMemberType][]*sdkMember)
byName := make(map[string]*sdkMember) byName := make(map[string]*sdkMember)
multilib := multilibNone
for _, memberRef := range memberRefs { for _, memberRef := range memberRefs {
memberType := memberRef.memberType memberType := memberRef.memberType
variant := memberRef.variant variant := memberRef.variant
@@ -158,8 +158,6 @@ func (s *sdk) organizeMembers(ctx android.ModuleContext, memberRefs []sdkMemberR
byType[memberType] = append(byType[memberType], member) byType[memberType] = append(byType[memberType], member)
} }
multilib = multilib.addArchType(variant.Target().Arch.ArchType)
// 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, variant) member.variants = appendUniqueVariants(member.variants, variant)
@@ -171,7 +169,7 @@ func (s *sdk) organizeMembers(ctx android.ModuleContext, memberRefs []sdkMemberR
members = append(members, membersOfType...) members = append(members, membersOfType...)
} }
return members, multilib.String() return members
} }
func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware { func appendUniqueVariants(variants []android.SdkAware, newVariant android.SdkAware) []android.SdkAware {
@@ -251,7 +249,7 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
} }
s.builderForTests = builder s.builderForTests = builder
members, multilib := s.organizeMembers(ctx, memberRefs) members := s.organizeMembers(ctx, memberRefs)
for _, member := range members { for _, member := range members {
memberType := member.memberType memberType := member.memberType
@@ -303,15 +301,6 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
addHostDeviceSupportedProperties(s.ModuleBase.DeviceSupported(), s.ModuleBase.HostSupported(), snapshotModule) addHostDeviceSupportedProperties(s.ModuleBase.DeviceSupported(), s.ModuleBase.HostSupported(), 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.
targetPropertySet := snapshotModule.AddPropertySet("target")
if s.HostSupported() && multilib != "" && multilib != "both" {
hostSet := targetPropertySet.AddPropertySet("host")
hostSet.AddProperty("compile_multilib", multilib)
}
var dynamicMemberPropertiesList []interface{} var dynamicMemberPropertiesList []interface{}
osTypeToMemberProperties := make(map[android.OsType]*sdk) osTypeToMemberProperties := make(map[android.OsType]*sdk)
for _, sdkVariant := range sdkVariants { for _, sdkVariant := range sdkVariants {
@@ -329,9 +318,20 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
s.addMemberPropertiesToPropertySet(builder, snapshotModule, commonDynamicMemberProperties) s.addMemberPropertiesToPropertySet(builder, snapshotModule, commonDynamicMemberProperties)
// Iterate over the os types in a fixed order. // Iterate over the os types in a fixed order.
targetPropertySet := snapshotModule.AddPropertySet("target")
for _, osType := range s.getPossibleOsTypes() { for _, osType := range s.getPossibleOsTypes() {
if sdkVariant, ok := osTypeToMemberProperties[osType]; ok { if sdkVariant, ok := osTypeToMemberProperties[osType]; ok {
osPropertySet := targetPropertySet.AddPropertySet(sdkVariant.Target().Os.Name) osPropertySet := targetPropertySet.AddPropertySet(sdkVariant.Target().Os.Name)
// 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.
multilib := sdkVariant.multilibUsages
if (osType.Class == android.Host || osType.Class == android.HostCross) &&
multilib != multilibNone && multilib != multilibBoth {
osPropertySet.AddProperty("compile_multilib", multilib.String())
}
s.addMemberPropertiesToPropertySet(builder, osPropertySet, sdkVariant.dynamicMemberTypeListProperties) s.addMemberPropertiesToPropertySet(builder, osPropertySet, sdkVariant.dynamicMemberTypeListProperties)
} }
} }