Make new module creation API more flexible am: 3a4eb50829

Change-Id: Icd9cc9d6de27417450dec1b31cb5b0059593b209
This commit is contained in:
Paul Duffin
2020-03-23 11:09:27 +00:00
committed by Automerger Merge Worker
5 changed files with 77 additions and 49 deletions

View File

@@ -357,7 +357,7 @@ type SdkMemberType interface {
// structure and calls AddToPropertySet(...) on the properties struct to add the member // structure and calls AddToPropertySet(...) on the properties struct to add the member
// specific properties in the correct place in the structure. // specific properties in the correct place in the structure.
// //
AddPrebuiltModule(sdkModuleContext ModuleContext, builder SnapshotBuilder, member SdkMember) BpModule AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule
// Create a structure into which variant specific properties can be added. // Create a structure into which variant specific properties can be added.
CreateVariantPropertiesStruct() SdkMemberProperties CreateVariantPropertiesStruct() SdkMemberProperties
@@ -386,7 +386,7 @@ func (b *SdkMemberTypeBase) BuildSnapshot(sdkModuleContext ModuleContext, builde
panic("override AddPrebuiltModule") panic("override AddPrebuiltModule")
} }
func (b *SdkMemberTypeBase) AddPrebuiltModule(sdkModuleContext ModuleContext, builder SnapshotBuilder, member SdkMember) BpModule { func (b *SdkMemberTypeBase) AddPrebuiltModule(ctx SdkMemberContext, member SdkMember) BpModule {
// Returning nil causes the legacy BuildSnapshot method to be used. // Returning nil causes the legacy BuildSnapshot method to be used.
return nil return nil
} }
@@ -501,9 +501,19 @@ type SdkMemberProperties interface {
// Access the base structure. // Access the base structure.
Base() *SdkMemberPropertiesBase Base() *SdkMemberPropertiesBase
// Populate the structure with information from the variant. // Populate this structure with information from the variant.
PopulateFromVariant(variant SdkAware) PopulateFromVariant(ctx SdkMemberContext, variant Module)
// Add the information from the structure to the property set. // Add the information from this structure to the property set.
AddToPropertySet(sdkModuleContext ModuleContext, builder SnapshotBuilder, propertySet BpPropertySet) AddToPropertySet(ctx SdkMemberContext, propertySet BpPropertySet)
}
// Provides access to information common to a specific member.
type SdkMemberContext interface {
// The module context of the sdk common os variant which is creating the snapshot.
SdkModuleContext() ModuleContext
// The builder of the snapshot.
SnapshotBuilder() SnapshotBuilder
} }

View File

@@ -63,9 +63,8 @@ func (mt *binarySdkMemberType) IsInstance(module android.Module) bool {
return false return false
} }
func (mt *binarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { func (mt *binarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
pbm := builder.AddPrebuiltModule(member, "cc_prebuilt_binary") return ctx.SnapshotBuilder().AddPrebuiltModule(member, "cc_prebuilt_binary")
return pbm
} }
func (mt *binarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { func (mt *binarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
@@ -107,7 +106,7 @@ type nativeBinaryInfoProperties struct {
SystemSharedLibs []string SystemSharedLibs []string
} }
func (p *nativeBinaryInfoProperties) PopulateFromVariant(variant android.SdkAware) { func (p *nativeBinaryInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
ccModule := variant.(*Module) ccModule := variant.(*Module)
p.archType = ccModule.Target().Arch.ArchType.String() p.archType = ccModule.Target().Arch.ArchType.String()
@@ -122,11 +121,12 @@ func (p *nativeBinaryInfoProperties) PopulateFromVariant(variant android.SdkAwar
} }
} }
func (p *nativeBinaryInfoProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { func (p *nativeBinaryInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
if p.Compile_multilib != "" { if p.Compile_multilib != "" {
propertySet.AddProperty("compile_multilib", p.Compile_multilib) propertySet.AddProperty("compile_multilib", p.Compile_multilib)
} }
builder := ctx.SnapshotBuilder()
if p.outputFile != nil { if p.outputFile != nil {
propertySet.AddProperty("srcs", []string{nativeBinaryPathFor(*p)}) propertySet.AddProperty("srcs", []string{nativeBinaryPathFor(*p)})

View File

@@ -110,8 +110,8 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
return false return false
} }
func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
pbm := builder.AddPrebuiltModule(member, mt.prebuiltModuleType) pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType)
ccModule := member.Variants()[0].(*Module) ccModule := member.Variants()[0].(*Module)
@@ -336,7 +336,7 @@ type nativeLibInfoProperties struct {
outputFile android.Path outputFile android.Path
} }
func (p *nativeLibInfoProperties) PopulateFromVariant(variant android.SdkAware) { func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
ccModule := variant.(*Module) ccModule := variant.(*Module)
// If the library has some link types then it produces an output binary file, otherwise it // If the library has some link types then it produces an output binary file, otherwise it
@@ -369,6 +369,6 @@ func (p *nativeLibInfoProperties) PopulateFromVariant(variant android.SdkAware)
p.exportedGeneratedHeaders = ccModule.ExportedGeneratedHeaders() p.exportedGeneratedHeaders = ccModule.ExportedGeneratedHeaders()
} }
func (p *nativeLibInfoProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
addPossiblyArchSpecificProperties(sdkModuleContext, builder, p, propertySet) addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet)
} }

View File

@@ -1909,8 +1909,8 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool {
return ok return ok
} }
func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
return builder.AddPrebuiltModule(member, "java_import") return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import")
} }
func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
@@ -1926,15 +1926,18 @@ type librarySdkMemberProperties struct {
jarToExport android.Path jarToExport android.Path
} }
func (p *librarySdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
j := variant.(*Library) j := variant.(*Library)
p.library = j p.library = j
p.jarToExport = p.memberType.jarToExportGetter(j) p.jarToExport = p.memberType.jarToExportGetter(j)
} }
func (p *librarySdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { func (p *librarySdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
if p.jarToExport != nil { if p.jarToExport != nil {
sdkModuleContext := ctx.SdkModuleContext()
builder := ctx.SnapshotBuilder()
exportedJar := p.jarToExport exportedJar := p.jarToExport
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name()) snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name())
builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath)
@@ -2113,8 +2116,8 @@ func (mt *testSdkMemberType) IsInstance(module android.Module) bool {
return ok return ok
} }
func (mt *testSdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule {
return builder.AddPrebuiltModule(member, "java_test_import") return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import")
} }
func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties {
@@ -2128,7 +2131,7 @@ type testSdkMemberProperties struct {
jarToExport android.Path jarToExport android.Path
} }
func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) {
test := variant.(*Test) test := variant.(*Test)
implementationJars := test.ImplementationJars() implementationJars := test.ImplementationJars()
@@ -2140,8 +2143,10 @@ func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware)
p.jarToExport = implementationJars[0] p.jarToExport = implementationJars[0]
} }
func (p *testSdkMemberProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { func (p *testSdkMemberProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) {
if p.jarToExport != nil { if p.jarToExport != nil {
builder := ctx.SnapshotBuilder()
snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name()) snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name())
builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath) builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath)

View File

@@ -254,12 +254,15 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro
members, multilib := s.organizeMembers(ctx, memberRefs) members, multilib := s.organizeMembers(ctx, memberRefs)
for _, member := range members { for _, member := range members {
memberType := member.memberType memberType := member.memberType
prebuiltModule := memberType.AddPrebuiltModule(ctx, builder, member)
memberCtx := &memberContext{ctx, builder}
prebuiltModule := memberType.AddPrebuiltModule(memberCtx, member)
if prebuiltModule == nil { if prebuiltModule == nil {
// Fall back to legacy method of building a snapshot // Fall back to legacy method of building a snapshot
memberType.BuildSnapshot(ctx, builder, member) memberType.BuildSnapshot(ctx, builder, member)
} else { } else {
s.createMemberSnapshot(ctx, builder, member, prebuiltModule) s.createMemberSnapshot(memberCtx, member, prebuiltModule)
} }
} }
@@ -831,7 +834,7 @@ type variantPropertiesFactoryFunc func() android.SdkMemberProperties
// Create a new osTypeSpecificInfo for the specified os type and its properties // Create a new osTypeSpecificInfo for the specified os type and its properties
// structures populated with information from the variants. // structures populated with information from the variants.
func newOsTypeSpecificInfo(osType android.OsType, variantPropertiesFactory variantPropertiesFactoryFunc, osTypeVariants []android.SdkAware) *osTypeSpecificInfo { func newOsTypeSpecificInfo(ctx android.SdkMemberContext, osType android.OsType, variantPropertiesFactory variantPropertiesFactoryFunc, osTypeVariants []android.Module) *osTypeSpecificInfo {
osInfo := &osTypeSpecificInfo{ osInfo := &osTypeSpecificInfo{
osType: osType, osType: osType,
} }
@@ -847,7 +850,7 @@ func newOsTypeSpecificInfo(osType android.OsType, variantPropertiesFactory varia
osInfo.Properties = osSpecificVariantPropertiesFactory() osInfo.Properties = osSpecificVariantPropertiesFactory()
// Group the variants by arch type. // Group the variants by arch type.
var variantsByArchName = make(map[string][]android.SdkAware) var variantsByArchName = make(map[string][]android.Module)
var archTypes []android.ArchType var archTypes []android.ArchType
for _, variant := range osTypeVariants { for _, variant := range osTypeVariants {
archType := variant.Target().Arch.ArchType archType := variant.Target().Arch.ArchType
@@ -866,14 +869,14 @@ func newOsTypeSpecificInfo(osType android.OsType, variantPropertiesFactory varia
// A common arch type only has one variant and its properties should be treated // A common arch type only has one variant and its properties should be treated
// as common to the os type. // as common to the os type.
osInfo.Properties.PopulateFromVariant(commonVariants[0]) osInfo.Properties.PopulateFromVariant(ctx, commonVariants[0])
} else { } else {
// Create an arch specific info for each supported architecture type. // Create an arch specific info for each supported architecture type.
for _, archType := range archTypes { for _, archType := range archTypes {
archTypeName := archType.Name archTypeName := archType.Name
archVariants := variantsByArchName[archTypeName] archVariants := variantsByArchName[archTypeName]
archInfo := newArchSpecificInfo(archType, osSpecificVariantPropertiesFactory, archVariants) archInfo := newArchSpecificInfo(ctx, archType, osSpecificVariantPropertiesFactory, archVariants)
osInfo.archInfos = append(osInfo.archInfos, archInfo) osInfo.archInfos = append(osInfo.archInfos, archInfo)
} }
@@ -912,10 +915,7 @@ func (osInfo *osTypeSpecificInfo) optimizeProperties(commonValueExtractor *commo
// Maps the properties related to the os variants through to an appropriate // Maps the properties related to the os variants through to an appropriate
// module structure that will produce equivalent set of variants when it is // module structure that will produce equivalent set of variants when it is
// processed in a build. // processed in a build.
func (osInfo *osTypeSpecificInfo) addToPropertySet( func (osInfo *osTypeSpecificInfo) addToPropertySet(ctx *memberContext, bpModule android.BpModule, targetPropertySet android.BpPropertySet) {
builder *snapshotBuilder,
bpModule android.BpModule,
targetPropertySet android.BpPropertySet) {
var osPropertySet android.BpPropertySet var osPropertySet android.BpPropertySet
var archPropertySet android.BpPropertySet var archPropertySet android.BpPropertySet
@@ -965,7 +965,7 @@ func (osInfo *osTypeSpecificInfo) addToPropertySet(
} }
// Add the os specific but arch independent properties to the module. // Add the os specific but arch independent properties to the module.
osInfo.Properties.AddToPropertySet(builder.ctx, builder, osPropertySet) osInfo.Properties.AddToPropertySet(ctx, osPropertySet)
// Add arch (and possibly os) specific sections for each set of arch (and possibly // Add arch (and possibly os) specific sections for each set of arch (and possibly
// os) specific properties. // os) specific properties.
@@ -973,7 +973,7 @@ func (osInfo *osTypeSpecificInfo) addToPropertySet(
// The archInfos list will be empty if the os contains variants for the common // The archInfos list will be empty if the os contains variants for the common
// architecture. // architecture.
for _, archInfo := range osInfo.archInfos { for _, archInfo := range osInfo.archInfos {
archInfo.addToPropertySet(builder, archPropertySet, archOsPrefix) archInfo.addToPropertySet(ctx, archPropertySet, archOsPrefix)
} }
} }
@@ -987,7 +987,7 @@ type archTypeSpecificInfo struct {
// Create a new archTypeSpecificInfo for the specified arch type and its properties // Create a new archTypeSpecificInfo for the specified arch type and its properties
// structures populated with information from the variants. // structures populated with information from the variants.
func newArchSpecificInfo(archType android.ArchType, variantPropertiesFactory variantPropertiesFactoryFunc, archVariants []android.SdkAware) *archTypeSpecificInfo { func newArchSpecificInfo(ctx android.SdkMemberContext, archType android.ArchType, variantPropertiesFactory variantPropertiesFactoryFunc, archVariants []android.Module) *archTypeSpecificInfo {
// Create an arch specific info into which the variant properties can be copied. // Create an arch specific info into which the variant properties can be copied.
archInfo := &archTypeSpecificInfo{archType: archType} archInfo := &archTypeSpecificInfo{archType: archType}
@@ -997,7 +997,7 @@ func newArchSpecificInfo(archType android.ArchType, variantPropertiesFactory var
archInfo.Properties = variantPropertiesFactory() archInfo.Properties = variantPropertiesFactory()
if len(archVariants) == 1 { if len(archVariants) == 1 {
archInfo.Properties.PopulateFromVariant(archVariants[0]) archInfo.Properties.PopulateFromVariant(ctx, archVariants[0])
} else { } else {
// There is more than one variant for this arch type which must be differentiated // There is more than one variant for this arch type which must be differentiated
// by link type. // by link type.
@@ -1006,7 +1006,7 @@ func newArchSpecificInfo(archType android.ArchType, variantPropertiesFactory var
if linkType == "" { if linkType == "" {
panic(fmt.Errorf("expected one arch specific variant as it is not identified by link type but found %d", len(archVariants))) panic(fmt.Errorf("expected one arch specific variant as it is not identified by link type but found %d", len(archVariants)))
} else { } else {
linkInfo := newLinkSpecificInfo(linkType, variantPropertiesFactory, linkVariant) linkInfo := newLinkSpecificInfo(ctx, linkType, variantPropertiesFactory, linkVariant)
archInfo.linkInfos = append(archInfo.linkInfos, linkInfo) archInfo.linkInfos = append(archInfo.linkInfos, linkInfo)
} }
@@ -1052,14 +1052,14 @@ func (archInfo *archTypeSpecificInfo) optimizeProperties(commonValueExtractor *c
} }
// Add the properties for an arch type to a property set. // Add the properties for an arch type to a property set.
func (archInfo *archTypeSpecificInfo) addToPropertySet(builder *snapshotBuilder, archPropertySet android.BpPropertySet, archOsPrefix string) { func (archInfo *archTypeSpecificInfo) addToPropertySet(ctx *memberContext, archPropertySet android.BpPropertySet, archOsPrefix string) {
archTypeName := archInfo.archType.Name archTypeName := archInfo.archType.Name
archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName) archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName)
archInfo.Properties.AddToPropertySet(builder.ctx, builder, archTypePropertySet) archInfo.Properties.AddToPropertySet(ctx, archTypePropertySet)
for _, linkInfo := range archInfo.linkInfos { for _, linkInfo := range archInfo.linkInfos {
linkPropertySet := archTypePropertySet.AddPropertySet(linkInfo.linkType) linkPropertySet := archTypePropertySet.AddPropertySet(linkInfo.linkType)
linkInfo.Properties.AddToPropertySet(builder.ctx, builder, linkPropertySet) linkInfo.Properties.AddToPropertySet(ctx, linkPropertySet)
} }
} }
@@ -1071,7 +1071,7 @@ type linkTypeSpecificInfo struct {
// Create a new linkTypeSpecificInfo for the specified link type and its properties // Create a new linkTypeSpecificInfo for the specified link type and its properties
// structures populated with information from the variant. // structures populated with information from the variant.
func newLinkSpecificInfo(linkType string, variantPropertiesFactory variantPropertiesFactoryFunc, linkVariant android.SdkAware) *linkTypeSpecificInfo { func newLinkSpecificInfo(ctx android.SdkMemberContext, linkType string, variantPropertiesFactory variantPropertiesFactoryFunc, linkVariant android.Module) *linkTypeSpecificInfo {
linkInfo := &linkTypeSpecificInfo{ linkInfo := &linkTypeSpecificInfo{
baseInfo: baseInfo{ baseInfo: baseInfo{
// Create the properties into which the link type specific properties will be // Create the properties into which the link type specific properties will be
@@ -1080,16 +1080,29 @@ func newLinkSpecificInfo(linkType string, variantPropertiesFactory variantProper
}, },
linkType: linkType, linkType: linkType,
} }
linkInfo.Properties.PopulateFromVariant(linkVariant) linkInfo.Properties.PopulateFromVariant(ctx, linkVariant)
return linkInfo return linkInfo
} }
func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, builder *snapshotBuilder, member *sdkMember, bpModule android.BpModule) { type memberContext struct {
sdkMemberContext android.ModuleContext
builder *snapshotBuilder
}
func (m *memberContext) SdkModuleContext() android.ModuleContext {
return m.sdkMemberContext
}
func (m *memberContext) SnapshotBuilder() android.SnapshotBuilder {
return m.builder
}
func (s *sdk) createMemberSnapshot(ctx *memberContext, member *sdkMember, bpModule android.BpModule) {
memberType := member.memberType memberType := member.memberType
// Group the variants by os type. // Group the variants by os type.
variantsByOsType := make(map[android.OsType][]android.SdkAware) variantsByOsType := make(map[android.OsType][]android.Module)
variants := member.Variants() variants := member.Variants()
for _, variant := range variants { for _, variant := range variants {
osType := variant.Target().Os osType := variant.Target().Os
@@ -1118,7 +1131,7 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build
var osSpecificPropertiesList []android.SdkMemberProperties var osSpecificPropertiesList []android.SdkMemberProperties
for osType, osTypeVariants := range variantsByOsType { for osType, osTypeVariants := range variantsByOsType {
osInfo := newOsTypeSpecificInfo(osType, variantPropertiesFactory, osTypeVariants) osInfo := newOsTypeSpecificInfo(ctx, osType, variantPropertiesFactory, osTypeVariants)
osTypeToInfo[osType] = osInfo osTypeToInfo[osType] = osInfo
// Add the os specific properties to a list of os type specific yet architecture // Add the os specific properties to a list of os type specific yet architecture
// independent properties structs. // independent properties structs.
@@ -1132,7 +1145,7 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build
commonValueExtractor.extractCommonProperties(commonProperties, osSpecificPropertiesList) commonValueExtractor.extractCommonProperties(commonProperties, osSpecificPropertiesList)
// Add the common properties to the module. // Add the common properties to the module.
commonProperties.AddToPropertySet(sdkModuleContext, builder, bpModule) commonProperties.AddToPropertySet(ctx, bpModule)
// Create a target property set into which target specific properties can be // Create a target property set into which target specific properties can be
// added. // added.
@@ -1145,7 +1158,7 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build
continue continue
} }
osInfo.addToPropertySet(builder, bpModule, targetPropertySet) osInfo.addToPropertySet(ctx, bpModule, targetPropertySet)
} }
} }