annotations: compact same value across all flavour within the same arch
authorAndrea Righi <andrea.righi@canonical.com>
Thu, 15 Dec 2022 08:46:20 +0000 (09:46 +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 92167f806849aaa4510ef01419eb6c2dc439c9d1..e7eb42324666f058a16e1993116334e57f987cd9 100644 (file)
@@ -208,11 +208,30 @@ class Annotation(Config):
                     if self.config[conf]['policy'][flavour] == self.config[conf]['policy'][generic]:
                         del self.config[conf]['policy'][flavour]
                         continue
+            # Remove rules for flavours / arches that are not supported (not
+            # listed in the annotations header).
             for flavour in self.config[conf]['policy'].copy():
                 if flavour not in list(set(self.arch + self.flavour)):
                     del self.config[conf]['policy'][flavour]
+            # Drop empty rules
             if not self.config[conf]['policy']:
                 del self.config[conf]
+            else:
+                # Compact same value across all flavour within the same arch
+                for arch in self.arch:
+                    arch_flavours = [i for i in self.flavour if i.startswith(arch)]
+                    value = None
+                    for flavour in arch_flavours:
+                        if flavour not in self.config[conf]['policy']:
+                            break
+                        elif value is None:
+                            value = self.config[conf]['policy'][flavour]
+                        elif value != self.config[conf]['policy'][flavour]:
+                            break
+                    else:
+                        for flavour in arch_flavours:
+                            del self.config[conf]['policy'][flavour]
+                        self.config[conf]['policy'][arch] = value
 
     def save(self, fname: str):
         """ Save annotations data to the annotation file """