Merge changes I025ee90e,I2a9e0327
* changes: Extract the osTypeSpecificInfo code from module creation loop Extract archTypeSpecificInfo code from module creation loop
This commit is contained in:
commit
2812418eac
209
sdk/update.go
209
sdk/update.go
|
@ -793,66 +793,32 @@ type baseInfo struct {
|
|||
type osTypeSpecificInfo struct {
|
||||
baseInfo
|
||||
|
||||
osType android.OsType
|
||||
|
||||
// The list of arch type specific info for this os type.
|
||||
//
|
||||
// Nil if there is one variant whose arch type is common
|
||||
archInfos []*archTypeSpecificInfo
|
||||
}
|
||||
|
||||
type archTypeSpecificInfo struct {
|
||||
baseInfo
|
||||
type variantPropertiesFactoryFunc func() android.SdkMemberProperties
|
||||
|
||||
archType android.ArchType
|
||||
}
|
||||
|
||||
func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, builder *snapshotBuilder, member *sdkMember, bpModule android.BpModule) {
|
||||
|
||||
memberType := member.memberType
|
||||
|
||||
// Group the variants by os type.
|
||||
variantsByOsType := make(map[android.OsType][]android.SdkAware)
|
||||
variants := member.Variants()
|
||||
for _, variant := range variants {
|
||||
osType := variant.Target().Os
|
||||
variantsByOsType[osType] = append(variantsByOsType[osType], variant)
|
||||
// Create a new osTypeSpecificInfo for the specified os type and its properties
|
||||
// structures populated with information from the variants.
|
||||
func newOsTypeSpecificInfo(osType android.OsType, variantPropertiesFactory variantPropertiesFactoryFunc, osTypeVariants []android.SdkAware) *osTypeSpecificInfo {
|
||||
osInfo := &osTypeSpecificInfo{
|
||||
osType: osType,
|
||||
}
|
||||
|
||||
osCount := len(variantsByOsType)
|
||||
variantPropertiesFactory := func() android.SdkMemberProperties {
|
||||
properties := memberType.CreateVariantPropertiesStruct()
|
||||
base := properties.Base()
|
||||
base.Os_count = osCount
|
||||
return properties
|
||||
}
|
||||
|
||||
osTypeToInfo := make(map[android.OsType]*osTypeSpecificInfo)
|
||||
|
||||
// The set of properties that are common across all architectures and os types.
|
||||
commonProperties := variantPropertiesFactory()
|
||||
commonProperties.Base().Os = android.CommonOS
|
||||
|
||||
// Create common value extractor that can be used to optimize the properties.
|
||||
commonValueExtractor := newCommonValueExtractor(commonProperties)
|
||||
|
||||
// The list of property structures which are os type specific but common across
|
||||
// architectures within that os type.
|
||||
var osSpecificPropertiesList []android.SdkMemberProperties
|
||||
|
||||
for osType, osTypeVariants := range variantsByOsType {
|
||||
// Group the properties for each variant by arch type within the os.
|
||||
osInfo := &osTypeSpecificInfo{}
|
||||
osTypeToInfo[osType] = osInfo
|
||||
|
||||
osSpecificVariantPropertiesFactory := func() android.SdkMemberProperties {
|
||||
properties := variantPropertiesFactory()
|
||||
properties.Base().Os = osType
|
||||
return properties
|
||||
}
|
||||
|
||||
// Add the os specific properties to a list of os type specific yet architecture
|
||||
// independent properties structs.
|
||||
// Create a structure into which properties common across the architectures in
|
||||
// this os type will be stored.
|
||||
osInfo.Properties = osSpecificVariantPropertiesFactory()
|
||||
osSpecificPropertiesList = append(osSpecificPropertiesList, osInfo.Properties)
|
||||
|
||||
// Group the variants by arch type.
|
||||
var variantsByArchName = make(map[string][]android.SdkAware)
|
||||
|
@ -881,22 +847,23 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build
|
|||
archTypeName := archType.Name
|
||||
|
||||
archVariants := variantsByArchName[archTypeName]
|
||||
if len(archVariants) != 1 {
|
||||
panic(fmt.Errorf("expected one arch specific variant but found %d", len(variants)))
|
||||
}
|
||||
|
||||
// Create an arch specific info into which the variant properties can be copied.
|
||||
archInfo := &archTypeSpecificInfo{archType: archType}
|
||||
|
||||
// Create the properties into which the arch type specific properties will be
|
||||
// added.
|
||||
archInfo.Properties = osSpecificVariantPropertiesFactory()
|
||||
archInfo.Properties.PopulateFromVariant(archVariants[0])
|
||||
archInfo := newArchSpecificInfo(archType, osSpecificVariantPropertiesFactory, archVariants)
|
||||
|
||||
osInfo.archInfos = append(osInfo.archInfos, archInfo)
|
||||
}
|
||||
}
|
||||
|
||||
return osInfo
|
||||
}
|
||||
|
||||
// Optimize the properties by extracting common properties from arch type specific
|
||||
// properties into os type specific properties.
|
||||
func (osInfo *osTypeSpecificInfo) optimizeProperties(commonValueExtractor *commonValueExtractor) {
|
||||
// Nothing to do if there is only a single common architecture.
|
||||
if len(osInfo.archInfos) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var archPropertiesList []android.SdkMemberProperties
|
||||
for _, archInfo := range osInfo.archInfos {
|
||||
archPropertiesList = append(archPropertiesList, archInfo.Properties)
|
||||
|
@ -918,24 +885,17 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build
|
|||
}
|
||||
|
||||
osInfo.Properties.Base().Compile_multilib = multilib
|
||||
}
|
||||
}
|
||||
|
||||
// Extract properties which are common across all architectures and os types.
|
||||
commonValueExtractor.extractCommonProperties(commonProperties, osSpecificPropertiesList)
|
||||
|
||||
// Add the common properties to the module.
|
||||
commonProperties.AddToPropertySet(sdkModuleContext, builder, bpModule)
|
||||
|
||||
// Create a target property set into which target specific properties can be
|
||||
// added.
|
||||
targetPropertySet := bpModule.AddPropertySet("target")
|
||||
|
||||
// Iterate over the os types in a fixed order.
|
||||
for _, osType := range s.getPossibleOsTypes() {
|
||||
osInfo := osTypeToInfo[osType]
|
||||
if osInfo == nil {
|
||||
continue
|
||||
}
|
||||
// Add the properties for an os to a property set.
|
||||
//
|
||||
// Maps the properties related to the os variants through to an appropriate
|
||||
// module structure that will produce equivalent set of variants when it is
|
||||
// processed in a build.
|
||||
func (osInfo *osTypeSpecificInfo) addToPropertySet(
|
||||
builder *snapshotBuilder,
|
||||
bpModule android.BpModule,
|
||||
targetPropertySet android.BpPropertySet) {
|
||||
|
||||
var osPropertySet android.BpPropertySet
|
||||
var archPropertySet android.BpPropertySet
|
||||
|
@ -975,6 +935,7 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build
|
|||
// <arch and os specific sections, e.g. android_x86>
|
||||
// }
|
||||
//
|
||||
osType := osInfo.osType
|
||||
osPropertySet = targetPropertySet.AddPropertySet(osType.Name)
|
||||
archPropertySet = targetPropertySet
|
||||
|
||||
|
@ -983,17 +944,113 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build
|
|||
archOsPrefix = osType.Name + "_"
|
||||
}
|
||||
|
||||
osInfo.Properties.AddToPropertySet(sdkModuleContext, builder, osPropertySet)
|
||||
// Add the os specific but arch independent properties to the module.
|
||||
osInfo.Properties.AddToPropertySet(builder.ctx, builder, osPropertySet)
|
||||
|
||||
// Add arch (and possibly os) specific sections for each set of arch (and possibly
|
||||
// os) specific properties.
|
||||
//
|
||||
// The archInfos list will be empty if the os contains variants for the common
|
||||
// architecture.
|
||||
for _, archInfo := range osInfo.archInfos {
|
||||
archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archInfo.archType.Name)
|
||||
|
||||
archInfo.Properties.AddToPropertySet(sdkModuleContext, builder, archTypePropertySet)
|
||||
archInfo.addToPropertySet(builder, archPropertySet, archOsPrefix)
|
||||
}
|
||||
}
|
||||
|
||||
type archTypeSpecificInfo struct {
|
||||
baseInfo
|
||||
|
||||
archType android.ArchType
|
||||
}
|
||||
|
||||
// Create a new archTypeSpecificInfo for the specified arch type and its properties
|
||||
// structures populated with information from the variants.
|
||||
func newArchSpecificInfo(archType android.ArchType, variantPropertiesFactory variantPropertiesFactoryFunc, archVariants []android.SdkAware) *archTypeSpecificInfo {
|
||||
|
||||
if len(archVariants) != 1 {
|
||||
panic(fmt.Errorf("expected one arch specific variant but found %d", len(archVariants)))
|
||||
}
|
||||
|
||||
// Create an arch specific info into which the variant properties can be copied.
|
||||
archInfo := &archTypeSpecificInfo{archType: archType}
|
||||
|
||||
// Create the properties into which the arch type specific properties will be
|
||||
// added.
|
||||
archInfo.Properties = variantPropertiesFactory()
|
||||
archInfo.Properties.PopulateFromVariant(archVariants[0])
|
||||
|
||||
return archInfo
|
||||
}
|
||||
|
||||
// Add the properties for an arch type to a property set.
|
||||
func (archInfo *archTypeSpecificInfo) addToPropertySet(builder *snapshotBuilder, archPropertySet android.BpPropertySet, archOsPrefix string) {
|
||||
archTypeName := archInfo.archType.Name
|
||||
archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName)
|
||||
archInfo.Properties.AddToPropertySet(builder.ctx, builder, archTypePropertySet)
|
||||
}
|
||||
|
||||
func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, builder *snapshotBuilder, member *sdkMember, bpModule android.BpModule) {
|
||||
|
||||
memberType := member.memberType
|
||||
|
||||
// Group the variants by os type.
|
||||
variantsByOsType := make(map[android.OsType][]android.SdkAware)
|
||||
variants := member.Variants()
|
||||
for _, variant := range variants {
|
||||
osType := variant.Target().Os
|
||||
variantsByOsType[osType] = append(variantsByOsType[osType], variant)
|
||||
}
|
||||
|
||||
osCount := len(variantsByOsType)
|
||||
variantPropertiesFactory := func() android.SdkMemberProperties {
|
||||
properties := memberType.CreateVariantPropertiesStruct()
|
||||
base := properties.Base()
|
||||
base.Os_count = osCount
|
||||
return properties
|
||||
}
|
||||
|
||||
osTypeToInfo := make(map[android.OsType]*osTypeSpecificInfo)
|
||||
|
||||
// The set of properties that are common across all architectures and os types.
|
||||
commonProperties := variantPropertiesFactory()
|
||||
commonProperties.Base().Os = android.CommonOS
|
||||
|
||||
// Create common value extractor that can be used to optimize the properties.
|
||||
commonValueExtractor := newCommonValueExtractor(commonProperties)
|
||||
|
||||
// The list of property structures which are os type specific but common across
|
||||
// architectures within that os type.
|
||||
var osSpecificPropertiesList []android.SdkMemberProperties
|
||||
|
||||
for osType, osTypeVariants := range variantsByOsType {
|
||||
osInfo := newOsTypeSpecificInfo(osType, variantPropertiesFactory, osTypeVariants)
|
||||
osTypeToInfo[osType] = osInfo
|
||||
// Add the os specific properties to a list of os type specific yet architecture
|
||||
// independent properties structs.
|
||||
osSpecificPropertiesList = append(osSpecificPropertiesList, osInfo.Properties)
|
||||
|
||||
// Optimize the properties across all the variants for a specific os type.
|
||||
osInfo.optimizeProperties(commonValueExtractor)
|
||||
}
|
||||
|
||||
// Extract properties which are common across all architectures and os types.
|
||||
commonValueExtractor.extractCommonProperties(commonProperties, osSpecificPropertiesList)
|
||||
|
||||
// Add the common properties to the module.
|
||||
commonProperties.AddToPropertySet(sdkModuleContext, builder, bpModule)
|
||||
|
||||
// Create a target property set into which target specific properties can be
|
||||
// added.
|
||||
targetPropertySet := bpModule.AddPropertySet("target")
|
||||
|
||||
// Iterate over the os types in a fixed order.
|
||||
for _, osType := range s.getPossibleOsTypes() {
|
||||
osInfo := osTypeToInfo[osType]
|
||||
if osInfo == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
osInfo.addToPropertySet(builder, bpModule, targetPropertySet)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue