Index: cheddar_monkey.py |
diff --git a/cheddar_monkey.py b/cheddar_monkey.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..6c5e70f231a7d9ff32f6af72d260fd89a2313d45 |
--- /dev/null |
+++ b/cheddar_monkey.py |
@@ -0,0 +1,59 @@ |
+#!/usr/bin/env python |
+# Copyright 2016 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import argparse |
+import os |
+import re |
+import subprocess |
+import sys |
+ |
+# Clang errors look like this: |
+# ../../base/test/test_discardable_memory_allocator.cc:22:5: error: use of undeclared identifier 'DCHECK' |
+_CLANG_ERROR_RE = re.compile('(?P<path>[^:]+):\d+:\d+: error: .+') |
+ |
+ |
+def FindFirstFileWithError(output): |
+ for line in output.splitlines(): |
+ match = _CLANG_ERROR_RE.match(line) |
+ if match: |
+ return match.group('path') |
+ |
+ |
+def main(): |
+ parser = argparse.ArgumentParser() |
+ parser.add_argument('--header', required=True) |
+ parser.add_argument('--build-dir', default='.') |
+ parser.add_argument('additional_build_args', nargs='*') |
+ args = parser.parse_args() |
+ |
+ while True: |
+ try: |
+ ninja_args = ['ninja'] |
+ ninja_args.extend(['-C', args.build_dir]) |
+ ninja_args.extend(args.additional_build_args) |
+ print 'Running %s' % ninja_args |
+ subprocess.check_output(ninja_args) |
+ except subprocess.CalledProcessError as e: |
+ print 'Got a compile error!' |
+ bad_file = FindFirstFileWithError(e.output) |
+ if not bad_file: |
+ print 'Something bad happened!' |
+ print e.output |
+ return 2 |
+ bad_file_path = os.path.join(args.build_dir, bad_file) |
+ add_header_args = ['python', 'tools/clang/pass_to_move/add_header.py', |
+ '--header', args.header, bad_file_path] |
+ print 'Inserting header with command %s' % add_header_args |
+ subprocess.check_call(add_header_args) |
+ continue |
+ except Exception as e: |
+ print 'Something weird happened: %s' % e |
+ return 1 |
+ print 'Probably done! \(^.^)/' |
+ break |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main()) |