OLD | NEW |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Configuration for the shell abstraction. | 5 """Configuration for the shell abstraction. |
6 | 6 |
7 This module declares ShellConfig and knows how to compute it from command-line | 7 This module declares ShellConfig and knows how to compute it from command-line |
8 arguments, applying any default paths inferred from the checkout, configuration | 8 arguments, applying any default paths inferred from the checkout, configuration |
9 file, etc. | 9 file, etc. |
10 """ | 10 """ |
(...skipping 11 matching lines...) Expand all Loading... |
22 class ShellConfig(object): | 22 class ShellConfig(object): |
23 """Configuration for the shell abstraction.""" | 23 """Configuration for the shell abstraction.""" |
24 | 24 |
25 def __init__(self): | 25 def __init__(self): |
26 self.android = None | 26 self.android = None |
27 self.shell_path = None | 27 self.shell_path = None |
28 self.origin = None | 28 self.origin = None |
29 self.map_url_list = [] | 29 self.map_url_list = [] |
30 self.map_origin_list = [] | 30 self.map_origin_list = [] |
31 self.dev_servers = [] | 31 self.dev_servers = [] |
32 self.sky = None | 32 self.content_handlers = dict() |
33 self.verbose = None | 33 self.verbose = None |
34 | 34 |
35 # Android-only. | 35 # Android-only. |
36 self.adb_path = None | 36 self.adb_path = None |
37 self.target_device = None | 37 self.target_device = None |
38 self.logcat_tags = None | 38 self.logcat_tags = None |
39 | 39 |
40 # Desktop-only. | 40 # Desktop-only. |
41 self.use_osmesa = None | 41 self.use_osmesa = None |
42 | 42 |
(...skipping 16 matching lines...) Expand all Loading... |
59 action='store_true') | 59 action='store_true') |
60 parser.add_argument('--shell-path', help='Path of the Mojo shell binary.') | 60 parser.add_argument('--shell-path', help='Path of the Mojo shell binary.') |
61 parser.add_argument('--origin', help='Origin for mojo: URLs. This can be a ' | 61 parser.add_argument('--origin', help='Origin for mojo: URLs. This can be a ' |
62 'web url or a local directory path.') | 62 'web url or a local directory path.') |
63 parser.add_argument('--map-url', action='append', | 63 parser.add_argument('--map-url', action='append', |
64 help='Define a mapping for a url in the format ' | 64 help='Define a mapping for a url in the format ' |
65 '<url>=<url-or-local-file-path>') | 65 '<url>=<url-or-local-file-path>') |
66 parser.add_argument('--map-origin', action='append', | 66 parser.add_argument('--map-origin', action='append', |
67 help='Define a mapping for a url origin in the format ' | 67 help='Define a mapping for a url origin in the format ' |
68 '<origin>=<url-or-local-file-path>') | 68 '<origin>=<url-or-local-file-path>') |
69 parser.add_argument('--sky', action='store_true', | |
70 help='Maps mojo:sky_viewer as the content handler for ' | |
71 'dart apps.') | |
72 parser.add_argument('-v', '--verbose', action="store_true", | 69 parser.add_argument('-v', '--verbose', action="store_true", |
73 help="Increase output verbosity") | 70 help="Increase output verbosity") |
74 | 71 |
75 android_group = parser.add_argument_group('Android-only', | 72 android_group = parser.add_argument_group('Android-only', |
76 'These arguments apply only when --android is passed.') | 73 'These arguments apply only when --android is passed.') |
77 android_group.add_argument('--adb-path', help='Path of the adb binary.') | 74 android_group.add_argument('--adb-path', help='Path of the adb binary.') |
78 android_group.add_argument('--target-device', help='Device to run on.') | 75 android_group.add_argument('--target-device', help='Device to run on.') |
79 android_group.add_argument('--logcat-tags', help='Comma-separated list of ' | 76 android_group.add_argument('--logcat-tags', help='Comma-separated list of ' |
80 'additional logcat tags to display.') | 77 'additional logcat tags to display.') |
81 | 78 |
82 desktop_group = parser.add_argument_group('Desktop-only', | 79 desktop_group = parser.add_argument_group('Desktop-only', |
83 'These arguments apply only when running on desktop.') | 80 'These arguments apply only when running on desktop.') |
84 desktop_group.add_argument('--use-osmesa', action='store_true', | 81 desktop_group.add_argument('--use-osmesa', action='store_true', |
85 help='Configure the native viewport service ' | 82 help='Configure the native viewport service ' |
86 'for off-screen rendering.') | 83 'for off-screen rendering.') |
87 | 84 |
88 config_file_group = parser.add_argument_group('Configuration file', | 85 config_file_group = parser.add_argument_group('Configuration file', |
89 'These arguments allow to modify the behavior regarding the mojoconfig ' | 86 'These arguments allow to modify the behavior regarding the mojoconfig ' |
90 'file.') | 87 'file.') |
91 config_file_group.add_argument('--config-file', type=file, | 88 config_file_group.add_argument('--config-file', type=file, |
92 help='Path of the configuration file to use.') | 89 help='Path of the configuration file to use.') |
| 90 config_file_group.add_argument('--config-alias', action='append', |
| 91 dest='config_aliases', |
| 92 help='Alias to substitute in the config file ' |
| 93 'of the form ALIAS=<value>. Can be passed ' |
| 94 'more than once.') |
93 config_file_group.add_argument('--no-config-file', action='store_true', | 95 config_file_group.add_argument('--no-config-file', action='store_true', |
94 help='Pass to skip automatic discovery of the ' | 96 help='Pass to skip automatic discovery of the ' |
95 'mojoconfig file.') | 97 'mojoconfig file.') |
96 | 98 |
97 # Arguments allowing to indicate the build directory we are targeting when | 99 # Arguments allowing to indicate the build directory we are targeting when |
98 # running within a Chromium-like checkout (e.g. Mojo checkout). These will go | 100 # running within a Chromium-like checkout (e.g. Mojo checkout). These will go |
99 # away once we have devtools config files, see | 101 # away once we have devtools config files, see |
100 # https://github.com/domokit/devtools/issues/28. | 102 # https://github.com/domokit/devtools/issues/28. |
101 chromium_checkout_group = parser.add_argument_group( | 103 chromium_checkout_group = parser.add_argument_group( |
102 'Chromium-like checkout configuration', | 104 'Chromium-like checkout configuration', |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 inferred_paths = paths.infer_paths(script_args.android, script_args.debug, | 140 inferred_paths = paths.infer_paths(script_args.android, script_args.debug, |
139 script_args.target_cpu) | 141 script_args.target_cpu) |
140 shell_config = ShellConfig() | 142 shell_config = ShellConfig() |
141 | 143 |
142 shell_config.android = script_args.android | 144 shell_config.android = script_args.android |
143 shell_config.shell_path = (script_args.shell_path or | 145 shell_config.shell_path = (script_args.shell_path or |
144 inferred_paths['shell_path']) | 146 inferred_paths['shell_path']) |
145 shell_config.origin = script_args.origin | 147 shell_config.origin = script_args.origin |
146 shell_config.map_url_list = script_args.map_url | 148 shell_config.map_url_list = script_args.map_url |
147 shell_config.map_origin_list = script_args.map_origin | 149 shell_config.map_origin_list = script_args.map_origin |
148 shell_config.sky = script_args.sky | |
149 shell_config.verbose = script_args.verbose | 150 shell_config.verbose = script_args.verbose |
150 | 151 |
151 # Android-only. | 152 # Android-only. |
152 shell_config.adb_path = (script_args.adb_path or inferred_paths['adb_path']) | 153 shell_config.adb_path = (script_args.adb_path or inferred_paths['adb_path']) |
153 shell_config.target_device = script_args.target_device | 154 shell_config.target_device = script_args.target_device |
154 shell_config.logcat_tags = script_args.logcat_tags | 155 shell_config.logcat_tags = script_args.logcat_tags |
155 | 156 |
156 # Desktop-only. | 157 # Desktop-only. |
157 shell_config.use_osmesa = script_args.use_osmesa | 158 shell_config.use_osmesa = script_args.use_osmesa |
158 | 159 |
159 if (shell_config.android and not shell_config.origin and | 160 if (shell_config.android and not shell_config.origin and |
160 inferred_paths['build_dir_path']): | 161 inferred_paths['build_dir_path']): |
161 shell_config.origin = inferred_paths['build_dir_path'] | 162 shell_config.origin = inferred_paths['build_dir_path'] |
162 | 163 |
163 # Read the mojoconfig file. | 164 # Read the mojoconfig file. |
164 config_file = script_args.config_file | 165 config_file = script_args.config_file |
165 if not script_args.no_config_file: | 166 if not script_args.no_config_file: |
166 config_file = config_file or _discover_config_file() | 167 config_file = config_file or _discover_config_file() |
167 | 168 |
168 if config_file: | 169 if config_file: |
169 with config_file: | 170 with config_file: |
170 config_file_aliases = [] | 171 config_file_aliases = [] |
| 172 if script_args.config_aliases: |
| 173 for alias_spec in script_args.config_aliases: |
| 174 alias_from, alias_to = alias_spec.split('=') |
| 175 config_file_aliases.append(('@{%s}' % alias_from, alias_to)) |
| 176 |
171 if inferred_paths['build_dir_path']: | 177 if inferred_paths['build_dir_path']: |
172 config_file_aliases.append(('@{BUILD_DIR}', | 178 config_file_aliases.append(('@{BUILD_DIR}', |
173 inferred_paths['build_dir_path'])) | 179 inferred_paths['build_dir_path'])) |
174 | 180 |
175 config = None | 181 config = None |
176 try: | 182 try: |
177 if script_args.verbose: | 183 if script_args.verbose: |
178 print 'Reading config file from: ' + config_file.name | 184 print 'Reading config file from: ' + config_file.name |
179 config = _read_config_file(config_file, config_file_aliases) | 185 config = _read_config_file(config_file, config_file_aliases) |
180 except SyntaxError: | 186 except SyntaxError: |
181 raise ShellConfigurationException('Failed to parse the mojoconfig ' | 187 raise ShellConfigurationException('Failed to parse the mojoconfig ' |
182 'file.') | 188 'file.') |
183 | 189 |
184 if 'dev_servers' in config: | 190 if 'dev_servers' in config: |
185 try: | 191 try: |
186 for dev_server_spec in config['dev_servers']: | 192 for dev_server_spec in config['dev_servers']: |
187 dev_server_config = DevServerConfig() | 193 dev_server_config = DevServerConfig() |
188 dev_server_config.host = dev_server_spec['host'] | 194 dev_server_config.host = dev_server_spec['host'] |
189 dev_server_config.mappings = [] | 195 dev_server_config.mappings = [] |
190 for prefix, path in dev_server_spec['mappings']: | 196 for prefix, path in dev_server_spec['mappings']: |
191 dev_server_config.mappings.append((prefix, path)) | 197 dev_server_config.mappings.append((prefix, path)) |
192 shell_config.dev_servers.append(dev_server_config) | 198 shell_config.dev_servers.append(dev_server_config) |
193 except (ValueError, KeyError): | 199 except (ValueError, KeyError): |
194 raise ShellConfigurationException('Failed to parse dev_servers in ' | 200 raise ShellConfigurationException('Failed to parse dev_servers in ' |
195 'the mojoconfig file.') | 201 'the config file.') |
| 202 |
| 203 if 'content_handlers' in config: |
| 204 try: |
| 205 for (mime_type, |
| 206 content_handler_url) in config['content_handlers'].iteritems(): |
| 207 shell_config.content_handlers[mime_type] = content_handler_url |
| 208 except (ValueError, KeyError): |
| 209 raise ShellConfigurationException('Failed to parse content_handlers in ' |
| 210 'the config file.') |
196 return shell_config | 211 return shell_config |
OLD | NEW |