annotations: properly update arch overrides
authorAndrea Righi <andrea.righi@canonical.com>
Tue, 12 Dec 2023 16:02:12 +0000 (17:02 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 12 Dec 2023 16:02:12 +0000 (17:02 +0100)
New rules that are overriding a whole arch should also override all the
correspondent flavours for that particular arch.

Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
kconfig/annotations.py

index 98121d967fa96e7a4e571f742cebf3c86f2863bd..69cf5015f771b4b7e409146cc8e069cbf102ff31 100644 (file)
@@ -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: