diff options
| author | Ulf Magnusson <ulfalizer@gmail.com> | 2019-05-28 15:51:58 +0200 |
|---|---|---|
| committer | Ulf Magnusson <ulfalizer@gmail.com> | 2019-05-28 17:00:24 +0200 |
| commit | 3aea9f74d250817924fff80c73c42edb84e509a1 (patch) | |
| tree | ba5d6949669a306e20b8ae072a79478cbb494519 | |
| parent | 8279491bedfa5245415efad69b94b79769c8abe4 (diff) | |
Add '# end of <menu>' after menus in .config
Mirrors commit aff11cd983ec ("kconfig: Terminate menu blocks with a
comment in the generated config") in the kernel.
This makes the compatibility tests pass again, and is handy.
| -rw-r--r-- | kconfiglib.py | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/kconfiglib.py b/kconfiglib.py index aa2e437..65399b4 100644 --- a/kconfiglib.py +++ b/kconfiglib.py @@ -1391,17 +1391,61 @@ class Kconfig(object): with self._open(filename, "w") as f: f.write(header) - for node in self.node_iter(unique_syms=True): + for sym in self.unique_defined_syms: + sym._visited = False + + # Did we just print an '# end of ...' comment? + after_end_comment = False + + node = self.top_node + while 1: + # Jump to the next node with an iterative tree walk + if node.list: + node = node.list + elif node.next: + node = node.next + else: + while node.parent: + node = node.parent + + # Print a comment when leaving visible menus + if node.item is MENU and expr_value(node.dep) and \ + expr_value(node.visibility) and \ + node is not self.top_node: + f.write("# end of {}\n".format(node.prompt[0])) + after_end_comment = True + + if node.next: + node = node.next + break + else: + # No more nodes + return + item = node.item if item.__class__ is Symbol: - f.write(item.config_string) + if item._visited: + continue + item._visited = True + + conf_string = item.config_string + if not conf_string: + continue + + if after_end_comment: + # Add a blank line before the first symbol printed + # after an '# end of ...' comment + after_end_comment = False + f.write("\n") + f.write(conf_string) elif expr_value(node.dep) and \ ((item is MENU and expr_value(node.visibility)) or item is COMMENT): f.write("\n#\n# {}\n#\n".format(node.prompt[0])) + after_end_comment = False if verbose: print("Configuration written to '{}'".format(filename)) |
