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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2014 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 contextlib
8 import json
9 import os
10 import subprocess
11 import sys
12 import tempfile
13
14
15 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
16 SRC_DIR = os.path.abspath(
17 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir))
18
19
20 def run_command(argv):
21 print 'Running %r' % argv
22 rc = subprocess.call(argv)
23 print 'Command %r returned exit code %d' % (argv, rc)
24 return rc
25
26
27 @contextlib.contextmanager
28 def temporary_file():
29 fd, path = tempfile.mkstemp()
30 os.close(fd)
31 try:
32 yield path
33 finally:
34 os.remove(path)
35
36
37 def mode_run(args):
38 with temporary_file() as tempfile_path:
39 rc = run_command([
40 os.path.join(SRC_DIR, 'buildtools', 'checkdeps', 'checkdeps.py'),
41 '--json', tempfile_path
42 ])
43
44 with open(tempfile_path) as f:
45 checkdeps_results = json.load(f)
46
47 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.
48 for result in checkdeps_results:
49 for violation in result['violations']:
50 result_set.add((result['dependee_path'], violation['include_path']))
51
52 with open(args.output, 'w') as f:
53 json.dump({
54 'valid': True,
55 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set],
56 }, f)
57
58 return rc
59
60
61 def main(argv):
62 parser = argparse.ArgumentParser()
63
64 subparsers = parser.add_subparsers()
65
66 run_parser = subparsers.add_parser('run')
67 run_parser.add_argument('--output', required=True)
68 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
69
70 args = parser.parse_args(argv)
71 return args.func(args)
72
73
74 if __name__ == '__main__':
75 sys.exit(main(sys.argv[1:]))
OLDNEW
« 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