diff options
author | 2024-06-07 11:06:57 +0000 | |
---|---|---|
committer | 2024-06-10 18:12:35 +0000 | |
commit | 98aa8fa8400131af264405f81045b08201d64e33 (patch) | |
tree | ebc599e2c01d360cf51a77ad1ed2f6871acd46f3 /sdk/update.go | |
parent | d5e16ac52be02e2c41c47964a3b5dbc776bd6799 (diff) |
Remove exportable modules when generating snapshots targeting older platform
This change modifies the contents of the generated Android.bp files so
that when generating a snapshot on a older platform, the "exportable"
modules are removed from the bp files, as the "exportable" modules are
first introduced in V and do not exist in older platforms.
Bug: 345162614
Test: ABTD
Change-Id: I2dba51b98deec7805bd796647a66981f237c55a9
Diffstat (limited to 'sdk/update.go')
-rw-r--r-- | sdk/update.go | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/sdk/update.go b/sdk/update.go index afecf9fe2..0a97fd9ee 100644 --- a/sdk/update.go +++ b/sdk/update.go @@ -480,6 +480,12 @@ be unnecessary as every module in the sdk already has its own licenses property. // Transform the module module to make it suitable for use in the snapshot. module = transformModule(module, snapshotTransformer) module = transformModule(module, emptyClasspathContentsTransformation{}) + + targetApiLevel, err := android.ApiLevelFromUserWithConfig(ctx.Config(), s.targetBuildRelease(ctx).name) + if err == nil && targetApiLevel.LessThan(android.ApiLevelVanillaIceCream) { + module = transformModule(module, replaceExportablePropertiesTransformer{}) + } + if module != nil { bpFile.AddModule(module) } @@ -804,6 +810,50 @@ func (t pruneEmptySetTransformer) transformPropertySetAfterContents(_ string, pr } } +type replaceExportablePropertiesTransformer struct { + identityTransformation +} + +var _ bpTransformer = (*replaceExportablePropertiesTransformer)(nil) + +func handleExportableProperties[T any](value T) any { + switch v := any(value).(type) { + case string: + return java.AllApiScopes.ConvertStubsLibraryExportableToEverything(v) + case *bpPropertySet: + v.properties = handleExportableProperties(v.properties).(map[string]interface{}) + return v + case []string: + result := make([]string, len(v)) + for i, elem := range v { + result[i] = handleExportableProperties(elem).(string) + } + return result + case []any: + result := make([]any, len(v)) + for i, elem := range v { + result[i] = handleExportableProperties(elem) + } + return result + case map[string]any: + result := make(map[string]any) + for k, val := range v { + result[k] = handleExportableProperties(val) + } + return result + default: + return value + } +} + +func (t replaceExportablePropertiesTransformer) transformPropertySetAfterContents(name string, propertySet *bpPropertySet, tag android.BpPropertyTag) (*bpPropertySet, android.BpPropertyTag) { + if name == "name" { + return propertySet, tag + } + propertySet.properties = handleExportableProperties(propertySet.properties).(map[string]interface{}) + return propertySet, tag +} + func generateBpContents(bpFile *bpFile) string { contents := &generatedContents{} contents.IndentedPrintf("// This is auto-generated. DO NOT EDIT.\n") |