| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 def add_shell_arguments(parser): | 55 def add_shell_arguments(parser): |
| 56 """Adds argparse arguments allowing to configure shell abstraction using | 56 """Adds argparse arguments allowing to configure shell abstraction using |
| 57 configure_shell() below. | 57 configure_shell() below. |
| 58 """ | 58 """ |
| 59 # Arguments configuring the shell run. | 59 # Arguments configuring the shell run. |
| 60 parser.add_argument('--android', help='Run on Android', | 60 parser.add_argument('--android', help='Run on Android', |
| 61 action='store_true') | 61 action='store_true') |
| 62 parser.add_argument('--shell-path', help='Path of the Mojo shell binary.') | 62 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 ' | 63 parser.add_argument('--origin', help='Origin for mojo: URLs. This can be a ' |
| 64 'web url or a local directory path.') | 64 'web url or a local directory path. If MOJO_VERSION file ' |
| 65 'is among ancestors of this file, by default the origin ' |
| 66 'will point to mojo services prebuilt at the ' |
| 67 'specified version in Google Storage') |
| 65 parser.add_argument('--map-url', action='append', | 68 parser.add_argument('--map-url', action='append', |
| 66 help='Define a mapping for a url in the format ' | 69 help='Define a mapping for a url in the format ' |
| 67 '<url>=<url-or-local-file-path>') | 70 '<url>=<url-or-local-file-path>') |
| 68 parser.add_argument('--map-origin', action='append', | 71 parser.add_argument('--map-origin', action='append', |
| 69 help='Define a mapping for a url origin in the format ' | 72 help='Define a mapping for a url origin in the format ' |
| 70 '<origin>=<url-or-local-file-path>') | 73 '<origin>=<url-or-local-file-path>') |
| 71 parser.add_argument('--reuse-servers', action='store_true', | 74 parser.add_argument('--reuse-servers', action='store_true', |
| 72 help='Do not spawn any development servers. Assume that ' | 75 help='Do not spawn any development servers. Assume that ' |
| 73 'dev servers are already running and only forward them ' | 76 'dev servers are already running and only forward them ' |
| 74 'to a device if needed.') | 77 'to a device if needed.') |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 | 139 |
| 137 def get_shell_config(script_args): | 140 def get_shell_config(script_args): |
| 138 """Processes command-line options defined in add_shell_arguments(), applying | 141 """Processes command-line options defined in add_shell_arguments(), applying |
| 139 any inferred default paths and produces an instance of ShellConfig. | 142 any inferred default paths and produces an instance of ShellConfig. |
| 140 | 143 |
| 141 Returns: | 144 Returns: |
| 142 An instance of ShellConfig. | 145 An instance of ShellConfig. |
| 143 """ | 146 """ |
| 144 # Infer paths based on the Chromium configuration options | 147 # Infer paths based on the Chromium configuration options |
| 145 # (--debug/--release, etc.), if running within a Chromium-like checkout. | 148 # (--debug/--release, etc.), if running within a Chromium-like checkout. |
| 146 inferred_paths = paths.infer_paths(script_args.android, script_args.debug, | 149 inferred_params = paths.infer_params(script_args.android, script_args.debug, |
| 147 script_args.target_cpu) | 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 |
| 148 shell_config = ShellConfig() | 164 shell_config = ShellConfig() |
| 149 | |
| 150 shell_config.android = script_args.android | 165 shell_config.android = script_args.android |
| 151 shell_config.shell_path = (script_args.shell_path or | 166 shell_config.shell_path = (script_args.shell_path or |
| 152 inferred_paths['shell_path']) | 167 inferred_params['shell_path']) |
| 153 shell_config.origin = script_args.origin | 168 shell_config.origin = script_args.origin or inferred_origin |
| 154 shell_config.map_url_list = script_args.map_url | 169 shell_config.map_url_list = script_args.map_url |
| 155 shell_config.map_origin_list = script_args.map_origin | 170 shell_config.map_origin_list = script_args.map_origin |
| 156 shell_config.reuse_servers = script_args.reuse_servers | 171 shell_config.reuse_servers = script_args.reuse_servers |
| 157 shell_config.verbose = script_args.verbose | 172 shell_config.verbose = script_args.verbose |
| 158 | 173 |
| 159 # Android-only. | 174 # Android-only. |
| 160 shell_config.adb_path = (script_args.adb_path or inferred_paths['adb_path'] or | 175 shell_config.adb_path = (script_args.adb_path or inferred_params['adb_path'] |
| 161 'adb') | 176 or 'adb') |
| 162 shell_config.target_device = script_args.target_device | 177 shell_config.target_device = script_args.target_device |
| 163 shell_config.logcat_tags = script_args.logcat_tags | 178 shell_config.logcat_tags = script_args.logcat_tags |
| 164 | 179 |
| 165 # Desktop-only. | 180 # Desktop-only. |
| 166 shell_config.use_osmesa = script_args.use_osmesa | 181 shell_config.use_osmesa = script_args.use_osmesa |
| 167 | 182 |
| 168 if (shell_config.android and not shell_config.origin and | 183 if (shell_config.android and not shell_config.origin and |
| 169 inferred_paths['build_dir_path']): | 184 inferred_params['build_dir_path']): |
| 170 shell_config.origin = inferred_paths['build_dir_path'] | 185 shell_config.origin = inferred_params['build_dir_path'] |
| 171 | 186 |
| 172 # Read the mojoconfig file. | 187 # Read the mojoconfig file. |
| 173 config_file = script_args.config_file | 188 config_file = script_args.config_file |
| 174 if not script_args.no_config_file: | 189 if not script_args.no_config_file: |
| 175 config_file = config_file or _discover_config_file() | 190 config_file = config_file or _discover_config_file() |
| 176 | 191 |
| 177 if config_file: | 192 if config_file: |
| 178 with config_file: | 193 with config_file: |
| 179 config_file_aliases = [] | 194 config_file_aliases = [] |
| 180 if script_args.config_aliases: | 195 if script_args.config_aliases: |
| 181 for alias_spec in script_args.config_aliases: | 196 for alias_spec in script_args.config_aliases: |
| 182 alias_from, alias_to = alias_spec.split('=') | 197 alias_from, alias_to = alias_spec.split('=') |
| 183 config_file_aliases.append(('@{%s}' % alias_from, alias_to)) | 198 config_file_aliases.append(('@{%s}' % alias_from, alias_to)) |
| 184 | 199 |
| 185 if inferred_paths['build_dir_path']: | 200 if inferred_params['build_dir_path']: |
| 186 config_file_aliases.append(('@{BUILD_DIR}', | 201 config_file_aliases.append(('@{BUILD_DIR}', |
| 187 inferred_paths['build_dir_path'])) | 202 inferred_params['build_dir_path'])) |
| 188 | 203 |
| 189 config = None | 204 config = None |
| 190 try: | 205 try: |
| 191 if script_args.verbose: | 206 if script_args.verbose: |
| 192 print 'Reading config file from: ' + config_file.name | 207 print 'Reading config file from: ' + config_file.name |
| 193 config = _read_config_file(config_file, config_file_aliases) | 208 config = _read_config_file(config_file, config_file_aliases) |
| 194 except SyntaxError: | 209 except SyntaxError: |
| 195 raise ShellConfigurationException('Failed to parse the mojoconfig ' | 210 raise ShellConfigurationException('Failed to parse the mojoconfig ' |
| 196 'file.') | 211 'file.') |
| 197 | 212 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 211 | 226 |
| 212 if 'content_handlers' in config: | 227 if 'content_handlers' in config: |
| 213 try: | 228 try: |
| 214 for (mime_type, | 229 for (mime_type, |
| 215 content_handler_url) in config['content_handlers'].iteritems(): | 230 content_handler_url) in config['content_handlers'].iteritems(): |
| 216 shell_config.content_handlers[mime_type] = content_handler_url | 231 shell_config.content_handlers[mime_type] = content_handler_url |
| 217 except (ValueError, KeyError): | 232 except (ValueError, KeyError): |
| 218 raise ShellConfigurationException('Failed to parse content_handlers in ' | 233 raise ShellConfigurationException('Failed to parse content_handlers in ' |
| 219 'the config file.') | 234 'the config file.') |
| 220 return shell_config | 235 return shell_config |
| OLD | NEW |