From: Andrea Righi Date: Thu, 15 Dec 2022 08:46:20 +0000 (+0100) Subject: annotations: compact same value across all flavour within the same arch X-Git-Tag: v0.1~41 X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=f6ccd8bef5515bcc5ea575b2be29cf3c835d68eb;p=annotations.git annotations: compact same value across all flavour within the same arch Signed-off-by: Andrea Righi --- diff --git a/kconfig/annotations.py b/kconfig/annotations.py index 92167f8..e7eb423 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -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 """