Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Unified Diff: tools/sort_sources.py

Issue 917083002: Sort GYP files under base using tools/sort_sources.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix the bug Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« base/base.gypi ('K') | « base/base.gypi ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/sort_sources.py
diff --git a/tools/sort_sources.py b/tools/sort_sources.py
index 83d27f0e636e2882f7cd84f5ed1091b1ff81d262..60d388100f387ab462272c074a0f63d17942714a 100755
--- a/tools/sort_sources.py
+++ b/tools/sort_sources.py
@@ -18,8 +18,9 @@ from yes_no import YesNo
SUFFIXES = ['c', 'cc', 'cpp', 'h', 'mm', 'rc', 'rc.version', 'ico', 'def',
'release']
-PATTERN = re.compile('^\s+[\'"].*\.(%s)[\'"],$' %
- '|'.join([re.escape(x) for x in SUFFIXES]))
+SOURCE_PATTERN = re.compile('^\s+[\'"].*\.(%s)[\'"],$' %
+ '|'.join([re.escape(x) for x in SUFFIXES]))
+COMMENT_PATTERN = re.compile('^\s+#')
def SortSources(original_lines):
"""Sort source file names in |original_lines|.
@@ -30,21 +31,31 @@ def SortSources(original_lines):
Returns:
Lines of the sorted content as a list of strings.
- The algorithm is fairly naive. The code tries to find a list of C-ish source
- file names by a simple regex, then sort them. The code does not try to
- understand the syntax of the build files, hence there are many cases that
- the code cannot handle correctly (ex. comments within a list of source file
- names).
+ The algorithm is fairly naive. The code tries to find a list of C-ish
+ source file names by a simple regex, then sort them. The code does not try
+ to understand the syntax of the build files, hence there are some cases
+ that the code cannot handle correctly (ex. blank lines within a list of
+ source file names).
"""
output_lines = []
+ comments = []
sources = []
for line in original_lines:
- if re.search(PATTERN, line):
- sources.append(line)
+ if re.search(COMMENT_PATTERN, line):
+ comments.append(line)
+ elif re.search(SOURCE_PATTERN, line):
+ # Associate the line with the preceeding comments.
+ sources.append([line, comments])
+ comments = []
else:
+ if comments:
+ output_lines.extend(comments)
+ comments = []
if sources:
- output_lines.extend(sorted(sources))
+ for source_line, source_comments in sorted(sources):
+ output_lines.extend(source_comments)
+ output_lines.append(source_line)
sources = []
output_lines.append(line)
return output_lines
« base/base.gypi ('K') | « base/base.gypi ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698