From f6ccd8bef5515bcc5ea575b2be29cf3c835d68eb Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Thu, 15 Dec 2022 09:46:20 +0100 Subject: [PATCH] annotations: compact same value across all flavour within the same arch Signed-off-by: Andrea Righi --- kconfig/annotations.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) 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 """ -- 2.31.1