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

Unified Diff: cheddar_monkey.py

Issue 1505823003: Add script to mass add a new #include. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Some fixes Created 4 years, 9 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
« no previous file with comments | « no previous file | tools/clang/pass_to_move/add_header.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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())
« no previous file with comments | « no previous file | tools/clang/pass_to_move/add_header.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698