Index: testing/scripts/checkdeps.py |
diff --git a/testing/scripts/checkdeps.py b/testing/scripts/checkdeps.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..6657c804ffd17e19a1e508cd5242f817116d1c24 |
--- /dev/null |
+++ b/testing/scripts/checkdeps.py |
@@ -0,0 +1,70 @@ |
+#!/usr/bin/env python |
+# Copyright 2014 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 json |
+import os |
+import subprocess |
+import sys |
+import tempfile |
+ |
+ |
+SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) |
+SRC_DIR = os.path.abspath( |
+ os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir)) |
+ |
+ |
+def run_command(argv): |
+ print 'Running %r' % argv |
+ rc = subprocess.call(argv) |
+ print 'Command %r returned exit code %d' % (argv, rc) |
+ return rc |
+ |
+ |
+def mode_run(args): |
+ try: |
+ fd, tempfile_path = tempfile.mkstemp() |
+ os.close(fd) |
+ |
+ rc = run_command([ |
+ os.path.join(SRC_DIR, 'buildtools', 'checkdeps', 'checkdeps.py'), |
+ '--json', tempfile_path |
+ ]) |
+ |
+ with open(tempfile_path) as f: |
iannucci
2014/10/10 08:53:50
does this have to run on windows? if not, you can
Paweł Hajdan Jr.
2014/10/10 09:21:20
Good suggestion, thanks for it and applied. Yes, t
|
+ checkdeps_results = json.load(f) |
+ |
+ result_set = set() |
+ for result in checkdeps_results: |
+ for violation in result['violations']: |
+ result_set.add((result['dependee_path'], violation['include_path'])) |
+ |
+ with open(args.output, 'w') as f: |
+ json.dump({ |
+ 'valid': True, |
+ 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set], |
+ }, f) |
+ |
+ return rc |
+ finally: |
+ os.remove(tempfile_path) |
+ |
+ |
+def main(argv): |
+ parser = argparse.ArgumentParser() |
iannucci
2014/10/10 08:53:49
why not subparsers? e.g. `cmd run --output /path/t
Paweł Hajdan Jr.
2014/10/10 09:21:20
Done.
|
+ parser.add_argument('--mode', required=True) |
+ parser.add_argument('--output', required=True) |
+ |
+ args = parser.parse_args(argv) |
+ |
+ if args.mode == 'run': |
iannucci
2014/10/10 08:53:50
then argparse does this for you
|
+ return mode_run(args) |
+ |
+ print 'Unhandled mode %r' % args.mode |
iannucci
2014/10/10 08:53:50
you should use parser.error for this sort of thing
|
+ return 1 |
+ |
+ |
+if __name__ == '__main__': |
+ sys.exit(main(sys.argv[1:])) |