diff --git a/android/sdk.go b/android/sdk.go index 731bdff11..0a4d3460a 100644 --- a/android/sdk.go +++ b/android/sdk.go @@ -357,7 +357,7 @@ type SdkMemberType interface { // structure and calls AddToPropertySet(...) on the properties struct to add the member // 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. CreateVariantPropertiesStruct() SdkMemberProperties @@ -386,7 +386,7 @@ func (b *SdkMemberTypeBase) BuildSnapshot(sdkModuleContext ModuleContext, builde 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. return nil } @@ -501,9 +501,19 @@ type SdkMemberProperties interface { // Access the base structure. Base() *SdkMemberPropertiesBase - // Populate the structure with information from the variant. - PopulateFromVariant(variant SdkAware) + // Populate this structure with information from the variant. + PopulateFromVariant(ctx SdkMemberContext, variant Module) - // Add the information from the structure to the property set. - AddToPropertySet(sdkModuleContext ModuleContext, builder SnapshotBuilder, propertySet BpPropertySet) + // Add the information from this structure to the property set. + 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 } diff --git a/cc/binary_sdk_member.go b/cc/binary_sdk_member.go index 2778ebd11..9b3235c5d 100644 --- a/cc/binary_sdk_member.go +++ b/cc/binary_sdk_member.go @@ -63,9 +63,8 @@ func (mt *binarySdkMemberType) IsInstance(module android.Module) bool { return false } -func (mt *binarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { - pbm := builder.AddPrebuiltModule(member, "cc_prebuilt_binary") - return pbm +func (mt *binarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { + return ctx.SnapshotBuilder().AddPrebuiltModule(member, "cc_prebuilt_binary") } func (mt *binarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { @@ -107,7 +106,7 @@ type nativeBinaryInfoProperties struct { SystemSharedLibs []string } -func (p *nativeBinaryInfoProperties) PopulateFromVariant(variant android.SdkAware) { +func (p *nativeBinaryInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { ccModule := variant.(*Module) 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 != "" { propertySet.AddProperty("compile_multilib", p.Compile_multilib) } + builder := ctx.SnapshotBuilder() if p.outputFile != nil { propertySet.AddProperty("srcs", []string{nativeBinaryPathFor(*p)}) diff --git a/cc/library_sdk_member.go b/cc/library_sdk_member.go index d010db10e..49674552f 100644 --- a/cc/library_sdk_member.go +++ b/cc/library_sdk_member.go @@ -110,8 +110,8 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { return false } -func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { - pbm := builder.AddPrebuiltModule(member, mt.prebuiltModuleType) +func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { + pbm := ctx.SnapshotBuilder().AddPrebuiltModule(member, mt.prebuiltModuleType) ccModule := member.Variants()[0].(*Module) @@ -336,7 +336,7 @@ type nativeLibInfoProperties struct { outputFile android.Path } -func (p *nativeLibInfoProperties) PopulateFromVariant(variant android.SdkAware) { +func (p *nativeLibInfoProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { ccModule := variant.(*Module) // 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() } -func (p *nativeLibInfoProperties) AddToPropertySet(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, propertySet android.BpPropertySet) { - addPossiblyArchSpecificProperties(sdkModuleContext, builder, p, propertySet) +func (p *nativeLibInfoProperties) AddToPropertySet(ctx android.SdkMemberContext, propertySet android.BpPropertySet) { + addPossiblyArchSpecificProperties(ctx.SdkModuleContext(), ctx.SnapshotBuilder(), p, propertySet) } diff --git a/java/java.go b/java/java.go index 8c779f5c4..41d864b90 100644 --- a/java/java.go +++ b/java/java.go @@ -1909,8 +1909,8 @@ func (mt *librarySdkMemberType) IsInstance(module android.Module) bool { return ok } -func (mt *librarySdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { - return builder.AddPrebuiltModule(member, "java_import") +func (mt *librarySdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { + return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_import") } func (mt *librarySdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { @@ -1926,15 +1926,18 @@ type librarySdkMemberProperties struct { jarToExport android.Path } -func (p *librarySdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { +func (p *librarySdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { j := variant.(*Library) p.library = 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 { + sdkModuleContext := ctx.SdkModuleContext() + builder := ctx.SnapshotBuilder() + exportedJar := p.jarToExport snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.library.Name()) builder.CopyToSnapshot(exportedJar, snapshotRelativeJavaLibPath) @@ -2113,8 +2116,8 @@ func (mt *testSdkMemberType) IsInstance(module android.Module) bool { return ok } -func (mt *testSdkMemberType) AddPrebuiltModule(sdkModuleContext android.ModuleContext, builder android.SnapshotBuilder, member android.SdkMember) android.BpModule { - return builder.AddPrebuiltModule(member, "java_test_import") +func (mt *testSdkMemberType) AddPrebuiltModule(ctx android.SdkMemberContext, member android.SdkMember) android.BpModule { + return ctx.SnapshotBuilder().AddPrebuiltModule(member, "java_test_import") } func (mt *testSdkMemberType) CreateVariantPropertiesStruct() android.SdkMemberProperties { @@ -2128,7 +2131,7 @@ type testSdkMemberProperties struct { jarToExport android.Path } -func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) { +func (p *testSdkMemberProperties) PopulateFromVariant(ctx android.SdkMemberContext, variant android.Module) { test := variant.(*Test) implementationJars := test.ImplementationJars() @@ -2140,8 +2143,10 @@ func (p *testSdkMemberProperties) PopulateFromVariant(variant android.SdkAware) 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 { + builder := ctx.SnapshotBuilder() + snapshotRelativeJavaLibPath := sdkSnapshotFilePathForJar(p.OsPrefix(), p.test.Name()) builder.CopyToSnapshot(p.jarToExport, snapshotRelativeJavaLibPath) diff --git a/sdk/update.go b/sdk/update.go index c706d1c15..4c167310c 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -254,12 +254,15 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) andro members, multilib := s.organizeMembers(ctx, memberRefs) for _, member := range members { memberType := member.memberType - prebuiltModule := memberType.AddPrebuiltModule(ctx, builder, member) + + memberCtx := &memberContext{ctx, builder} + + prebuiltModule := memberType.AddPrebuiltModule(memberCtx, member) if prebuiltModule == nil { // Fall back to legacy method of building a snapshot memberType.BuildSnapshot(ctx, builder, member) } 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 // 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{ osType: osType, } @@ -847,7 +850,7 @@ func newOsTypeSpecificInfo(osType android.OsType, variantPropertiesFactory varia osInfo.Properties = osSpecificVariantPropertiesFactory() // Group the variants by arch type. - var variantsByArchName = make(map[string][]android.SdkAware) + var variantsByArchName = make(map[string][]android.Module) var archTypes []android.ArchType for _, variant := range osTypeVariants { 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 // as common to the os type. - osInfo.Properties.PopulateFromVariant(commonVariants[0]) + osInfo.Properties.PopulateFromVariant(ctx, commonVariants[0]) } else { // Create an arch specific info for each supported architecture type. for _, archType := range archTypes { archTypeName := archType.Name archVariants := variantsByArchName[archTypeName] - archInfo := newArchSpecificInfo(archType, osSpecificVariantPropertiesFactory, archVariants) + archInfo := newArchSpecificInfo(ctx, archType, osSpecificVariantPropertiesFactory, archVariants) 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 // 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) { +func (osInfo *osTypeSpecificInfo) addToPropertySet(ctx *memberContext, bpModule android.BpModule, targetPropertySet android.BpPropertySet) { var osPropertySet 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. - 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 // 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 // architecture. 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 // 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. archInfo := &archTypeSpecificInfo{archType: archType} @@ -997,7 +997,7 @@ func newArchSpecificInfo(archType android.ArchType, variantPropertiesFactory var archInfo.Properties = variantPropertiesFactory() if len(archVariants) == 1 { - archInfo.Properties.PopulateFromVariant(archVariants[0]) + archInfo.Properties.PopulateFromVariant(ctx, archVariants[0]) } else { // There is more than one variant for this arch type which must be differentiated // by link type. @@ -1006,7 +1006,7 @@ func newArchSpecificInfo(archType android.ArchType, variantPropertiesFactory var if linkType == "" { panic(fmt.Errorf("expected one arch specific variant as it is not identified by link type but found %d", len(archVariants))) } else { - linkInfo := newLinkSpecificInfo(linkType, variantPropertiesFactory, linkVariant) + linkInfo := newLinkSpecificInfo(ctx, linkType, variantPropertiesFactory, linkVariant) 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. -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 archTypePropertySet := archPropertySet.AddPropertySet(archOsPrefix + archTypeName) - archInfo.Properties.AddToPropertySet(builder.ctx, builder, archTypePropertySet) + archInfo.Properties.AddToPropertySet(ctx, archTypePropertySet) for _, linkInfo := range archInfo.linkInfos { 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 // 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{ baseInfo: baseInfo{ // Create the properties into which the link type specific properties will be @@ -1080,16 +1080,29 @@ func newLinkSpecificInfo(linkType string, variantPropertiesFactory variantProper }, linkType: linkType, } - linkInfo.Properties.PopulateFromVariant(linkVariant) + linkInfo.Properties.PopulateFromVariant(ctx, linkVariant) 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 // Group the variants by os type. - variantsByOsType := make(map[android.OsType][]android.SdkAware) + variantsByOsType := make(map[android.OsType][]android.Module) variants := member.Variants() for _, variant := range variants { osType := variant.Target().Os @@ -1118,7 +1131,7 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build var osSpecificPropertiesList []android.SdkMemberProperties for osType, osTypeVariants := range variantsByOsType { - osInfo := newOsTypeSpecificInfo(osType, variantPropertiesFactory, osTypeVariants) + osInfo := newOsTypeSpecificInfo(ctx, osType, variantPropertiesFactory, osTypeVariants) osTypeToInfo[osType] = osInfo // Add the os specific properties to a list of os type specific yet architecture // independent properties structs. @@ -1132,7 +1145,7 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build commonValueExtractor.extractCommonProperties(commonProperties, osSpecificPropertiesList) // 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 // added. @@ -1145,7 +1158,7 @@ func (s *sdk) createMemberSnapshot(sdkModuleContext android.ModuleContext, build continue } - osInfo.addToPropertySet(builder, bpModule, targetPropertySet) + osInfo.addToPropertySet(ctx, bpModule, targetPropertySet) } }