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

Side by Side Diff: testing/scripts/checkdeps.py

Issue 670183003: Update from chromium 62675d9fb31fb8cedc40f68e78e8445a74f362e7 (Closed) Base URL: git@github.com:domokit/mojo.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 | « testing/buildbot/trybot_analyze_config.json ('k') | testing/scripts/common.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2014 The Chromium Authors. All rights reserved. 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 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import argparse
7 import contextlib
8 import json 6 import json
9 import os 7 import os
10 import subprocess
11 import sys 8 import sys
12 import tempfile
13 9
14 10
15 SCRIPT_DIR = os.path.abspath(os.path.dirname(__file__)) 11 import common
16 SRC_DIR = os.path.abspath(
17 os.path.join(SCRIPT_DIR, os.path.pardir, os.path.pardir))
18 12
19 13
20 def run_command(argv): 14 def main_run(args):
21 print 'Running %r' % argv 15 with common.temporary_file() as tempfile_path:
22 rc = subprocess.call(argv) 16 rc = common.run_command([
23 print 'Command %r returned exit code %d' % (argv, rc) 17 os.path.join(common.SRC_DIR, 'buildtools', 'checkdeps', 'checkdeps.py'),
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 18 '--json', tempfile_path
42 ]) 19 ])
43 20
44 with open(tempfile_path) as f: 21 with open(tempfile_path) as f:
45 checkdeps_results = json.load(f) 22 checkdeps_results = json.load(f)
46 23
47 result_set = set() 24 result_set = set()
48 for result in checkdeps_results: 25 for result in checkdeps_results:
49 for violation in result['violations']: 26 for violation in result['violations']:
50 result_set.add((result['dependee_path'], violation['include_path'])) 27 result_set.add((result['dependee_path'], violation['include_path']))
51 28
52 with open(args.output, 'w') as f: 29 json.dump({
53 json.dump({ 30 'valid': True,
54 'valid': True, 31 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set],
55 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set], 32 }, args.output)
56 }, f)
57 33
58 return rc 34 return rc
59 35
60 36
61 def main(argv): 37 def main_compile_targets(args):
62 parser = argparse.ArgumentParser() 38 json.dump([], args.output)
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)
69
70 args = parser.parse_args(argv)
71 return args.func(args)
72 39
73 40
74 if __name__ == '__main__': 41 if __name__ == '__main__':
75 sys.exit(main(sys.argv[1:])) 42 funcs = {
43 'run': main_run,
44 'compile_targets': main_compile_targets,
45 }
46 sys.exit(common.run_script(sys.argv[1:], funcs))
OLDNEW
« no previous file with comments | « testing/buildbot/trybot_analyze_config.json ('k') | testing/scripts/common.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698