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

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

Issue 1256323011: Devtools: refactor shell configuration logic. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Fix a typo. 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
« no previous file with comments | « mojo/devtools/common/devtoolslib/shell_arguments.py ('k') | mojo/devtools/common/mojo_run » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 """Configuration for the shell abstraction.
6
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
9 file, etc.
10 """
11
12 from devtoolslib import paths
13
14
15 class ShellConfig(object):
16 """Configuration for the shell abstraction."""
17
18 def __init__(self):
19 self.android = None
20 self.shell_path = None
21 self.origin = None
22 self.map_url_list = None
23 self.map_origin_list = None
24 self.sky = None
25 self.verbose = None
26
27 # Android-only.
28 self.adb_path = None
29 self.target_device = None
30 self.logcat_tags = None
31
32 # Desktop-only.
33 self.use_osmesa = None
34
35
36 def add_shell_arguments(parser):
37 """Adds argparse arguments allowing to configure shell abstraction using
38 configure_shell() below.
39 """
40 # Arguments configuring the shell run.
41 parser.add_argument('--android', help='Run on Android',
42 action='store_true')
43 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 '
45 'web url or a local directory path.')
46 parser.add_argument('--map-url', action='append',
47 help='Define a mapping for a url in the format '
48 '<url>=<url-or-local-file-path>')
49 parser.add_argument('--map-origin', action='append',
50 help='Define a mapping for a url origin in the format '
51 '<origin>=<url-or-local-file-path>')
52 parser.add_argument('--sky', action='store_true',
53 help='Maps mojo:sky_viewer as the content handler for '
54 'dart apps.')
55 parser.add_argument('-v', '--verbose', action="store_true",
56 help="Increase output verbosity")
57
58 android_group = parser.add_argument_group('Android-only',
59 'These arguments apply only when --android is passed.')
60 android_group.add_argument('--adb-path', help='Path of the adb binary.')
61 android_group.add_argument('--target-device', help='Device to run on.')
62 android_group.add_argument('--logcat-tags', help='Comma-separated list of '
63 'additional logcat tags to display.')
64
65 desktop_group = parser.add_argument_group('Desktop-only',
66 'These arguments apply only when running on desktop.')
67 desktop_group.add_argument('--use-osmesa', action='store_true',
68 help='Configure the native viewport service '
69 'for off-screen rendering.')
70
71 # Arguments allowing to indicate the configuration we are targeting when
72 # running within a Chromium-like checkout. These will go away once we have
73 # devtools config files, see https://github.com/domokit/devtools/issues/28.
74 chromium_config_group = parser.add_argument_group('Chromium configuration',
75 'These arguments allow to infer paths to tools and build results '
76 'when running withing a Chromium-like checkout')
77 debug_group = chromium_config_group.add_mutually_exclusive_group()
78 debug_group.add_argument('--debug', help='Debug build (default)',
79 default=True, action='store_true')
80 debug_group.add_argument('--release', help='Release build', default=False,
81 dest='debug', action='store_false')
82 chromium_config_group.add_argument('--target-cpu',
83 help='CPU architecture to run for.',
84 choices=['x64', 'x86', 'arm'])
85
86
87 def get_shell_config(script_args):
88 """Processes command-line options defined in add_shell_arguments(), applying
89 any inferred default paths and produces an instance of ShellConfig.
90
91 Returns:
92 An instance of ShellConfig.
93 """
94 # Infer paths based on the Chromium configuration options
95 # (--debug/--release, etc.), if running within a Chromium-like checkout.
96 inferred_paths = paths.infer_paths(script_args.android, script_args.debug,
97 script_args.target_cpu)
98
99 shell_config = ShellConfig()
100
101 shell_config.android = script_args.android
102 shell_config.shell_path = (script_args.shell_path or
103 inferred_paths['shell_path'])
104 shell_config.origin = script_args.origin
105 shell_config.map_url_list = script_args.map_url
106 shell_config.map_origin_list = script_args.map_origin
107 shell_config.sky = script_args.sky
108 shell_config.verbose = script_args.verbose
109
110 # Android-only.
111 shell_config.adb_path = (script_args.adb_path or inferred_paths['adb_path'])
112 shell_config.target_device = script_args.target_device
113 shell_config.logcat_tags = script_args.logcat_tags
114
115 # Desktop-only.
116 shell_config.use_osmesa = script_args.use_osmesa
117
118 if (shell_config.android and not shell_config.origin and
119 inferred_paths['build_dir_path']):
120 shell_config.origin = inferred_paths['build_dir_path']
121 return shell_config
OLDNEW
« no previous file with comments | « mojo/devtools/common/devtoolslib/shell_arguments.py ('k') | mojo/devtools/common/mojo_run » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698