OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 4 # Use of this source code is governed by a BSD-style license that can be |
5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
6 | 6 |
7 """Instruments classes and jar files. | 7 """Instruments classes and jar files. |
8 | 8 |
9 This script corresponds to the 'emma_instr' action in the java build process. | 9 This script corresponds to the 'emma_instr' action in the java build process. |
10 Depending on whether emma_instrument is set, the 'emma_instr' action will either | 10 Depending on whether emma_instrument is set, the 'emma_instr' action will either |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 50 |
51 def _AddInstrumentOptions(option_parser): | 51 def _AddInstrumentOptions(option_parser): |
52 """Adds options related to instrumentation to |option_parser|.""" | 52 """Adds options related to instrumentation to |option_parser|.""" |
53 _AddCommonOptions(option_parser) | 53 _AddCommonOptions(option_parser) |
54 option_parser.add_option('--sources', | 54 option_parser.add_option('--sources', |
55 help='Space separated list of sources.') | 55 help='Space separated list of sources.') |
56 option_parser.add_option('--src-root', | 56 option_parser.add_option('--src-root', |
57 help='Root of the src repository.') | 57 help='Root of the src repository.') |
58 option_parser.add_option('--emma-jar', | 58 option_parser.add_option('--emma-jar', |
59 help='Path to emma.jar.') | 59 help='Path to emma.jar.') |
| 60 option_parser.add_option( |
| 61 '--filter-string', default='', |
| 62 help=('Filter string consisting of a list of inclusion/exclusion ' |
| 63 'patterns separated with whitespace and/or comma.')) |
60 | 64 |
61 | 65 |
62 def _RunCopyCommand(command, options, args, option_parser): | 66 def _RunCopyCommand(command, options, args, option_parser): |
63 """Copies the jar from input to output locations. | 67 """Copies the jar from input to output locations. |
64 | 68 |
65 Also removes any old coverage/sources file. | 69 Also removes any old coverage/sources file. |
66 | 70 |
67 Args: | 71 Args: |
68 command: String indicating the command that was received to trigger | 72 command: String indicating the command that was received to trigger |
69 this function. | 73 this function. |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 options.coverage_file and options.sources_file and options.sources and | 147 options.coverage_file and options.sources_file and options.sources and |
144 options.src_root and options.emma_jar): | 148 options.src_root and options.emma_jar): |
145 option_parser.error('All arguments are required.') | 149 option_parser.error('All arguments are required.') |
146 | 150 |
147 coverage_file = os.path.join(os.path.dirname(options.output_path), | 151 coverage_file = os.path.join(os.path.dirname(options.output_path), |
148 options.coverage_file) | 152 options.coverage_file) |
149 sources_file = os.path.join(os.path.dirname(options.output_path), | 153 sources_file = os.path.join(os.path.dirname(options.output_path), |
150 options.sources_file) | 154 options.sources_file) |
151 temp_dir = tempfile.mkdtemp() | 155 temp_dir = tempfile.mkdtemp() |
152 try: | 156 try: |
153 # TODO(gkanwar): Add '-ix' option to filter out useless classes. | 157 cmd = ['java', '-cp', options.emma_jar, |
154 build_utils.CheckCallDie(['java', '-cp', options.emma_jar, | 158 'emma', 'instr', |
155 'emma', 'instr', | 159 '-ip', options.input_path, |
156 '-ip', options.input_path, | 160 '-ix', options.filter_string, |
157 '-d', temp_dir, | 161 '-d', temp_dir, |
158 '-out', coverage_file, | 162 '-out', coverage_file, |
159 '-m', 'fullcopy'], suppress_output=True) | 163 '-m', 'fullcopy'] |
| 164 build_utils.CheckCallDie(cmd, suppress_output=True) |
160 | 165 |
161 if command == 'instrument_jar': | 166 if command == 'instrument_jar': |
162 for jar in os.listdir(os.path.join(temp_dir, 'lib')): | 167 for jar in os.listdir(os.path.join(temp_dir, 'lib')): |
163 shutil.copy(os.path.join(temp_dir, 'lib', jar), | 168 shutil.copy(os.path.join(temp_dir, 'lib', jar), |
164 options.output_path) | 169 options.output_path) |
165 else: # 'instrument_classes' | 170 else: # 'instrument_classes' |
166 if os.path.isdir(options.output_path): | 171 if os.path.isdir(options.output_path): |
167 shutil.rmtree(options.output_path, ignore_errors=True) | 172 shutil.rmtree(options.output_path, ignore_errors=True) |
168 shutil.copytree(os.path.join(temp_dir, 'classes'), | 173 shutil.copytree(os.path.join(temp_dir, 'classes'), |
169 options.output_path) | 174 options.output_path) |
(...skipping 21 matching lines...) Expand all Loading... |
191 | 196 |
192 | 197 |
193 def main(argv): | 198 def main(argv): |
194 option_parser = command_option_parser.CommandOptionParser( | 199 option_parser = command_option_parser.CommandOptionParser( |
195 commands_dict=VALID_COMMANDS) | 200 commands_dict=VALID_COMMANDS) |
196 command_option_parser.ParseAndExecute(option_parser) | 201 command_option_parser.ParseAndExecute(option_parser) |
197 | 202 |
198 | 203 |
199 if __name__ == '__main__': | 204 if __name__ == '__main__': |
200 sys.exit(main(sys.argv)) | 205 sys.exit(main(sys.argv)) |
OLD | NEW |