annotations: make sure to always drop undefined configs
authorAndrea Righi <andrea.righi@canonical.com>
Mon, 30 Jan 2023 08:11:54 +0000 (09:11 +0100)
committerAndrea Righi <andrea.righi@canonical.com>
Mon, 30 Jan 2023 08:12:28 +0000 (09:12 +0100)
Signed-off-by: Andrea Righi <andrea.righi@canonical.com>
kconfig/annotations.py

index 20e7451a0ae17b7c353a85d27dfdc3a2d7077b21..84dd4d26e6af6841c820293192f980aa9222f78e 100644 (file)
@@ -236,6 +236,17 @@ class Annotation(Config):
                         for flavour in arch_flavours:
                             del self.config[conf]['policy'][flavour]
                         self.config[conf]['policy'][arch] = value
+        # After the first round of compaction we may end up having configs that
+        # are undefined across all arches, so do another round of compaction to
+        # drop these settings that are not needed anymore.
+        for conf in self.config.copy():
+            # Remove configs that are all undefined across all arches/flavours
+            if 'policy' in self.config[conf]:
+                if list(set(self.config[conf]['policy'].values())) == ['-']:
+                    self.config[conf]['policy'] = {}
+            # Drop empty rules
+            if not self.config[conf]['policy']:
+                del self.config[conf]
 
     def save(self, fname: str):
         """ Save annotations data to the annotation file """