From 4621f412ef5e6cb4c72aa6cb110ee21d8be760b3 Mon Sep 17 00:00:00 2001 From: Andrea Righi Date: Tue, 28 Mar 2023 12:48:03 +0200 Subject: [PATCH] annotations: prevent duplicate include lines Includes are always parsed recursively, but when we save them (e.g., when the annotations file is updated) we should always save only the top-level includes, without repeating the recursive ones. Signed-off-by: Andrea Righi --- kconfig/annotations.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/kconfig/annotations.py b/kconfig/annotations.py index a1ad282..dcc133d 100644 --- a/kconfig/annotations.py +++ b/kconfig/annotations.py @@ -61,7 +61,7 @@ class Annotation(Config): """ Parse body of annotations file """ - def _parse_body(self, data: str): + def _parse_body(self, data: str, parent=True): for line in data.splitlines(): # Replace tabs with spaces, squeeze multiple into singles and # remove leading and trailing spaces @@ -85,10 +85,11 @@ class Annotation(Config): # Handle includes (recursively) m = re.match(r'^include\s+"?([^"]*)"?', line) if m: - self.include.append(m.group(1)) + if parent: + self.include.append(m.group(1)) include_fname = dirname(abspath(self.fname)) + '/' + m.group(1) include_data = self._load(include_fname) - self._parse_body(include_data) + self._parse_body(include_data, parent=False) continue # Handle policy and note lines -- 2.31.1