Chromium Code Reviews| Index: build/android/emma_html_output.py |
| diff --git a/build/android/emma_html_output.py b/build/android/emma_html_output.py |
| new file mode 100755 |
| index 0000000000000000000000000000000000000000..4070ab3d183b19775f66cf52124b6dd5a7921441 |
| --- /dev/null |
| +++ b/build/android/emma_html_output.py |
| @@ -0,0 +1,83 @@ |
| +#! /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.
|
| + |
| +# 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.""" |
| + |
| +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. |
| + """ |
| + |
| + 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, |
| + 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.')) |
|
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
|
| + options, args = option_parser.parse_args() |
| + |
| + if not options.coverage_dir: |
| + option_parser.error('--coverage_dir is required.') |
| + return constants.ERROR_EXIT_CODE |
| + |
| + if not options.metadata_dir: |
| + option_parser.error('--metadata_dir is required.') |
| + return constants.ERROR_EXIT_CODE |
| + |
| + 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.
|
| + option_parser.error('--output is required.') |
| + return constants.ERROR_EXIT_CODE |
| + |
| + 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.
|
| + if not android_sdk_root: |
| + logging.error('Environment variable ANDROID_SDK_ROOT must be set.') |
| + return constants.ERROR_EXIT_CODE |
| + |
| + 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.
|
| + |
| + coverage_files = _GetFilesWithExt(options.coverage_dir, '.ec') |
| + metadata_files = _GetFilesWithExt(options.metadata_dir, '.em') |
| + |
| + file_args = [] |
|
frankf
2013/07/25 20:28:19
input_args
gkanwar1
2013/08/01 02:14:35
Done.
|
| + for f in coverage_files + metadata_files: |
| + file_args.append('-in') |
| + file_args.append(f) |
| + |
| + output_args = ['-Dreport.html.out.file', options.output] |
| + |
| + return cmd_helper.RunCmd(['java', '-cp', emma_file, 'emma', |
| + 'report', '-r', 'html'] + file_args + output_args) |
| + |
| + |
| +if __name__ == '__main__': |
| + sys.exit(main(sys.argv)) |