diff options
author | Andreas Sandberg <andreas.sandberg@arm.com> | 2016-03-30 15:30:05 +0100 |
---|---|---|
committer | Andreas Sandberg <andreas.sandberg@arm.com> | 2016-03-30 15:30:05 +0100 |
commit | 062b6c4c9db83c91ef475b09425a1b844d93c72a (patch) | |
tree | 23b9db7a69b773501eb5a27da7a9b547d6e01c48 | |
parent | 7277defc31e67ffcb8c8d2cb45c2ae235d100ee1 (diff) | |
download | gem5-062b6c4c9db83c91ef475b09425a1b844d93c72a.tar.xz |
style: Change include sorter to yield one line at a time
The include sorter class normally yields one string per line and
relies on the caller to merge lines into a block of text separated by
newlines. However, there are cases when this isn't true. This makes
diffing using Python's difflib hard. This changeset updates the
include sorter to never do this and always yield one line at a time.
Signed-off-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Curtis Dunham <curtis.dunham@arm.com>
Reviewed-by: Steve Reinhardt <steve.reinhardt@amd.com>
--HG--
extra : rebase_source : 154c9c7e1ebdd77e09fe5f28d0cfddc9e6c6b1eb
-rw-r--r-- | util/sort_includes.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/util/sort_includes.py b/util/sort_includes.py index 595a648a3..334d9e29e 100644 --- a/util/sort_includes.py +++ b/util/sort_includes.py @@ -204,17 +204,15 @@ class SortIncludes(object): return sorted(set(includes)) def dump_includes(self): - blocks = [] - # Create a list of blocks in the prescribed include - # order. Each entry in the list is a multi-line string with - # multiple includes. + includes = [] for types in self.block_order: - block = "\n".join(self.dump_blocks(types)) - if block: - blocks.append(block) + block = self.dump_blocks(types) + if includes and block: + includes.append("") + includes += block self.reset() - return "\n\n".join(blocks) + return includes def __call__(self, lines, filename, language): self.reset() @@ -263,7 +261,8 @@ class SortIncludes(object): # Output pending includes, a new line between, and the # current l. - yield self.dump_includes() + for include in self.dump_includes(): + yield include yield '' yield line else: @@ -272,9 +271,8 @@ class SortIncludes(object): # We've reached EOF, so dump any pending includes if processing_includes: - yield self.dump_includes() - - + for include in self.dump_includes(): + yield include # default language types to try to apply our sorting rules to default_languages = frozenset(('C', 'C++', 'isa', 'python', 'scons', 'swig')) |