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

Unified Diff: testing/scripts/checkdeps.py

Issue 645593002: Add src-side launcher for checkdeps (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 6 years, 2 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 | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: testing/scripts/checkdeps.py
diff --git a/testing/scripts/checkdeps.py b/testing/scripts/checkdeps.py
new file mode 100755
index 0000000000000000000000000000000000000000..73fa35be134b6ad506e575553f769af180a92760
--- /dev/null
+++ b/testing/scripts/checkdeps.py
@@ -0,0 +1,75 @@
+#!/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 contextlib
+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
+
+
+@contextlib.contextmanager
+def temporary_file():
+ fd, path = tempfile.mkstemp()
+ os.close(fd)
+ try:
+ yield path
+ finally:
+ os.remove(path)
+
+
+def mode_run(args):
+ with temporary_file() as tempfile_path:
+ rc = run_command([
+ os.path.join(SRC_DIR, 'buildtools', 'checkdeps', 'checkdeps.py'),
+ '--json', tempfile_path
+ ])
+
+ with open(tempfile_path) as f:
+ checkdeps_results = json.load(f)
+
+ result_set = set()
iannucci 2014/10/10 09:30:30 I would de-indent here. No reason to have the file
Paweł Hajdan Jr. 2014/10/10 10:50:43 Done.
+ 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
+
+
+def main(argv):
+ parser = argparse.ArgumentParser()
+
+ subparsers = parser.add_subparsers()
+
+ run_parser = subparsers.add_parser('run')
+ run_parser.add_argument('--output', required=True)
+ run_parser.set_defaults(func=mode_run)
iannucci 2014/10/10 09:30:30 fancy! I didn't know that trick, but it makes sens
+
+ args = parser.parse_args(argv)
+ return args.func(args)
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698