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 11 matching lines...) Expand all Loading... |
22 import collections | 22 import collections |
23 import json | 23 import json |
24 import os | 24 import os |
25 import shutil | 25 import shutil |
26 import sys | 26 import sys |
27 import tempfile | 27 import tempfile |
28 | 28 |
29 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) | 29 sys.path.append(os.path.join(os.path.dirname(__file__), os.pardir)) |
30 from pylib.utils import command_option_parser | 30 from pylib.utils import command_option_parser |
31 | 31 |
32 from util import build_utils # pylint: disable=F0401 | 32 from util import build_utils |
33 | 33 |
34 | 34 |
35 def _AddCommonOptions(option_parser): | 35 def _AddCommonOptions(option_parser): |
36 """Adds common options to |option_parser|.""" | 36 """Adds common options to |option_parser|.""" |
37 option_parser.add_option('--input-path', | 37 option_parser.add_option('--input-path', |
38 help=('Path to input file(s). Either the classes ' | 38 help=('Path to input file(s). Either the classes ' |
39 'directory, or the path to a jar.')) | 39 'directory, or the path to a jar.')) |
40 option_parser.add_option('--output-path', | 40 option_parser.add_option('--output-path', |
41 help=('Path to output final file(s) to. Either the ' | 41 help=('Path to output final file(s) to. Either the ' |
42 'final classes directory, or the directory in ' | 42 'final classes directory, or the directory in ' |
(...skipping 13 matching lines...) Expand all Loading... |
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( | 60 option_parser.add_option( |
61 '--filter-string', default='', | 61 '--filter-string', default='', |
62 help=('Filter string consisting of a list of inclusion/exclusion ' | 62 help=('Filter string consisting of a list of inclusion/exclusion ' |
63 'patterns separated with whitespace and/or comma.')) | 63 'patterns separated with whitespace and/or comma.')) |
64 | 64 |
65 | 65 |
66 def _RunCopyCommand(_command, options, _, option_parser): | 66 def _RunCopyCommand(command, options, args, option_parser): |
67 """Copies the jar from input to output locations. | 67 """Copies the jar from input to output locations. |
68 | 68 |
69 Also removes any old coverage/sources file. | 69 Also removes any old coverage/sources file. |
70 | 70 |
71 Args: | 71 Args: |
72 command: String indicating the command that was received to trigger | 72 command: String indicating the command that was received to trigger |
73 this function. | 73 this function. |
74 options: optparse options dictionary. | 74 options: optparse options dictionary. |
75 args: List of extra args from optparse. | 75 args: List of extra args from optparse. |
76 option_parser: optparse.OptionParser object. | 76 option_parser: optparse.OptionParser object. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 % (abs_source, src_root)) | 122 % (abs_source, src_root)) |
123 return 1 | 123 return 1 |
124 rel_source = os.path.relpath(abs_source, src_root) | 124 rel_source = os.path.relpath(abs_source, src_root) |
125 | 125 |
126 relative_sources.append(rel_source) | 126 relative_sources.append(rel_source) |
127 | 127 |
128 with open(sources_file, 'w') as f: | 128 with open(sources_file, 'w') as f: |
129 json.dump(relative_sources, f) | 129 json.dump(relative_sources, f) |
130 | 130 |
131 | 131 |
132 def _RunInstrumentCommand(command, options, _, option_parser): | 132 def _RunInstrumentCommand(command, options, args, option_parser): |
133 """Instruments the classes/jar files using EMMA. | 133 """Instruments the classes/jar files using EMMA. |
134 | 134 |
135 Args: | 135 Args: |
136 command: 'instrument_jar' or 'instrument_classes'. This distinguishes | 136 command: 'instrument_jar' or 'instrument_classes'. This distinguishes |
137 whether we copy the output from the created lib/ directory, or classes/ | 137 whether we copy the output from the created lib/ directory, or classes/ |
138 directory. | 138 directory. |
139 options: optparse options dictionary. | 139 options: optparse options dictionary. |
140 args: List of extra args from optparse. | 140 args: List of extra args from optparse. |
141 option_parser: optparse.OptionParser object. | 141 option_parser: optparse.OptionParser object. |
142 | 142 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 VALID_COMMANDS = { | 190 VALID_COMMANDS = { |
191 'copy': CommandFunctionTuple(_AddCommonOptions, | 191 'copy': CommandFunctionTuple(_AddCommonOptions, |
192 _RunCopyCommand), | 192 _RunCopyCommand), |
193 'instrument_jar': CommandFunctionTuple(_AddInstrumentOptions, | 193 'instrument_jar': CommandFunctionTuple(_AddInstrumentOptions, |
194 _RunInstrumentCommand), | 194 _RunInstrumentCommand), |
195 'instrument_classes': CommandFunctionTuple(_AddInstrumentOptions, | 195 'instrument_classes': CommandFunctionTuple(_AddInstrumentOptions, |
196 _RunInstrumentCommand), | 196 _RunInstrumentCommand), |
197 } | 197 } |
198 | 198 |
199 | 199 |
200 def main(): | 200 def main(argv): |
201 option_parser = command_option_parser.CommandOptionParser( | 201 option_parser = command_option_parser.CommandOptionParser( |
202 commands_dict=VALID_COMMANDS) | 202 commands_dict=VALID_COMMANDS) |
203 command_option_parser.ParseAndExecute(option_parser) | 203 command_option_parser.ParseAndExecute(option_parser) |
204 | 204 |
205 | 205 |
206 if __name__ == '__main__': | 206 if __name__ == '__main__': |
207 sys.exit(main()) | 207 sys.exit(main(sys.argv)) |
OLD | NEW |