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 """ |
11 | 11 |
12 import ast | 12 import ast |
13 | 13 |
14 from devtoolslib import paths | 14 from devtoolslib import paths |
15 | 15 |
16 | 16 |
17 class ShellConfigurationException(Exception): | 17 class ShellConfigurationException(Exception): |
18 """Represents an error preventing creating a functional shell abstraction.""" | 18 """Represents an error preventing creating a functional shell abstraction.""" |
19 pass | 19 pass |
20 | 20 |
21 | 21 |
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.mojo_version = None |
27 self.shell_path = None | 28 self.shell_path = None |
28 self.origin = None | 29 self.origin = None |
29 self.map_url_list = [] | 30 self.map_url_list = [] |
30 self.map_origin_list = [] | 31 self.map_origin_list = [] |
31 self.dev_servers = [] | 32 self.dev_servers = [] |
32 self.reuse_servers = False | 33 self.reuse_servers = False |
33 self.content_handlers = dict() | 34 self.content_handlers = dict() |
34 self.verbose = None | 35 self.verbose = None |
35 | 36 |
36 # Android-only. | 37 # Android-only. |
(...skipping 15 matching lines...) Expand all Loading... |
52 self.mappings = None | 53 self.mappings = None |
53 | 54 |
54 | 55 |
55 def add_shell_arguments(parser): | 56 def add_shell_arguments(parser): |
56 """Adds argparse arguments allowing to configure shell abstraction using | 57 """Adds argparse arguments allowing to configure shell abstraction using |
57 configure_shell() below. | 58 configure_shell() below. |
58 """ | 59 """ |
59 # Arguments configuring the shell run. | 60 # Arguments configuring the shell run. |
60 parser.add_argument('--android', help='Run on Android', | 61 parser.add_argument('--android', help='Run on Android', |
61 action='store_true') | 62 action='store_true') |
| 63 parser.add_argument('--mojo-version', help='Version of the Mojo to use. ' |
| 64 'This will set the origin and download the shell binary ' |
| 65 'at the given version') |
62 parser.add_argument('--shell-path', help='Path of the Mojo shell binary.') | 66 parser.add_argument('--shell-path', help='Path of the Mojo shell binary.') |
63 parser.add_argument('--origin', help='Origin for mojo: URLs. This can be a ' | 67 parser.add_argument('--origin', help='Origin for mojo: URLs. This can be a ' |
64 'web url or a local directory path. If MOJO_VERSION file ' | 68 'web url or a local directory path. If MOJO_VERSION file ' |
65 'is among ancestors of this file, by default the origin ' | 69 'is among ancestors of this file, by default the origin ' |
66 'will point to mojo services prebuilt at the ' | 70 'will point to mojo services prebuilt at the ' |
67 'specified version in Google Storage') | 71 'specified version in Google Storage') |
68 parser.add_argument('--map-url', action='append', | 72 parser.add_argument('--map-url', action='append', |
69 help='Define a mapping for a url in the format ' | 73 help='Define a mapping for a url in the format ' |
70 '<url>=<url-or-local-file-path>') | 74 '<url>=<url-or-local-file-path>') |
71 parser.add_argument('--map-origin', action='append', | 75 parser.add_argument('--map-origin', action='append', |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 return ast.literal_eval(spec) | 141 return ast.literal_eval(spec) |
138 | 142 |
139 | 143 |
140 def get_shell_config(script_args): | 144 def get_shell_config(script_args): |
141 """Processes command-line options defined in add_shell_arguments(), applying | 145 """Processes command-line options defined in add_shell_arguments(), applying |
142 any inferred default paths and produces an instance of ShellConfig. | 146 any inferred default paths and produces an instance of ShellConfig. |
143 | 147 |
144 Returns: | 148 Returns: |
145 An instance of ShellConfig. | 149 An instance of ShellConfig. |
146 """ | 150 """ |
147 # Infer paths based on the Chromium configuration options | |
148 # (--debug/--release, etc.), if running within a Chromium-like checkout. | |
149 inferred_params = paths.infer_params(script_args.android, script_args.debug, | |
150 script_args.target_cpu) | |
151 inferred_origin = None | |
152 if inferred_params['mojo_version']: | |
153 inferred_origin = "https://storage.googleapis.com/mojo/services" | |
154 if script_args.android: | |
155 inferred_origin += "/android-arm" | |
156 else: | |
157 inferred_origin += "/linux-x64" | |
158 # Get the versions that were built against Modular's version of the SDK. | |
159 inferred_origin += "/%s" % inferred_params['mojo_version'] | |
160 if script_args.verbose: | |
161 print('Inferring origin from `MOJO_VERSION` as: ' + | |
162 inferred_origin) | |
163 | 151 |
164 shell_config = ShellConfig() | 152 shell_config = ShellConfig() |
165 shell_config.android = script_args.android | 153 shell_config.android = script_args.android |
166 shell_config.shell_path = (script_args.shell_path or | 154 shell_config.mojo_version = script_args.mojo_version |
167 inferred_params['shell_path']) | 155 shell_config.shell_path = script_args.shell_path |
168 shell_config.origin = script_args.origin or inferred_origin | 156 shell_config.origin = script_args.origin |
169 shell_config.map_url_list = script_args.map_url | 157 shell_config.map_url_list = script_args.map_url |
170 shell_config.map_origin_list = script_args.map_origin | 158 shell_config.map_origin_list = script_args.map_origin |
171 shell_config.reuse_servers = script_args.reuse_servers | 159 shell_config.reuse_servers = script_args.reuse_servers |
172 shell_config.verbose = script_args.verbose | 160 shell_config.verbose = script_args.verbose |
173 | 161 |
| 162 # Infer paths based on the Chromium configuration options |
| 163 # (--debug/--release, etc.), if running within a Chromium-like checkout. |
| 164 inferred_params = paths.infer_params(script_args.android, script_args.debug, |
| 165 script_args.target_cpu) |
| 166 # Infer |mojo_version| if the client sets it in a MOJO_VERSION file. |
| 167 shell_config.mojo_version = (shell_config.mojo_version or |
| 168 inferred_params['mojo_version']) |
| 169 # Use the shell binary and mojo: apps from the build directory, unless |
| 170 # |mojo_version| is set. |
| 171 if not shell_config.mojo_version: |
| 172 shell_config.shell_path = (shell_config.shell_path or |
| 173 inferred_params['shell_path']) |
| 174 if shell_config.android: |
| 175 shell_config.origin = (shell_config.origin or |
| 176 inferred_params['build_dir_path']) |
| 177 |
174 # Android-only. | 178 # Android-only. |
175 shell_config.adb_path = (script_args.adb_path or inferred_params['adb_path'] | 179 shell_config.adb_path = (script_args.adb_path or inferred_params['adb_path'] |
176 or 'adb') | 180 or 'adb') |
177 shell_config.target_device = script_args.target_device | 181 shell_config.target_device = script_args.target_device |
178 shell_config.logcat_tags = script_args.logcat_tags | 182 shell_config.logcat_tags = script_args.logcat_tags |
179 | 183 |
180 # Desktop-only. | 184 # Desktop-only. |
181 shell_config.use_osmesa = script_args.use_osmesa | 185 shell_config.use_osmesa = script_args.use_osmesa |
182 | 186 |
183 if (shell_config.android and not shell_config.origin and | |
184 inferred_params['build_dir_path']): | |
185 shell_config.origin = inferred_params['build_dir_path'] | |
186 | |
187 # Read the mojoconfig file. | 187 # Read the mojoconfig file. |
188 config_file = script_args.config_file | 188 config_file = script_args.config_file |
189 if not script_args.no_config_file: | 189 if not script_args.no_config_file: |
190 config_file = config_file or _discover_config_file() | 190 config_file = config_file or _discover_config_file() |
191 | 191 |
192 if config_file: | 192 if config_file: |
193 with config_file: | 193 with config_file: |
194 config_file_aliases = [] | 194 config_file_aliases = [] |
195 if script_args.config_aliases: | 195 if script_args.config_aliases: |
196 for alias_spec in script_args.config_aliases: | 196 for alias_spec in script_args.config_aliases: |
(...skipping 29 matching lines...) Expand all Loading... |
226 | 226 |
227 if 'content_handlers' in config: | 227 if 'content_handlers' in config: |
228 try: | 228 try: |
229 for (mime_type, | 229 for (mime_type, |
230 content_handler_url) in config['content_handlers'].iteritems(): | 230 content_handler_url) in config['content_handlers'].iteritems(): |
231 shell_config.content_handlers[mime_type] = content_handler_url | 231 shell_config.content_handlers[mime_type] = content_handler_url |
232 except (ValueError, KeyError): | 232 except (ValueError, KeyError): |
233 raise ShellConfigurationException('Failed to parse content_handlers in ' | 233 raise ShellConfigurationException('Failed to parse content_handlers in ' |
234 'the config file.') | 234 'the config file.') |
235 return shell_config | 235 return shell_config |
OLD | NEW |