From 751a4a5fa26fca6553a6eb7a821d017484389eaf Mon Sep 17 00:00:00 2001 From: Cole Faust Date: Tue, 21 May 2024 16:51:59 -0700 Subject: [PATCH] Export release flag types to make/soong And use the types to appropriately type selects on the release variables. Bug: 323382414 Test: Presubmits Change-Id: Ide7eca95662caaa7b4be42e20399d9fcd7fed35f --- android/module.go | 14 ++++++++++++-- android/variable.go | 2 ++ .../release_config_lib/flag_value.go | 19 +++++++++++++++++++ .../release_config_lib/release_configs.go | 3 ++- 4 files changed, 35 insertions(+), 3 deletions(-) diff --git a/android/module.go b/android/module.go index 4dc16888c..c4cc5e617 100644 --- a/android/module.go +++ b/android/module.go @@ -2157,8 +2157,18 @@ func (e configurationEvalutor) EvaluateConfiguration(condition proptools.Configu ctx.OtherModulePropertyErrorf(m, property, "release_flag requires 1 argument, found %d", condition.NumArgs()) return proptools.ConfigurableValueUndefined() } - if v, ok := ctx.Config().productVariables.BuildFlags[condition.Arg(0)]; ok { - return proptools.ConfigurableValueString(v) + if ty, ok := ctx.Config().productVariables.BuildFlagTypes[condition.Arg(0)]; ok { + v := ctx.Config().productVariables.BuildFlags[condition.Arg(0)] + switch ty { + case "unspecified", "obsolete": + return proptools.ConfigurableValueUndefined() + case "string": + return proptools.ConfigurableValueString(v) + case "bool": + return proptools.ConfigurableValueBool(v == "true") + default: + panic("unhandled release flag type: " + ty) + } } return proptools.ConfigurableValueUndefined() case "product_variable": diff --git a/android/variable.go b/android/variable.go index 419bd61de..a3fdafb77 100644 --- a/android/variable.go +++ b/android/variable.go @@ -492,6 +492,8 @@ type ProductVariables struct { BuildFlags map[string]string `json:",omitempty"` + BuildFlagTypes map[string]string `json:",omitempty"` + BuildFromSourceStub *bool `json:",omitempty"` BuildIgnoreApexContributionContents *bool `json:",omitempty"` diff --git a/cmd/release_config/release_config_lib/flag_value.go b/cmd/release_config/release_config_lib/flag_value.go index 59021e260..76363cec4 100644 --- a/cmd/release_config/release_config_lib/flag_value.go +++ b/cmd/release_config/release_config_lib/flag_value.go @@ -74,3 +74,22 @@ func MarshalValue(value *rc_proto.Value) string { return "" } } + +// Returns a string representation of the type of the value for make +func ValueType(value *rc_proto.Value) string { + if value == nil || value.Val == nil { + return "unspecified" + } + switch value.Val.(type) { + case *rc_proto.Value_UnspecifiedValue: + return "unspecified" + case *rc_proto.Value_StringValue: + return "string" + case *rc_proto.Value_BoolValue: + return "bool" + case *rc_proto.Value_Obsolete: + return "obsolete" + default: + panic("Unhandled type") + } +} diff --git a/cmd/release_config/release_config_lib/release_configs.go b/cmd/release_config/release_config_lib/release_configs.go index 403ba1a58..3bffe85f4 100644 --- a/cmd/release_config/release_config_lib/release_configs.go +++ b/cmd/release_config/release_config_lib/release_configs.go @@ -348,6 +348,7 @@ func (configs *ReleaseConfigs) WriteMakefile(outFile, targetRelease string) erro } value := MarshalValue(flag.Value) makeVars[name] = value + addVar(name, "TYPE", ValueType(flag.Value)) addVar(name, "PARTITIONS", strings.Join(decl.Containers, " ")) addVar(name, "DEFAULT", MarshalValue(decl.Value)) addVar(name, "VALUE", value) @@ -356,7 +357,7 @@ func (configs *ReleaseConfigs) WriteMakefile(outFile, targetRelease string) erro addVar(name, "NAMESPACE", *decl.Namespace) } pNames := []string{} - for k, _ := range partitions { + for k := range partitions { pNames = append(pNames, k) } slices.SortFunc(pNames, func(a, b string) int {