diff options
author | 2022-05-24 20:10:05 +0000 | |
---|---|---|
committer | 2022-05-24 20:10:05 +0000 | |
commit | b01ac4b6ba89e13cbb47e9d22619bf015270ee26 (patch) | |
tree | c6b4041b3d463057232330bfc81a8101517acef1 /sdk/update.go | |
parent | 78ce8c23def25e30fba5e2cdb124ad3f0409751c (diff) |
Remove support for generating versioned snapshots
Previously, the code for selecting specific versions of sdk snapshots
was removed (along with the uses_sdks property). That makes versioned
snapshots useless so this change removes all the code and tests that
generated those versioned snapshots.
Bug: 232546567
Test: m nothing
packages/modules/common/build/mainline_modules_sdks.sh
Change-Id: Ib6d1b72bc8399fbb39075494ae37da92f4b28d03
Diffstat (limited to 'sdk/update.go')
-rw-r--r-- | sdk/update.go | 319 |
1 files changed, 38 insertions, 281 deletions
diff --git a/sdk/update.go b/sdk/update.go index c5adddafb..457828bdd 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -35,7 +35,7 @@ import ( // ======================================================== // // SOONG_SDK_SNAPSHOT_PREFER -// By default every unversioned module in the generated snapshot has prefer: false. Building it +// By default every module in the generated snapshot has prefer: false. Building it // with SOONG_SDK_SNAPSHOT_PREFER=true will force them to use prefer: true. // // SOONG_SDK_SNAPSHOT_USE_SOURCE_CONFIG_VAR @@ -69,20 +69,6 @@ import ( // maintainable solution has been implemented. // TODO(b/174997203): Remove when no longer necessary. // -// SOONG_SDK_SNAPSHOT_VERSION -// This provides control over the version of the generated snapshot. -// -// SOONG_SDK_SNAPSHOT_VERSION=current will generate unversioned and versioned prebuilts and a -// versioned snapshot module. This is the default behavior. The zip file containing the -// generated snapshot will be <sdk-name>-current.zip. -// -// SOONG_SDK_SNAPSHOT_VERSION=unversioned will generate unversioned prebuilts only and the zip -// file containing the generated snapshot will be <sdk-name>.zip. -// -// SOONG_SDK_SNAPSHOT_VERSION=<number> will generate versioned prebuilts and a versioned -// snapshot module only. The zip file containing the generated snapshot will be -// <sdk-name>-<number>.zip. -// // SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE // This allows the target build release (i.e. the release version of the build within which // the snapshot will be used) of the snapshot to be specified. If unspecified then it defaults @@ -130,8 +116,7 @@ var ( ) const ( - soongSdkSnapshotVersionUnversioned = "unversioned" - soongSdkSnapshotVersionCurrent = "current" + soongSdkSnapshotVersionCurrent = "current" ) type generatedContents struct { @@ -163,13 +148,13 @@ func (gc *generatedContents) Dedent() { // IndentedPrintf will add spaces to indent the line to the appropriate level before printing the // arguments. func (gc *generatedContents) IndentedPrintf(format string, args ...interface{}) { - fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format, args...) + _, _ = fmt.Fprintf(&(gc.content), strings.Repeat(" ", gc.indentLevel)+format, args...) } // UnindentedPrintf does not add spaces to indent the line to the appropriate level before printing // the arguments. func (gc *generatedContents) UnindentedPrintf(format string, args ...interface{}) { - fmt.Fprintf(&(gc.content), format, args...) + _, _ = fmt.Fprintf(&(gc.content), format, args...) } func (gf *generatedFile) build(pctx android.PackageContext, ctx android.BuilderContext, implicits android.Paths) { @@ -321,12 +306,6 @@ const BUILD_NUMBER_FILE = "snapshot-creation-build-number.txt" // <arch>/lib/ // libFoo.so : a stub library -// A name that uniquely identifies a prebuilt SDK member for a version of SDK snapshot -// This isn't visible to users, so could be changed in future. -func versionedSdkMemberName(ctx android.ModuleContext, memberName string, version string) string { - return ctx.ModuleName() + "_" + memberName + string(android.SdkVersionSeparator) + version -} - // buildSnapshot is the main function in this source file. It creates rules to copy // the contents (header files, stub libraries, etc) into the zip file. func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { @@ -378,20 +357,9 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { } config := ctx.Config() - version := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_VERSION", "current") - - // Generate versioned modules in the snapshot unless an unversioned snapshot has been requested. - generateVersioned := version != soongSdkSnapshotVersionUnversioned - // Generate unversioned modules in the snapshot unless a numbered snapshot has been requested. - // - // Unversioned modules are not required in that case because the numbered version will be a - // finalized version of the snapshot that is intended to be kept separate from the - generateUnversioned := version == soongSdkSnapshotVersionUnversioned || version == soongSdkSnapshotVersionCurrent - snapshotFileSuffix := "" - if generateVersioned { - snapshotFileSuffix = "-" + version - } + // Always add -current to the end + snapshotFileSuffix := "-current" currentBuildRelease := latestBuildRelease() targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name) @@ -404,7 +372,6 @@ func (s *sdk) buildSnapshot(ctx android.ModuleContext, sdkVariants []*sdk) { builder := &snapshotBuilder{ ctx: ctx, sdk: s, - version: version, snapshotDir: snapshotDir.OutputPath, copies: make(map[string]string), filesToZip: []android.Path{bp.path}, @@ -454,38 +421,19 @@ be unnecessary as every module in the sdk already has its own licenses property. s.createMemberSnapshot(memberCtx, member, prebuiltModule.(*bpModule)) } - // Create a transformer that will transform an unversioned module into a versioned module. - unversionedToVersionedTransformer := unversionedToVersionedTransformation{builder: builder} - - // Create a transformer that will transform an unversioned module by replacing any references + // Create a transformer that will transform a module by replacing any references // to internal members with a unique module name and setting prefer: false. - unversionedTransformer := unversionedTransformation{ + snapshotTransformer := snapshotTransformation{ builder: builder, } - for _, unversioned := range builder.prebuiltOrder { + for _, module := range builder.prebuiltOrder { // Prune any empty property sets. - unversioned = unversioned.transform(pruneEmptySetTransformer{}) - - if generateVersioned { - // Copy the unversioned module so it can be modified to make it versioned. - versioned := unversioned.deepCopy() + module = module.transform(pruneEmptySetTransformer{}) - // Transform the unversioned module into a versioned one. - versioned.transform(unversionedToVersionedTransformer) - bpFile.AddModule(versioned) - } - - if generateUnversioned { - // Transform the unversioned module to make it suitable for use in the snapshot. - unversioned.transform(unversionedTransformer) - bpFile.AddModule(unversioned) - } - } - - if generateVersioned { - // Add the sdk/module_exports_snapshot module to the bp file. - s.addSnapshotModule(ctx, builder, sdkVariants, memberVariantDeps) + // Transform the module module to make it suitable for use in the snapshot. + module.transform(snapshotTransformer) + bpFile.AddModule(module) } // generate Android.bp @@ -672,7 +620,7 @@ func (s *sdk) generateInfoData(ctx android.ModuleContext, memberVariantDeps []sd func filterOutComponents(ctx android.ModuleContext, deps []sdkMemberVariantDep) []sdkMemberVariantDep { // Collate the set of components that all the modules added to the sdk provide. components := map[string]*sdkMemberVariantDep{} - for i, _ := range deps { + for i := range deps { dep := &deps[i] for _, c := range dep.exportedComponentsInfo.Components { components[c] = dep @@ -707,81 +655,6 @@ func filterOutComponents(ctx android.ModuleContext, deps []sdkMemberVariantDep) return filtered } -// addSnapshotModule adds the sdk_snapshot/module_exports_snapshot module to the builder. -func (s *sdk) addSnapshotModule(ctx android.ModuleContext, builder *snapshotBuilder, sdkVariants []*sdk, memberVariantDeps []sdkMemberVariantDep) { - bpFile := builder.bpFile - - snapshotName := ctx.ModuleName() + string(android.SdkVersionSeparator) + builder.version - var snapshotModuleType string - if s.properties.Module_exports { - snapshotModuleType = "module_exports_snapshot" - } else { - snapshotModuleType = "sdk_snapshot" - } - snapshotModule := bpFile.newModule(snapshotModuleType) - snapshotModule.AddProperty("name", snapshotName) - - // Make sure that the snapshot has the same visibility as the sdk. - visibility := android.EffectiveVisibilityRules(ctx, s).Strings() - if len(visibility) != 0 { - snapshotModule.AddProperty("visibility", visibility) - } - - addHostDeviceSupportedProperties(s.ModuleBase.DeviceSupported(), s.ModuleBase.HostSupported(), snapshotModule) - - combinedPropertiesList := s.collateSnapshotModuleInfo(ctx, sdkVariants, memberVariantDeps) - commonCombinedProperties := s.optimizeSnapshotModuleProperties(ctx, combinedPropertiesList) - - s.addSnapshotPropertiesToPropertySet(builder, snapshotModule, commonCombinedProperties) - - targetPropertySet := snapshotModule.AddPropertySet("target") - - // Create a mapping from osType to combined properties. - osTypeToCombinedProperties := map[android.OsType]*combinedSnapshotModuleProperties{} - for _, combined := range combinedPropertiesList { - osTypeToCombinedProperties[combined.sdkVariant.Os()] = combined - } - - // Iterate over the os types in a fixed order. - for _, osType := range s.getPossibleOsTypes() { - if combined, ok := osTypeToCombinedProperties[osType]; ok { - osPropertySet := targetPropertySet.AddPropertySet(osType.Name) - - s.addSnapshotPropertiesToPropertySet(builder, osPropertySet, combined) - } - } - - // 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 _, memberVariantDep := range memberVariantDeps { - if memberVariantDep.memberType.IsHostOsDependent() && memberVariantDep.variant.Target().Os.Class == android.Host { - targetString := memberVariantDep.variant.Target().Os.String() + "_" + memberVariantDep.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{}) - - bpFile.AddModule(snapshotModule) -} - // Check the syntax of the generated Android.bp file contents and if they are // invalid then log an error with the contents (tagged with line numbers) and the // errors that were found so that it is easy to see where the problem lies. @@ -918,92 +791,34 @@ func (s *sdk) optimizeSnapshotModuleProperties(ctx android.ModuleContext, list [ } } -func (s *sdk) addSnapshotPropertiesToPropertySet(builder *snapshotBuilder, propertySet android.BpPropertySet, combined *combinedSnapshotModuleProperties) { - staticProperties := combined.staticProperties - multilib := staticProperties.Compile_multilib - if multilib != "" && multilib != "both" { - // Compile_multilib defaults to both so only needs to be set when it's specified and not both. - propertySet.AddProperty("compile_multilib", multilib) - } - - dynamicMemberTypeListProperties := combined.dynamicProperties - for _, memberListProperty := range s.memberTypeListProperties() { - if memberListProperty.getter == nil { - continue - } - names := memberListProperty.getter(dynamicMemberTypeListProperties) - if len(names) > 0 { - propertySet.AddProperty(memberListProperty.propertyName(), builder.versionedSdkMemberNames(names, false)) - } - } -} - type propertyTag struct { name string } var _ android.BpPropertyTag = propertyTag{} -// A BpPropertyTag to add to a property that contains references to other sdk members. +// BpPropertyTag instances to add to a property that contains references to other sdk members. // -// This will cause the references to be rewritten to a versioned reference in the version -// specific instance of a snapshot module. +// These will ensure that the referenced modules are available, if required. var requiredSdkMemberReferencePropertyTag = propertyTag{"requiredSdkMemberReferencePropertyTag"} var optionalSdkMemberReferencePropertyTag = propertyTag{"optionalSdkMemberReferencePropertyTag"} -// A BpPropertyTag that indicates the property should only be present in the versioned -// module. -// -// This will cause the property to be removed from the unversioned instance of a -// snapshot module. -var sdkVersionedOnlyPropertyTag = propertyTag{"sdkVersionedOnlyPropertyTag"} - -type unversionedToVersionedTransformation struct { +type snapshotTransformation struct { identityTransformation builder *snapshotBuilder } -func (t unversionedToVersionedTransformation) transformModule(module *bpModule) *bpModule { - // Use a versioned name for the module but remember the original name for the - // snapshot. - name := module.Name() - module.setProperty("name", t.builder.versionedSdkMemberName(name, true)) - module.insertAfter("name", "sdk_member_name", name) - // Remove the prefer property if present as versioned modules never need marking with prefer. - module.removeProperty("prefer") - // Ditto for use_source_config_var - module.removeProperty("use_source_config_var") - return module -} - -func (t unversionedToVersionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { - if tag == requiredSdkMemberReferencePropertyTag || tag == optionalSdkMemberReferencePropertyTag { - required := tag == requiredSdkMemberReferencePropertyTag - return t.builder.versionedSdkMemberNames(value.([]string), required), tag - } else { - return value, tag - } -} - -type unversionedTransformation struct { - identityTransformation - builder *snapshotBuilder -} - -func (t unversionedTransformation) transformModule(module *bpModule) *bpModule { +func (t snapshotTransformation) transformModule(module *bpModule) *bpModule { // If the module is an internal member then use a unique name for it. name := module.Name() - module.setProperty("name", t.builder.unversionedSdkMemberName(name, true)) + module.setProperty("name", t.builder.snapshotSdkMemberName(name, true)) return module } -func (t unversionedTransformation) transformProperty(name string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { +func (t snapshotTransformation) transformProperty(_ string, value interface{}, tag android.BpPropertyTag) (interface{}, android.BpPropertyTag) { if tag == requiredSdkMemberReferencePropertyTag || tag == optionalSdkMemberReferencePropertyTag { required := tag == requiredSdkMemberReferencePropertyTag - return t.builder.unversionedSdkMemberNames(value.([]string), required), tag - } else if tag == sdkVersionedOnlyPropertyTag { - // The property is not allowed in the unversioned module so remove it. - return nil, nil + return t.builder.snapshotSdkMemberNames(value.([]string), required), tag } else { return value, tag } @@ -1015,7 +830,7 @@ type pruneEmptySetTransformer struct { var _ bpTransformer = (*pruneEmptySetTransformer)(nil) -func (t pruneEmptySetTransformer) transformPropertySetAfterContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { +func (t pruneEmptySetTransformer) transformPropertySetAfterContents(_ string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { if len(propertySet.properties) == 0 { return nil, nil } else { @@ -1024,20 +839,12 @@ func (t pruneEmptySetTransformer) transformPropertySetAfterContents(name string, } func generateBpContents(contents *generatedContents, bpFile *bpFile) { - generateFilteredBpContents(contents, bpFile, func(*bpModule) bool { - return true - }) -} - -func generateFilteredBpContents(contents *generatedContents, bpFile *bpFile, moduleFilter func(module *bpModule) bool) { contents.IndentedPrintf("// This is auto-generated. DO NOT EDIT.\n") for _, bpModule := range bpFile.order { - if moduleFilter(bpModule) { - contents.IndentedPrintf("\n") - contents.IndentedPrintf("%s {\n", bpModule.moduleType) - outputPropertySet(contents, bpModule.bpPropertySet) - contents.IndentedPrintf("}\n") - } + contents.IndentedPrintf("\n") + contents.IndentedPrintf("%s {\n", bpModule.moduleType) + outputPropertySet(contents, bpModule.bpPropertySet) + contents.IndentedPrintf("}\n") } } @@ -1173,36 +980,10 @@ func (s *sdk) GetInfoContentsForTests() string { return s.builderForTests.infoContents } -func (s *sdk) GetUnversionedAndroidBpContentsForTests() string { - contents := &generatedContents{} - generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool { - name := module.Name() - // Include modules that are either unversioned or have no name. - return !strings.Contains(name, "@") - }) - return contents.content.String() -} - -func (s *sdk) GetVersionedAndroidBpContentsForTests() string { - contents := &generatedContents{} - generateFilteredBpContents(contents, s.builderForTests.bpFile, func(module *bpModule) bool { - name := module.Name() - // Include modules that are either versioned or have no name. - return name == "" || strings.Contains(name, "@") - }) - return contents.content.String() -} - type snapshotBuilder struct { ctx android.ModuleContext sdk *sdk - // The version of the generated snapshot. - // - // See the documentation of SOONG_SDK_SNAPSHOT_VERSION above for details of the valid values of - // this field. - version string - snapshotDir android.OutputPath bpFile *bpFile @@ -1356,13 +1137,6 @@ func (s *snapshotBuilder) AddPrebuiltModule(member android.SdkMember, moduleType addHostDeviceSupportedProperties(deviceSupported, hostSupported, m) - // Disable installation in the versioned module of those modules that are ever installable. - if installable, ok := variant.(interface{ EverInstallable() bool }); ok { - if installable.EverInstallable() { - m.AddPropertyWithTag("installable", false, sdkVersionedOnlyPropertyTag) - } - } - s.prebuiltModules[name] = m s.prebuiltOrder = append(s.prebuiltOrder, m) return m @@ -1395,45 +1169,28 @@ func (s *snapshotBuilder) OptionalSdkMemberReferencePropertyTag() android.BpProp return optionalSdkMemberReferencePropertyTag } -// Get a versioned name appropriate for the SDK snapshot version being taken. -func (s *snapshotBuilder) versionedSdkMemberName(unversionedName string, required bool) string { - if _, ok := s.allMembersByName[unversionedName]; !ok { +// Get a name for sdk snapshot member. If the member is private then generate a snapshot specific +// name. As part of the processing this checks to make sure that any required members are part of +// the snapshot. +func (s *snapshotBuilder) snapshotSdkMemberName(name string, required bool) string { + if _, ok := s.allMembersByName[name]; !ok { if required { - s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", unversionedName) + s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", name) } - return unversionedName + return name } - return versionedSdkMemberName(s.ctx, unversionedName, s.version) -} -func (s *snapshotBuilder) versionedSdkMemberNames(members []string, required bool) []string { - var references []string = nil - for _, m := range members { - references = append(references, s.versionedSdkMemberName(m, required)) - } - return references -} - -// Get an internal name unique to the sdk. -func (s *snapshotBuilder) unversionedSdkMemberName(unversionedName string, required bool) string { - if _, ok := s.allMembersByName[unversionedName]; !ok { - if required { - s.ctx.ModuleErrorf("Required member reference %s is not a member of the sdk", unversionedName) - } - return unversionedName - } - - if s.isInternalMember(unversionedName) { - return s.ctx.ModuleName() + "_" + unversionedName + if s.isInternalMember(name) { + return s.ctx.ModuleName() + "_" + name } else { - return unversionedName + return name } } -func (s *snapshotBuilder) unversionedSdkMemberNames(members []string, required bool) []string { +func (s *snapshotBuilder) snapshotSdkMemberNames(members []string, required bool) []string { var references []string = nil for _, m := range members { - references = append(references, s.unversionedSdkMemberName(m, required)) + references = append(references, s.snapshotSdkMemberName(m, required)) } return references } |