Enable sdk and sdk members in os_arch granularity

This amends Idad7ef138cdbcbd209d390bf6c10ca8365d4619f. With the change,
when there is a member that returns IsHostOsDependent() == true,
the sdk having the member and the member itself are disable for host and
only the os that the member supports is explicitly enabled.

However, that change will cause a problem when we add the support for
the linux_bionic_arm64 target. The target is not enabled when building
sdk snapshots. The only linux_bionic target that is enabled is
'linux_bionic_x86_64'. However, since the granularity is os which is
linux_bionic, the snapshot is generated as follows.

cc_prebuilt_binary {
    target: {
        host: {
	    enabled: false,
	},
	linux_bionic: {
            enabled: true,
        },
	linux_bionic_x86_64: {
            srcs: ["x86_64/bin/..."],
	},
	// no srcs for linux_bionic_arm64
    },
}

Above is a problem for linux_bionic_arm64 target because the target is
enabled (via linux_bionic.enabled: true), but srcs is not provided.

To fix the problem, the enabling of a target is done in a target
(os_arch) granularity, rather than os granularity. For example, above
now becomes ...

cc_prebuilt_binary {
    target: {
        host: {
	    enabled: false,
	},
	linux_bionic_x86_64: {
            enabled: true,
            srcs: ["x86_64/bin/..."],
	},
    },
}

Only the targets that the snapshot actually can provide srcs are enabled
and the rest of the host targets are disabled.

Bug: 159685774
Test: m nothing
Test: build/soong/scripts/build-aml-prebuilts.sh
runtime-module-host-exports

Change-Id: Ibca48c40f6dc4628b5f4bfa4ceb68ebe0973cc81
This commit is contained in:
Jiyong Park
2020-10-19 22:47:34 +09:00
parent faf30e19d6
commit 8fe14e6a49
2 changed files with 148 additions and 120 deletions

View File

@@ -347,34 +347,11 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
targetPropertySet := snapshotModule.AddPropertySet("target")
// If host is supported and any member is host OS dependent then disable host
// by default, so that we can enable each host OS variant explicitly. This
// avoids problems with implicitly enabled OS variants when the snapshot is
// used, which might be different from this run (e.g. different build OS).
hasHostOsDependentMember := false
if s.HostSupported() {
for _, memberRef := range memberRefs {
if memberRef.memberType.IsHostOsDependent() {
hasHostOsDependentMember = true
break
}
}
if hasHostOsDependentMember {
hostPropertySet := targetPropertySet.AddPropertySet("host")
hostPropertySet.AddProperty("enabled", false)
}
}
// Iterate over the os types in a fixed order.
for _, osType := range s.getPossibleOsTypes() {
if sdkVariant, ok := osTypeToMemberProperties[osType]; ok {
osPropertySet := targetPropertySet.AddPropertySet(sdkVariant.Target().Os.Name)
// Enable the variant explicitly when we've disabled it by default on host.
if hasHostOsDependentMember && osType.Class == android.Host {
osPropertySet.AddProperty("enabled", true)
}
variantProps := variantToProperties[sdkVariant]
if variantProps.Compile_multilib != "" && variantProps.Compile_multilib != "both" {
osPropertySet.AddProperty("compile_multilib", variantProps.Compile_multilib)
@@ -384,6 +361,31 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
}
}
// If host is supported and any member is host OS dependent then disable host
// by default, so that we can enable each host OS variant explicitly. This
// avoids problems with implicitly enabled OS variants when the snapshot is
// used, which might be different from this run (e.g. different build OS).
if s.HostSupported() {
var supportedHostTargets []string
for _, memberRef := range memberRefs {
if memberRef.memberType.IsHostOsDependent() && memberRef.variant.Target().Os.Class == android.Host {
targetString := memberRef.variant.Target().Os.String() + "_" + memberRef.variant.Target().Arch.ArchType.String()
if !android.InList(targetString, supportedHostTargets) {
supportedHostTargets = append(supportedHostTargets, targetString)
}
}
}
if len(supportedHostTargets) > 0 {
hostPropertySet := targetPropertySet.AddPropertySet("host")
hostPropertySet.AddProperty("enabled", false)
}
// Enable the <os>_<arch> variant explicitly when we've disabled it by default on host.
for _, hostTarget := range supportedHostTargets {
propertySet := targetPropertySet.AddPropertySet(hostTarget)
propertySet.AddProperty("enabled", true)
}
}
// Prune any empty property sets.
snapshotModule.transform(pruneEmptySetTransformer{})
@@ -984,7 +986,7 @@ func newOsTypeSpecificInfo(ctx android.SdkMemberContext, osType android.OsType,
archTypeName := archType.Name
archVariants := variantsByArchName[archTypeName]
archInfo := newArchSpecificInfo(ctx, archType, osSpecificVariantPropertiesFactory, archVariants)
archInfo := newArchSpecificInfo(ctx, archType, osType, osSpecificVariantPropertiesFactory, archVariants)
osInfo.archInfos = append(osInfo.archInfos, archInfo)
}
@@ -1067,11 +1069,6 @@ func (osInfo *osTypeSpecificInfo) addToPropertySet(ctx *memberContext, bpModule
osPropertySet = targetPropertySet.AddPropertySet(osType.Name)
archPropertySet = targetPropertySet
// Enable the variant explicitly when we've disabled it by default on host.
if ctx.memberType.IsHostOsDependent() && osType.Class == android.Host {
osPropertySet.AddProperty("enabled", true)
}
// Arch specific properties need to be added to an os and arch specific
// section prefixed with <os>_.
archOsPrefix = osType.Name + "_"
@@ -1105,6 +1102,7 @@ type archTypeSpecificInfo struct {
baseInfo
archType android.ArchType
osType android.OsType
linkInfos []*linkTypeSpecificInfo
}
@@ -1113,10 +1111,10 @@ var _ propertiesContainer = (*archTypeSpecificInfo)(nil)
// Create a new archTypeSpecificInfo for the specified arch type and its properties
// structures populated with information from the variants.
func newArchSpecificInfo(ctx android.SdkMemberContext, archType android.ArchType, variantPropertiesFactory variantPropertiesFactoryFunc, archVariants []android.Module) *archTypeSpecificInfo {
func newArchSpecificInfo(ctx android.SdkMemberContext, archType android.ArchType, osType android.OsType, variantPropertiesFactory variantPropertiesFactoryFunc, archVariants []android.Module) *archTypeSpecificInfo {
// Create an arch specific info into which the variant properties can be copied.
archInfo := &archTypeSpecificInfo{archType: archType}
archInfo := &archTypeSpecificInfo{archType: archType, osType: osType}
// Create the properties into which the arch type specific properties will be
// added.
@@ -1180,6 +1178,10 @@ func (archInfo *archTypeSpecificInfo) optimizeProperties(ctx *memberContext, com
func (archInfo *archTypeSpecificInfo) addToPropertySet(ctx *memberContext, archPropertySet android.BpPropertySet, archOsPrefix string) {
archTypeName := archInfo.archType.Name
archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName)
// Enable the <os>_<arch> variant explicitly when we've disabled it by default on host.
if ctx.memberType.IsHostOsDependent() && archInfo.osType.Class == android.Host {
archTypePropertySet.AddProperty("enabled", true)
}
addSdkMemberPropertiesToSet(ctx, archInfo.Properties, archTypePropertySet)
for _, linkInfo := range archInfo.linkInfos {