From 7a79eea193bbe2a77cc48c7404f085f16904f699 Mon Sep 17 00:00:00 2001 From: Juerg Haefliger Date: Tue, 7 Feb 2023 08:36:04 +0100 Subject: [PATCH] UBUNTU: [Packaging] annotations: Clean up policy writes The logic to determine if policy lines need to be written to the output file is a little convoluted. Basically, if there is no 'policy' key in a config, there is nothing to do, so put that check at the beginning of the loop. Signed-off-by: Juerg Haefliger Signed-off-by: Andrea Righi --- debian/scripts/misc/kconfig/annotations.py | 34 ++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/debian/scripts/misc/kconfig/annotations.py b/debian/scripts/misc/kconfig/annotations.py index 2af5f7c5b17b..ee679903d9da 100644 --- a/debian/scripts/misc/kconfig/annotations.py +++ b/debian/scripts/misc/kconfig/annotations.py @@ -276,25 +276,29 @@ class Annotation(Config): # Only save local differences (preserve includes) for conf in sorted(self.config): - old_val = tmp_a.config[conf] if conf in tmp_a.config else None new_val = self.config[conf] + if 'policy' not in new_val: + continue + # If new_val is a subset of old_val, skip it - if old_val and 'policy' in old_val and 'policy' in new_val: + old_val = tmp_a.config.get(conf) + if old_val and 'policy' in old_val: if old_val['policy'] == old_val['policy'] | new_val['policy']: continue - if 'policy' in new_val: - val = dict(sorted(new_val['policy'].items())) - line = f"{conf : <47} policy<{val}>" - if 'note' in new_val: - val = new_val['note'] - if new_val.get('oneline', False): - # Single line - line += f' note<{val}>' - else: - # Separate policy and note lines, - # followed by an empty line - line += f'\n{conf : <47} note<{val}>\n' - tmp.write(line + "\n") + + # Write out the policy (and note) line(s) + val = dict(sorted(new_val['policy'].items())) + line = f"{conf : <47} policy<{val}>" + if 'note' in new_val: + val = new_val['note'] + if new_val.get('oneline', False): + # Single line + line += f' note<{val}>' + else: + # Separate policy and note lines, + # followed by an empty line + line += f'\n{conf : <47} note<{val}>\n' + tmp.write(line + "\n") # Replace annotations with the updated version tmp.flush()