Retry: Support generating sdk snapshot for specific build release
This was reverted unnecessarily along with the change that actually
broke the build.
Previously, the sdk snapshot was assumed to be generated for the
current build system. This change adds support for the
SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE environment variable which can
be used to select the target build release in which the generated
snapshot will be used.
At the moment this will only affect the properties that are output but
if/when it becomes necessary it can also be used to control more
aspects of the snapshots such as supported member types or even
members.
This change does not modify any properties that are build release
specific. That will come in following changes. However, it does add a
test that targets build release S which defines a baseline for
properties that will be affected in following changes. That baseline
makes it easier to see the effect of those follow up changes.
Bug: 197842263
Test: m nothing
Change-Id: If4b452237f105382550d2842c8010249afbc7432
diff --git a/sdk/update.go b/sdk/update.go
index 3246832..389e845 100644
--- a/sdk/update.go
+++ b/sdk/update.go
@@ -81,6 +81,19 @@
// 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
+// to the current build release version. Otherwise, it must be the name of one of the build
+// releases defined in nameToBuildRelease, e.g. S, T, etc..
+//
+// The generated snapshot must only be used in the specified target release. If the target
+// build release is not the current build release then the generated Android.bp file not be
+// checked for compatibility.
+//
+// e.g. if setting SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE=S will cause the generated snapshot
+// to be compatible with S.
+//
var pctx = android.NewPackageContext("android/soong/sdk")
@@ -358,6 +371,14 @@
snapshotZipFileSuffix = "-" + version
}
+ currentBuildRelease := latestBuildRelease()
+ targetBuildReleaseEnv := config.GetenvWithDefault("SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE", currentBuildRelease.name)
+ targetBuildRelease, err := nameToRelease(targetBuildReleaseEnv)
+ if err != nil {
+ ctx.ModuleErrorf("invalid SOONG_SDK_SNAPSHOT_TARGET_BUILD_RELEASE: %s", err)
+ targetBuildRelease = currentBuildRelease
+ }
+
builder := &snapshotBuilder{
ctx: ctx,
sdk: s,
@@ -369,6 +390,7 @@
prebuiltModules: make(map[string]*bpModule),
allMembersByName: allMembersByName,
exportedMembersByName: exportedMembersByName,
+ targetBuildRelease: targetBuildRelease,
}
s.builderForTests = builder
@@ -449,7 +471,11 @@
generateBpContents(&bp.generatedContents, bpFile)
contents := bp.content.String()
- syntaxCheckSnapshotBpFile(ctx, contents)
+ // If the snapshot is being generated for the current build release then check the syntax to make
+ // sure that it is compatible.
+ if targetBuildRelease == currentBuildRelease {
+ syntaxCheckSnapshotBpFile(ctx, contents)
+ }
bp.build(pctx, ctx, nil)
@@ -1051,6 +1077,9 @@
// The set of exported members by name.
exportedMembersByName map[string]struct{}
+
+ // The target build release for which the snapshot is to be generated.
+ targetBuildRelease *buildRelease
}
func (s *snapshotBuilder) CopyToSnapshot(src android.Path, dest string) {
@@ -1426,6 +1455,16 @@
return osInfo
}
+func (osInfo *osTypeSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ if len(osInfo.archInfos) == 0 {
+ pruner.pruneProperties(osInfo.Properties)
+ } else {
+ for _, archInfo := range osInfo.archInfos {
+ archInfo.pruneUnsupportedProperties(pruner)
+ }
+ }
+}
+
// Optimize the properties by extracting common properties from arch type specific
// properties into os type specific properties.
func (osInfo *osTypeSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
@@ -1635,6 +1674,16 @@
return linkType
}
+func (archInfo *archTypeSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ if len(archInfo.imageVariantInfos) == 0 {
+ pruner.pruneProperties(archInfo.Properties)
+ } else {
+ for _, imageVariantInfo := range archInfo.imageVariantInfos {
+ imageVariantInfo.pruneUnsupportedProperties(pruner)
+ }
+ }
+}
+
// Optimize the properties by extracting common properties from link type specific
// properties into arch type specific properties.
func (archInfo *archTypeSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
@@ -1732,6 +1781,16 @@
return imageInfo
}
+func (imageInfo *imageVariantSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ if len(imageInfo.linkInfos) == 0 {
+ pruner.pruneProperties(imageInfo.Properties)
+ } else {
+ for _, linkInfo := range imageInfo.linkInfos {
+ linkInfo.pruneUnsupportedProperties(pruner)
+ }
+ }
+}
+
// Optimize the properties by extracting common properties from link type specific
// properties into arch type specific properties.
func (imageInfo *imageVariantSpecificInfo) optimizeProperties(ctx *memberContext, commonValueExtractor *commonValueExtractor) {
@@ -1798,6 +1857,10 @@
addSdkMemberPropertiesToSet(ctx, l.Properties, linkPropertySet)
}
+func (l *linkTypeSpecificInfo) pruneUnsupportedProperties(pruner *propertyPruner) {
+ pruner.pruneProperties(l.Properties)
+}
+
func (l *linkTypeSpecificInfo) String() string {
return fmt.Sprintf("LinkType{%s}", l.linkType)
}
@@ -1837,12 +1900,12 @@
memberType := member.memberType
// Do not add the prefer property if the member snapshot module is a source module type.
+ config := ctx.sdkMemberContext.Config()
if !memberType.UsesSourceModuleTypeInSnapshot() {
// Set the prefer based on the environment variable. This is a temporary work around to allow a
// snapshot to be created that sets prefer: true.
// TODO(b/174997203): Remove once the ability to select the modules to prefer can be done
// dynamically at build time not at snapshot generation time.
- config := ctx.sdkMemberContext.Config()
prefer := config.IsEnvTrue("SOONG_SDK_SNAPSHOT_PREFER")
// Set prefer. Setting this to false is not strictly required as that is the default but it does
@@ -1884,6 +1947,11 @@
commonProperties := variantPropertiesFactory()
commonProperties.Base().Os = android.CommonOS
+ // Create a property pruner that will prune any properties unsupported by the target build
+ // release.
+ targetBuildRelease := ctx.builder.targetBuildRelease
+ unsupportedPropertyPruner := newPropertyPrunerByBuildRelease(commonProperties, targetBuildRelease)
+
// Create common value extractor that can be used to optimize the properties.
commonValueExtractor := newCommonValueExtractor(commonProperties)
@@ -1898,6 +1966,8 @@
// independent properties structs.
osSpecificPropertiesContainers = append(osSpecificPropertiesContainers, osInfo)
+ osInfo.pruneUnsupportedProperties(unsupportedPropertyPruner)
+
// Optimize the properties across all the variants for a specific os type.
osInfo.optimizeProperties(ctx, commonValueExtractor)
}