From 979c1bdfc46262ded3287e43b56bbdaec749f4a1 Mon Sep 17 00:00:00 2001 From: LaMont Jones Date: Wed, 27 Mar 2024 17:37:32 -0700 Subject: [PATCH] release_config: cleanup how default values are used Set the flag value to the default value, rather than waiting until the end to check if it was set anywhere. This matters when the flag is declared `appends=True`. Bug: none Test: manual Ignore-AOSP-First: Will CP, testing on internal first. Change-Id: I8384cf8e0e0caedb5fb5a343f8be23f37bf4dc87 Merged-In: I8384cf8e0e0caedb5fb5a343f8be23f37bf4dc87 --- core/release_config.scl | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/core/release_config.scl b/core/release_config.scl index 728fc1b399..c5815dfe30 100644 --- a/core/release_config.scl +++ b/core/release_config.scl @@ -179,18 +179,23 @@ def release_config(all_flags, all_values): validate(all_flags, _all_flags_schema) validate(all_values, _all_values_schema) + # Final values. + values = {} # Validate flags flag_names = [] flags_dict = {} for flag in all_flags: - if flag["name"] in flag_names: - if equal_flag_declaration(flag, flags_dict[flag["name"]]): + name = flag["name"] + if name in flag_names: + if equal_flag_declaration(flag, flags_dict[name]): continue else: - fail(flag["declared_in"] + ": Duplicate declaration of flag " + flag["name"] + - " (declared first in " + flags_dict[flag["name"]]["declared_in"] + ")") - flag_names.append(flag["name"]) - flags_dict[flag["name"]] = flag + fail(flag["declared_in"] + ": Duplicate declaration of flag " + name + + " (declared first in " + flags_dict[name]["declared_in"] + ")") + flag_names.append(name) + flags_dict[name] = flag + # Set the flag value to the default value. + values[name] = {"name": name, "value": _format_value(flag["default"]), "set_in": flag["declared_in"]} # Record which flags go on which partition partitions = {} @@ -206,7 +211,6 @@ def release_config(all_flags, all_values): # Generate final values. # Only declared flags may have a value. - values = {} for value in all_values: name = value["name"] if name not in flag_names: @@ -227,19 +231,13 @@ def release_config(all_flags, all_values): for partition, names in partitions.items(): result["_ALL_RELEASE_FLAGS.PARTITIONS." + partition] = names for flag in all_flags: - if flag["name"] in values: - val = values[flag["name"]]["value"] - set_in = values[flag["name"]]["set_in"] - else: - val = flag["default"] - set_in = flag["declared_in"] - val = _format_value(val) + val = _format_value(values[flag["name"]]["value"]) result[flag["name"]] = val result["_ALL_RELEASE_FLAGS." + flag["name"] + ".PARTITIONS"] = flag["partitions"] result["_ALL_RELEASE_FLAGS." + flag["name"] + ".DEFAULT"] = _format_value(flag["default"]) result["_ALL_RELEASE_FLAGS." + flag["name"] + ".VALUE"] = val result["_ALL_RELEASE_FLAGS." + flag["name"] + ".DECLARED_IN"] = flag["declared_in"] - result["_ALL_RELEASE_FLAGS." + flag["name"] + ".SET_IN"] = set_in + result["_ALL_RELEASE_FLAGS." + flag["name"] + ".SET_IN"] = values[flag["name"]]["set_in"] result["_ALL_RELEASE_FLAGS." + flag["name"] + ".ORIGIN"] = flag["origin"] return result