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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
83 'These arguments apply only when running on desktop.') | 83 'These arguments apply only when running on desktop.') |
84 desktop_group.add_argument('--use-osmesa', action='store_true', | 84 desktop_group.add_argument('--use-osmesa', action='store_true', |
85 help='Configure the native viewport service ' | 85 help='Configure the native viewport service ' |
86 'for off-screen rendering.') | 86 'for off-screen rendering.') |
87 | 87 |
88 config_file_group = parser.add_argument_group('Configuration file', | 88 config_file_group = parser.add_argument_group('Configuration file', |
89 'These arguments allow to modify the behavior regarding the mojoconfig ' | 89 'These arguments allow to modify the behavior regarding the mojoconfig ' |
90 'file.') | 90 'file.') |
91 config_file_group.add_argument('--config-file', type=file, | 91 config_file_group.add_argument('--config-file', type=file, |
92 help='Path of the configuration file to use.') | 92 help='Path of the configuration file to use.') |
93 config_file_group.add_argument('--no-config-file', action='store_true', | |
94 help='Pass to skip automatic discovery of the ' | |
95 'mojoconfig file.') | |
93 | 96 |
94 # Arguments allowing to indicate the build directory we are targeting when | 97 # Arguments allowing to indicate the build directory we are targeting when |
95 # running within a Chromium-like checkout (e.g. Mojo checkout). These will go | 98 # running within a Chromium-like checkout (e.g. Mojo checkout). These will go |
96 # away once we have devtools config files, see | 99 # away once we have devtools config files, see |
97 # https://github.com/domokit/devtools/issues/28. | 100 # https://github.com/domokit/devtools/issues/28. |
98 chromium_checkout_group = parser.add_argument_group( | 101 chromium_checkout_group = parser.add_argument_group( |
99 'Chromium-like checkout configuration', | 102 'Chromium-like checkout configuration', |
100 'These arguments allow to infer paths to tools and build results ' | 103 'These arguments allow to infer paths to tools and build results ' |
101 'when running within a Chromium-like checkout') | 104 'when running within a Chromium-like checkout') |
102 debug_group = chromium_checkout_group.add_mutually_exclusive_group() | 105 debug_group = chromium_checkout_group.add_mutually_exclusive_group() |
103 debug_group.add_argument('--debug', help='Debug build (default)', | 106 debug_group.add_argument('--debug', help='Debug build (default)', |
104 default=True, action='store_true') | 107 default=True, action='store_true') |
105 debug_group.add_argument('--release', help='Release build', default=False, | 108 debug_group.add_argument('--release', help='Release build', default=False, |
106 dest='debug', action='store_false') | 109 dest='debug', action='store_false') |
107 chromium_checkout_group.add_argument('--target-cpu', | 110 chromium_checkout_group.add_argument('--target-cpu', |
108 help='CPU architecture to run for.', | 111 help='CPU architecture to run for.', |
109 choices=['x64', 'x86', 'arm']) | 112 choices=['x64', 'x86', 'arm']) |
110 | 113 |
111 | 114 |
115 def _discover_config_file(): | |
116 config_file_path = paths.find_within_ancestors('mojoconfig') | |
117 if not config_file_path: | |
118 return None | |
119 return open(config_file_path) | |
120 | |
121 | |
112 def _read_config_file(config_file, aliases): | 122 def _read_config_file(config_file, aliases): |
113 spec = config_file.read() | 123 spec = config_file.read() |
114 for alias_pattern, alias_value in aliases: | 124 for alias_pattern, alias_value in aliases: |
115 spec = spec.replace(alias_pattern, alias_value) | 125 spec = spec.replace(alias_pattern, alias_value) |
116 return ast.literal_eval(spec) | 126 return ast.literal_eval(spec) |
117 | 127 |
118 | 128 |
119 def get_shell_config(script_args): | 129 def get_shell_config(script_args): |
120 """Processes command-line options defined in add_shell_arguments(), applying | 130 """Processes command-line options defined in add_shell_arguments(), applying |
121 any inferred default paths and produces an instance of ShellConfig. | 131 any inferred default paths and produces an instance of ShellConfig. |
(...skipping 22 matching lines...) Expand all Loading... | |
144 shell_config.logcat_tags = script_args.logcat_tags | 154 shell_config.logcat_tags = script_args.logcat_tags |
145 | 155 |
146 # Desktop-only. | 156 # Desktop-only. |
147 shell_config.use_osmesa = script_args.use_osmesa | 157 shell_config.use_osmesa = script_args.use_osmesa |
148 | 158 |
149 if (shell_config.android and not shell_config.origin and | 159 if (shell_config.android and not shell_config.origin and |
150 inferred_paths['build_dir_path']): | 160 inferred_paths['build_dir_path']): |
151 shell_config.origin = inferred_paths['build_dir_path'] | 161 shell_config.origin = inferred_paths['build_dir_path'] |
152 | 162 |
153 # Read the mojoconfig file. | 163 # Read the mojoconfig file. |
154 if script_args.config_file: | 164 config_file = script_args.config_file |
165 if not script_args.no_config_file: | |
166 config_file = config_file or _discover_config_file() | |
167 | |
168 if config_file: | |
qsr
2015/08/05 11:50:59
Can you use:
with config_file:
inside the if (to n
ppi
2015/08/05 11:55:44
Seems to be working fine, done.
| |
155 config_file_aliases = [] | 169 config_file_aliases = [] |
156 if inferred_paths['build_dir_path']: | 170 if inferred_paths['build_dir_path']: |
157 config_file_aliases.append(('@{BUILD_DIR}', | 171 config_file_aliases.append(('@{BUILD_DIR}', |
158 inferred_paths['build_dir_path'])) | 172 inferred_paths['build_dir_path'])) |
159 | 173 |
160 mojoconfig = None | 174 config = None |
161 try: | 175 try: |
162 mojoconfig = _read_config_file(script_args.config_file, | 176 if script_args.verbose: |
163 config_file_aliases) | 177 print 'Reading config file from: ' + config_file.name |
178 config = _read_config_file(config_file, config_file_aliases) | |
179 config_file.close() | |
164 except SyntaxError: | 180 except SyntaxError: |
165 raise ShellConfigurationException('Failed to parse the mojoconfig file.') | 181 raise ShellConfigurationException('Failed to parse the mojoconfig file.') |
166 | 182 |
167 if 'dev_servers' in mojoconfig: | 183 if 'dev_servers' in config: |
168 try: | 184 try: |
169 for dev_server_spec in mojoconfig['dev_servers']: | 185 for dev_server_spec in config['dev_servers']: |
170 dev_server_config = DevServerConfig() | 186 dev_server_config = DevServerConfig() |
171 dev_server_config.host = dev_server_spec['host'] | 187 dev_server_config.host = dev_server_spec['host'] |
172 dev_server_config.mappings = [] | 188 dev_server_config.mappings = [] |
173 for prefix, path in dev_server_spec['mappings']: | 189 for prefix, path in dev_server_spec['mappings']: |
174 dev_server_config.mappings.append((prefix, path)) | 190 dev_server_config.mappings.append((prefix, path)) |
175 shell_config.dev_servers.append(dev_server_config) | 191 shell_config.dev_servers.append(dev_server_config) |
176 except (ValueError, KeyError): | 192 except (ValueError, KeyError): |
177 raise ShellConfigurationException('Failed to parse dev_servers in ' | 193 raise ShellConfigurationException('Failed to parse dev_servers in ' |
178 'the mojoconfig file.') | 194 'the mojoconfig file.') |
179 return shell_config | 195 return shell_config |
OLD | NEW |