From 1d674c2619b3664c23cf6e5a2e718e9ff58ea831 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Tue, 12 Dec 2023 17:02:12 +0100 Subject: [PATCH] annotations: properly update arch overrides New rules that are overriding a whole arch should also override all the correspondent flavours for that particular arch. Signed-off-by: Andrea Righi --- kconfig/annotations.py | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/kconfig/annotations.py b/kconfig/annotations.py index 98121d9..69cf501 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -110,13 +110,22 @@ class Annotation(Config): m = re.match(r".* policy<(.*?)>", line) if m: match = True - try: - entry["policy"] |= literal_eval(m.group(1)) - except TypeError: - entry["policy"] = { - **entry["policy"], - **literal_eval(m.group(1)), - } + # Update the previous entry considering potential overrides: + # - if the new entry is adding a rule for a new + # arch/flavour, simply add that + # - if the new entry is overriding a previous + # arch-flavour item, then overwrite that item + # - if the new entry is overriding a whole arch, then + # remove all the previous flavour rules of that arch + new_entry = literal_eval(m.group(1)) + for key in new_entry: + if key in self.arch: + for flavour_key in list(entry["policy"].keys()): + if flavour_key.startswith(key): + del entry["policy"][flavour_key] + entry["policy"][key] = new_entry[key] + else: + entry["policy"][key] = new_entry[key] m = re.match(r".* note<(.*?)>", line) if m: -- 2.31.1