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

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: 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 json
8 import os
9 import subprocess
10 import sys
11 import tempfile
12
13
14 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__))
15 SRC_DIR = os.path.abspath(
16 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir))
17
18
19 def run_command(argv):
20 print 'Running %r' % argv
21 rc = subprocess.call(argv)
22 print 'Command %r returned exit code %d' % (argv, rc)
23 return rc
24
25
26 def mode_run(args):
27 try:
28 fd, tempfile_path = tempfile.mkstemp()
29 os.close(fd)
30
31 rc = run_command([
32 os.path.join(SRC_DIR, 'buildtools', 'checkdeps', 'checkdeps.py'),
33 '--json', tempfile_path
34 ])
35
36 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
37 checkdeps_results = json.load(f)
38
39 result_set = set()
40 for result in checkdeps_results:
41 for violation in result['violations']:
42 result_set.add((result['dependee_path'], violation['include_path']))
43
44 with open(args.output, 'w') as f:
45 json.dump({
46 'valid': True,
47 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set],
48 }, f)
49
50 return rc
51 finally:
52 os.remove(tempfile_path)
53
54
55 def main(argv):
56 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.
57 parser.add_argument('--mode', required=True)
58 parser.add_argument('--output', required=True)
59
60 args = parser.parse_args(argv)
61
62 if args.mode == 'run':
iannucci 2014/10/10 08:53:50 then argparse does this for you
63 return mode_run(args)
64
65 print 'Unhandled mode %r' % args.mode
iannucci 2014/10/10 08:53:50 you should use parser.error for this sort of thing
66 return 1
67
68
69 if __name__ == '__main__':
70 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