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

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

Issue 649683005: Add src-side launcher for telemetry_unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: get_compile_targets.py 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 | testing/scripts/common.py » ('j') | testing/scripts/common.py » ('J')
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
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 12
36 13
37 def mode_run(args): 14 def mode_run(args):
38 with temporary_file() as tempfile_path: 15 with common.temporary_file() as tempfile_path:
39 rc = run_command([ 16 rc = common.run_command([
40 os.path.join(SRC_DIR, 'buildtools', 'checkdeps', 'checkdeps.py'), 17 os.path.join(common.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 with open(args.output, 'w') as f:
53 json.dump({ 30 json.dump({
54 'valid': True, 31 'valid': True,
55 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set], 32 'failures': ['%s: %s' % (r[0], r[1]) for r in result_set],
56 }, f) 33 }, f)
57 34
58 return rc 35 return rc
59 36
60 37
61 def main(argv): 38 def mode_compile_targets(args):
iannucci 2014/10/22 07:23:14 I would drop the mode_ prefix from these. maybe 'm
Paweł Hajdan Jr. 2014/10/22 09:43:27 Done.
62 parser = argparse.ArgumentParser() 39 with open(args.output, 'w') as f:
63 40 json.dump([], f)
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 41
73 42
74 if __name__ == '__main__': 43 if __name__ == '__main__':
75 sys.exit(main(sys.argv[1:])) 44 sys.exit(common.run_script(sys.argv[1:], mode_run, mode_compile_targets))
iannucci 2014/10/22 07:23:14 what about passing { 'run': mode_run, 'compile
Paweł Hajdan Jr. 2014/10/22 09:43:27 Done.
OLDNEW
« no previous file with comments | « no previous file | testing/scripts/common.py » ('j') | testing/scripts/common.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698