OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import argparse |
| 7 import os |
| 8 import re |
| 9 import subprocess |
| 10 import sys |
| 11 |
| 12 # Clang errors look like this: |
| 13 # ../../base/test/test_discardable_memory_allocator.cc:22:5: error: use of undec
lared identifier 'DCHECK' |
| 14 _CLANG_ERROR_RE = re.compile('(?P<path>[^:]+):\d+:\d+: error: .+') |
| 15 |
| 16 |
| 17 def FindFirstFileWithError(output): |
| 18 for line in output.splitlines(): |
| 19 match = _CLANG_ERROR_RE.match(line) |
| 20 if match: |
| 21 return match.group('path') |
| 22 |
| 23 |
| 24 def main(): |
| 25 parser = argparse.ArgumentParser() |
| 26 parser.add_argument('--header', required=True) |
| 27 parser.add_argument('--build-dir', default='.') |
| 28 parser.add_argument('additional_build_args', nargs='*') |
| 29 args = parser.parse_args() |
| 30 |
| 31 while True: |
| 32 try: |
| 33 ninja_args = ['ninja'] |
| 34 ninja_args.extend(['-C', args.build_dir]) |
| 35 ninja_args.extend(args.additional_build_args) |
| 36 print 'Running %s' % ninja_args |
| 37 subprocess.check_output(ninja_args) |
| 38 except subprocess.CalledProcessError as e: |
| 39 print 'Got a compile error!' |
| 40 bad_file = FindFirstFileWithError(e.output) |
| 41 if not bad_file: |
| 42 print 'Something bad happened!' |
| 43 print e.output |
| 44 return 2 |
| 45 bad_file_path = os.path.join(args.build_dir, bad_file) |
| 46 add_header_args = ['python', 'tools/clang/pass_to_move/add_header.py', |
| 47 '--header', args.header, bad_file_path] |
| 48 print 'Inserting header with command %s' % add_header_args |
| 49 subprocess.check_call(add_header_args) |
| 50 continue |
| 51 except Exception as e: |
| 52 print 'Something weird happened: %s' % e |
| 53 return 1 |
| 54 print 'Probably done! \(^.^)/' |
| 55 break |
| 56 |
| 57 |
| 58 if __name__ == '__main__': |
| 59 sys.exit(main()) |
OLD | NEW |