| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 # | 5 # |
| 6 # Script to apply fixits generated by clang. This is to work around the fact | 6 # Script to apply fixits generated by clang. This is to work around the fact |
| 7 # that clang's -Xclang -fixit-recompile flag, which automatically applies fixits | 7 # that clang's -Xclang -fixit-recompile flag, which automatically applies fixits |
| 8 # and recompiles, doesn't work well with parallel invocations of clang. | 8 # and recompiles, doesn't work well with parallel invocations of clang. |
| 9 # | 9 # |
| 10 # Usage: | 10 # Usage: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 def main(): | 41 def main(): |
| 42 parser = argparse.ArgumentParser() | 42 parser = argparse.ArgumentParser() |
| 43 parser.add_argument( | 43 parser.add_argument( |
| 44 'build_directory', | 44 'build_directory', |
| 45 nargs='?', | 45 nargs='?', |
| 46 default='out/Debug', | 46 default='out/Debug', |
| 47 help='path to the build directory to complete relative paths in fixits') | 47 help='path to the build directory to complete relative paths in fixits') |
| 48 args = parser.parse_args() | 48 args = parser.parse_args() |
| 49 | 49 |
| 50 fixits = collections.defaultdict(list) | 50 fixits = collections.defaultdict(list) |
| 51 for line in fileinput.input(): | 51 for line in fileinput.input(['-']): |
| 52 if not line.startswith('fix-it:'): | 52 if not line.startswith('fix-it:'): |
| 53 continue | 53 continue |
| 54 m = _FIXIT_RE.match(line) | 54 m = _FIXIT_RE.match(line) |
| 55 if not m: | 55 if not m: |
| 56 continue | 56 continue |
| 57 # The negative line numbers are a cheap hack so we can sort things in line | 57 # The negative line numbers are a cheap hack so we can sort things in line |
| 58 # order but reverse column order. Applying the fixits in reverse order makes | 58 # order but reverse column order. Applying the fixits in reverse order makes |
| 59 # things simpler, since offsets won't have to be adjusted as the text is | 59 # things simpler, since offsets won't have to be adjusted as the text is |
| 60 # changed. | 60 # changed. |
| 61 fixits[m.group('file')].append(FixIt( | 61 fixits[m.group('file')].append(FixIt( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 79 line = lines[fixit.start_line - 1] | 79 line = lines[fixit.start_line - 1] |
| 80 lines[fixit.start_line - 1] = (line[:-fixit.start_col - 1] + fixit.text | 80 lines[fixit.start_line - 1] = (line[:-fixit.start_col - 1] + fixit.text |
| 81 + line[-fixit.end_col - 1:]) | 81 + line[-fixit.end_col - 1:]) |
| 82 f.seek(0) | 82 f.seek(0) |
| 83 f.truncate() | 83 f.truncate() |
| 84 f.writelines(lines) | 84 f.writelines(lines) |
| 85 | 85 |
| 86 | 86 |
| 87 if __name__ == '__main__': | 87 if __name__ == '__main__': |
| 88 sys.exit(main()) | 88 sys.exit(main()) |
| OLD | NEW |