Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: mojo/devtools/common/devtoolslib/shell_config.py

Issue 1259793008: Support dev servers defined in a mojoconfig file. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Address Ben's comments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
13
12 from devtoolslib import paths 14 from devtoolslib import paths
13 15
14 16
17 class ShellConfigurationException(Exception):
18 """Represents an error preventing creating a functional shell abstraction."""
19 pass
20
21
15 class ShellConfig(object): 22 class ShellConfig(object):
16 """Configuration for the shell abstraction.""" 23 """Configuration for the shell abstraction."""
17 24
18 def __init__(self): 25 def __init__(self):
19 self.android = None 26 self.android = None
20 self.shell_path = None 27 self.shell_path = None
21 self.origin = None 28 self.origin = None
22 self.map_url_list = None 29 self.map_url_list = []
23 self.map_origin_list = None 30 self.map_origin_list = []
31 self.dev_servers = []
24 self.sky = None 32 self.sky = None
25 self.verbose = None 33 self.verbose = None
26 34
27 # Android-only. 35 # Android-only.
28 self.adb_path = None 36 self.adb_path = None
29 self.target_device = None 37 self.target_device = None
30 self.logcat_tags = None 38 self.logcat_tags = None
31 39
32 # Desktop-only. 40 # Desktop-only.
33 self.use_osmesa = None 41 self.use_osmesa = None
34 42
35 43
44 class DevServerConfig(object):
45 """Configuration for a development server running on a host and available to
46 the shell.
47 """
48 def __init__(self):
49 self.host = None
50 self.mappings = None
51
52
36 def add_shell_arguments(parser): 53 def add_shell_arguments(parser):
37 """Adds argparse arguments allowing to configure shell abstraction using 54 """Adds argparse arguments allowing to configure shell abstraction using
38 configure_shell() below. 55 configure_shell() below.
39 """ 56 """
40 # Arguments configuring the shell run. 57 # Arguments configuring the shell run.
41 parser.add_argument('--android', help='Run on Android', 58 parser.add_argument('--android', help='Run on Android',
42 action='store_true') 59 action='store_true')
43 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.')
44 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 '
45 'web url or a local directory path.') 62 'web url or a local directory path.')
(...skipping 15 matching lines...) Expand all
61 android_group.add_argument('--target-device', help='Device to run on.') 78 android_group.add_argument('--target-device', help='Device to run on.')
62 android_group.add_argument('--logcat-tags', help='Comma-separated list of ' 79 android_group.add_argument('--logcat-tags', help='Comma-separated list of '
63 'additional logcat tags to display.') 80 'additional logcat tags to display.')
64 81
65 desktop_group = parser.add_argument_group('Desktop-only', 82 desktop_group = parser.add_argument_group('Desktop-only',
66 'These arguments apply only when running on desktop.') 83 'These arguments apply only when running on desktop.')
67 desktop_group.add_argument('--use-osmesa', action='store_true', 84 desktop_group.add_argument('--use-osmesa', action='store_true',
68 help='Configure the native viewport service ' 85 help='Configure the native viewport service '
69 'for off-screen rendering.') 86 'for off-screen rendering.')
70 87
71 # Arguments allowing to indicate the configuration we are targeting when 88 config_file_group = parser.add_argument_group('Configuration file',
72 # running within a Chromium-like checkout. These will go away once we have 89 'These arguments allow to modify the behavior regarding the mojoconfig '
73 # devtools config files, see https://github.com/domokit/devtools/issues/28. 90 'file.')
74 chromium_config_group = parser.add_argument_group('Chromium configuration', 91 config_file_group.add_argument('--config-file', type=file,
92 help='Path of the configuration file to use.')
93
94 # 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
96 # away once we have devtools config files, see
97 # https://github.com/domokit/devtools/issues/28.
98 chromium_checkout_group = parser.add_argument_group(
99 'Chromium-like checkout configuration',
75 'These arguments allow to infer paths to tools and build results ' 100 'These arguments allow to infer paths to tools and build results '
76 'when running withing a Chromium-like checkout') 101 'when running within a Chromium-like checkout')
77 debug_group = chromium_config_group.add_mutually_exclusive_group() 102 debug_group = chromium_checkout_group.add_mutually_exclusive_group()
78 debug_group.add_argument('--debug', help='Debug build (default)', 103 debug_group.add_argument('--debug', help='Debug build (default)',
79 default=True, action='store_true') 104 default=True, action='store_true')
80 debug_group.add_argument('--release', help='Release build', default=False, 105 debug_group.add_argument('--release', help='Release build', default=False,
81 dest='debug', action='store_false') 106 dest='debug', action='store_false')
82 chromium_config_group.add_argument('--target-cpu', 107 chromium_checkout_group.add_argument('--target-cpu',
83 help='CPU architecture to run for.', 108 help='CPU architecture to run for.',
84 choices=['x64', 'x86', 'arm']) 109 choices=['x64', 'x86', 'arm'])
85 110
86 111
112 def _read_config_file(config_file, aliases):
113 spec = config_file.read()
114 for alias_pattern, alias_value in aliases:
115 spec = spec.replace(alias_pattern, alias_value)
116 return ast.literal_eval(spec)
117
118
87 def get_shell_config(script_args): 119 def get_shell_config(script_args):
88 """Processes command-line options defined in add_shell_arguments(), applying 120 """Processes command-line options defined in add_shell_arguments(), applying
89 any inferred default paths and produces an instance of ShellConfig. 121 any inferred default paths and produces an instance of ShellConfig.
90 122
91 Returns: 123 Returns:
92 An instance of ShellConfig. 124 An instance of ShellConfig.
93 """ 125 """
94 # Infer paths based on the Chromium configuration options 126 # Infer paths based on the Chromium configuration options
95 # (--debug/--release, etc.), if running within a Chromium-like checkout. 127 # (--debug/--release, etc.), if running within a Chromium-like checkout.
96 inferred_paths = paths.infer_paths(script_args.android, script_args.debug, 128 inferred_paths = paths.infer_paths(script_args.android, script_args.debug,
97 script_args.target_cpu) 129 script_args.target_cpu)
98
99 shell_config = ShellConfig() 130 shell_config = ShellConfig()
100 131
101 shell_config.android = script_args.android 132 shell_config.android = script_args.android
102 shell_config.shell_path = (script_args.shell_path or 133 shell_config.shell_path = (script_args.shell_path or
103 inferred_paths['shell_path']) 134 inferred_paths['shell_path'])
104 shell_config.origin = script_args.origin 135 shell_config.origin = script_args.origin
105 shell_config.map_url_list = script_args.map_url 136 shell_config.map_url_list = script_args.map_url
106 shell_config.map_origin_list = script_args.map_origin 137 shell_config.map_origin_list = script_args.map_origin
107 shell_config.sky = script_args.sky 138 shell_config.sky = script_args.sky
108 shell_config.verbose = script_args.verbose 139 shell_config.verbose = script_args.verbose
109 140
110 # Android-only. 141 # Android-only.
111 shell_config.adb_path = (script_args.adb_path or inferred_paths['adb_path']) 142 shell_config.adb_path = (script_args.adb_path or inferred_paths['adb_path'])
112 shell_config.target_device = script_args.target_device 143 shell_config.target_device = script_args.target_device
113 shell_config.logcat_tags = script_args.logcat_tags 144 shell_config.logcat_tags = script_args.logcat_tags
114 145
115 # Desktop-only. 146 # Desktop-only.
116 shell_config.use_osmesa = script_args.use_osmesa 147 shell_config.use_osmesa = script_args.use_osmesa
117 148
118 if (shell_config.android and not shell_config.origin and 149 if (shell_config.android and not shell_config.origin and
119 inferred_paths['build_dir_path']): 150 inferred_paths['build_dir_path']):
120 shell_config.origin = inferred_paths['build_dir_path'] 151 shell_config.origin = inferred_paths['build_dir_path']
152
153 # Read the mojoconfig file.
154 mojoconfig = None
qsr 2015/08/05 08:11:13 You can probably move the definition of this varia
ppi 2015/08/05 10:54:01 Done.
155 if script_args.config_file:
156 config_file_aliases = []
157 if inferred_paths['build_dir_path']:
158 config_file_aliases.append(('@{BUILD_DIR}',
159 inferred_paths['build_dir_path']))
160
161 try:
162 mojoconfig = _read_config_file(script_args.config_file,
163 config_file_aliases)
164 except SyntaxError:
165 raise ShellConfigurationException('Failed to parse the mojoconfig file.')
166
167 if 'dev_servers' in mojoconfig:
168 try:
169 for dev_server_spec in mojoconfig['dev_servers']:
170 dev_server_config = DevServerConfig()
171 dev_server_config.host = dev_server_spec['host']
172 dev_server_config.mappings = []
173 for prefix, path in dev_server_spec['mappings']:
174 dev_server_config.mappings.append((prefix, path))
175 shell_config.dev_servers.append(dev_server_config)
176 except (ValueError, KeyError):
177 raise ShellConfigurationException('Failed to parse dev_servers in '
178 'the mojoconfig file.')
121 return shell_config 179 return shell_config
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698