Chromium Code Reviews| Index: build/android/generate_emma_html.py |
| diff --git a/build/android/generate_emma_html.py b/build/android/generate_emma_html.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..47a66171f3c38b77409e2f7f3cb272175b54a977 |
| --- /dev/null |
| +++ b/build/android/generate_emma_html.py |
| @@ -0,0 +1,79 @@ |
| +#!/usr/bin/env python |
| + |
| +# Copyright 2013 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Accumulates EMMA coverage files to produce html output.""" |
|
frankf
2013/08/01 19:57:41
Aggregates
gkanwar1
2013/08/07 19:24:56
Done.
|
| + |
| +import logging |
| +import optparse |
| +import os |
| +import sys |
| + |
| +from pylib import cmd_helper |
| +from pylib import constants |
| + |
| + |
| +def _GetFilesWithExt(root_dir, ext): |
| + """Gets all files with a given extension. |
| + |
| + Args: |
| + root_dir: Directory in which to search for files. |
| + ext: Extension to look for (including dot) |
| + |
| + Returns: |
| + A list of absolute paths to files that match. |
| + """ |
| + |
|
frankf
2013/08/01 19:57:41
no blank line
gkanwar1
2013/08/07 19:24:56
Done.
|
| + files = [] |
| + for root, _, filenames in os.walk(root_dir): |
| + basenames = [f for f in filenames if os.path.splitext(f)[1] == ext] |
| + files.extend([os.path.join(root, basename) |
| + for basename in basenames]) |
| + |
| + return files |
| + |
| + |
| +def main(argv): |
| + option_parser = optparse.OptionParser() |
| + option_parser.add_option('-o', '--output', help='HTML output filename.') |
| + option_parser.add_option('-c', '--coverage_dir', default=None, |
|
frankf
2013/08/01 19:57:41
- not _
also below
gkanwar1
2013/08/07 19:24:56
Done.
|
| + help=('Root of the directory in which to search for ' |
| + 'coverage data (.ec) files.')) |
| + option_parser.add_option('-m', '--metadata_dir', default=None, |
| + help=('Root of the directory in which to search for ' |
| + 'coverage metadata (.em) files.')) |
| + options, args = option_parser.parse_args() |
| + |
| + if not (options.coverage_dir and options.metadata_dir and options.output): |
| + option_parser.error('All arguments are required.') |
| + return constants.ERROR_EXIT_CODE |
| + |
| + emma_jar = os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'lib', |
| + 'emma.jar') |
| + |
| + coverage_files = _GetFilesWithExt(options.coverage_dir, '.ec') |
| + metadata_files = _GetFilesWithExt(options.metadata_dir, '.em') |
| + sources_files = [] |
| + for f in metadata_files: |
| + sources_file = os.path.join(os.path.dirname(f), 'emma_sources.txt') |
| + if os.path.exists(sources_file): |
| + with open(sources_file, 'r') as f: |
| + sources_files.extend(f.read().split(' ')) |
|
frankf
2013/08/01 19:57:41
can you just split()
gkanwar1
2013/08/07 19:24:56
Good point. That's more robust also.
|
| + |
| + input_args = [] |
| + for f in coverage_files + metadata_files: |
| + input_args.append('-in') |
| + input_args.append(f) |
| + |
| + output_args = ['-Dreport.html.out.file', options.output] |
| + source_args = ['-sp', ','.join(sources_files)] |
| + |
| + return cmd_helper.RunCmd(['java', '-cp', emma_jar, 'emma', |
|
frankf
2013/08/01 19:57:41
align on next line
gkanwar1
2013/08/07 19:24:56
I assume by this you mean to move all args down to
|
| + 'report', '-r', 'html'] |
| + + input_args + output_args + source_args) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |