OLD | NEW |
---|---|
(Empty) | |
1 #! /usr/bin/env python | |
frankf
2013/07/25 20:28:19
Rename this to generate_emma_html.py
gkanwar1
2013/08/01 02:14:35
Done.
| |
2 | |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | |
4 # Use of this source code is governed by a BSD-style license that can be | |
5 # found in the LICENSE file. | |
6 | |
7 """Accumulates EMMA coverage files to produce html output.""" | |
8 | |
9 import logging | |
10 import optparse | |
11 import os | |
12 import sys | |
13 | |
14 from pylib import cmd_helper | |
15 from pylib import constants | |
16 | |
17 | |
18 def _GetFilesWithExt(root_dir, ext): | |
19 """Gets all files with a given extension. | |
20 | |
21 Args: | |
22 root_dir: Directory in which to search for files. | |
23 ext: Extension to look for (including dot) | |
24 | |
25 Returns: | |
26 A list of absolute paths to files that match. | |
27 """ | |
28 | |
29 files = [] | |
30 for root, _, filenames in os.walk(root_dir): | |
31 basenames = [f for f in filenames if os.path.splitext(f)[1] == ext] | |
32 files.extend([os.path.join(root, basename) | |
33 for basename in basenames]) | |
34 | |
35 return files | |
36 | |
37 | |
38 def main(argv): | |
39 option_parser = optparse.OptionParser() | |
40 option_parser.add_option('-o', '--output', help='HTML output filename.') | |
41 option_parser.add_option('-c', '--coverage_dir', default=None, | |
42 help=('Root of the directory in which to search for ' | |
43 'coverage data (.ec) files.')) | |
44 option_parser.add_option('-m', '--metadata_dir', default=None, | |
45 help=('Root of the directory in which to search for ' | |
46 'coverage metadata (.em) files.')) | |
frankf
2013/07/25 20:28:19
So you also need the path to the src passed in. Bu
gkanwar1
2013/08/01 02:14:35
See the latest patch set. I introduced an emma_sou
| |
47 options, args = option_parser.parse_args() | |
48 | |
49 if not options.coverage_dir: | |
50 option_parser.error('--coverage_dir is required.') | |
51 return constants.ERROR_EXIT_CODE | |
52 | |
53 if not options.metadata_dir: | |
54 option_parser.error('--metadata_dir is required.') | |
55 return constants.ERROR_EXIT_CODE | |
56 | |
57 if not options.output: | |
frankf
2013/07/25 20:28:19
Just combine these conditionals into one and print
gkanwar1
2013/08/01 02:14:35
Done.
| |
58 option_parser.error('--output is required.') | |
59 return constants.ERROR_EXIT_CODE | |
60 | |
61 android_sdk_root = os.environ.get('ANDROID_SDK_ROOT') | |
frankf
2013/07/25 20:28:19
This is defined in constant.py
gkanwar1
2013/08/01 02:14:35
Done.
| |
62 if not android_sdk_root: | |
63 logging.error('Environment variable ANDROID_SDK_ROOT must be set.') | |
64 return constants.ERROR_EXIT_CODE | |
65 | |
66 emma_file = os.path.join(android_sdk_root, 'tools', 'lib', 'emma.jar') | |
frankf
2013/07/25 20:28:19
-> emma_jar
gkanwar1
2013/08/01 02:14:35
Done.
| |
67 | |
68 coverage_files = _GetFilesWithExt(options.coverage_dir, '.ec') | |
69 metadata_files = _GetFilesWithExt(options.metadata_dir, '.em') | |
70 | |
71 file_args = [] | |
frankf
2013/07/25 20:28:19
input_args
gkanwar1
2013/08/01 02:14:35
Done.
| |
72 for f in coverage_files + metadata_files: | |
73 file_args.append('-in') | |
74 file_args.append(f) | |
75 | |
76 output_args = ['-Dreport.html.out.file', options.output] | |
77 | |
78 return cmd_helper.RunCmd(['java', '-cp', emma_file, 'emma', | |
79 'report', '-r', 'html'] + file_args + output_args) | |
80 | |
81 | |
82 if __name__ == '__main__': | |
83 sys.exit(main(sys.argv)) | |
OLD | NEW |