blob: e320ea6bba0452c159646536addf39c034bd6611 [file] [log] [blame]
Keun Soo Yimb293fdb2016-09-21 16:03:44 -07001#!/usr/bin/env python
2#
3# Copyright 2016 - The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
Sam Chiu42ac7c52018-10-22 12:27:34 +080016r"""
17Welcome to
18 ___ _______ ____ __ _____
19 / _ |/ ___/ / / __ \/ / / / _ \
20 / __ / /__/ /__/ /_/ / /_/ / // /
21/_/ |_\___/____/\____/\____/____/
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070022
Sam Chiu42ac7c52018-10-22 12:27:34 +080023
24This a tool to create Android Virtual Devices locally/remotely.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070025
26- Prerequisites:
Sam Chiu42ac7c52018-10-22 12:27:34 +080027 The manual will be available at
28 https://android.googlesource.com/platform/tools/acloud/+/master/README.md
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070029
Sam Chiu42ac7c52018-10-22 12:27:34 +080030- To get started:
31 - Create instances:
32 1) To create a remote cuttlefish instance with the local built image.
33 Example:
34 $ acloud create --local_image /tmp/image_dir
35 2) To create a local cuttlefish instance using the image which has been
36 built out in your workspace.
37 Example:
38 $ acloud create --local-instance --local-image
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070039
Sam Chiu42ac7c52018-10-22 12:27:34 +080040 - Delete instances:
41 $ acloud delete
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070042
Sam Chiu42ac7c52018-10-22 12:27:34 +080043Try $acloud [cmd] --help for further details.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070044
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070045"""
46import argparse
47import getpass
48import logging
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070049import sys
50
Kevin Chengf4137c62018-05-22 16:06:58 -070051# Needed to silence oauth2client.
Sam Chiu29d858f2018-08-14 20:06:25 +080052# This is a workaround to get rid of below warning message:
53# 'No handlers could be found for logger "oauth2client.contrib.multistore_file'
54# TODO(b/112803893): Remove this code once bug is fixed.
55OAUTH2_LOGGER = logging.getLogger('oauth2client.contrib.multistore_file')
56OAUTH2_LOGGER.setLevel(logging.CRITICAL)
57OAUTH2_LOGGER.addHandler(logging.FileHandler("/dev/null"))
Kevin Chengb5963882018-05-09 00:06:27 -070058
Kevin Chengf4137c62018-05-22 16:06:58 -070059# pylint: disable=wrong-import-position
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070060from acloud.internal import constants
61from acloud.public import acloud_common
62from acloud.public import config
63from acloud.public import device_driver
64from acloud.public import errors
Kevin Chengb5963882018-05-09 00:06:27 -070065from acloud.public.actions import create_cuttlefish_action
66from acloud.public.actions import create_goldfish_action
Kevin Cheng3087af52018-08-13 13:26:50 -070067from acloud.create import create
68from acloud.create import create_args
Kevin Chengeb85e862018-10-09 15:35:13 -070069from acloud.delete import delete
70from acloud.delete import delete_args
Kevin Chengee6030f2018-06-26 10:55:30 -070071from acloud.setup import setup
72from acloud.setup import setup_args
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070073
Sam Chiu445941f2018-10-04 11:54:40 +080074LOGGING_FMT = "%(asctime)s |%(levelname)s| %(module)s:%(lineno)s| %(message)s"
Sam Chiu29d858f2018-08-14 20:06:25 +080075ACLOUD_LOGGER = "acloud"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070076
77# Commands
Kevin Chengb5963882018-05-09 00:06:27 -070078CMD_CREATE_CUTTLEFISH = "create_cf"
79CMD_CREATE_GOLDFISH = "create_gf"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070080CMD_DELETE = "delete"
81CMD_CLEANUP = "cleanup"
Fang Deng69498c32017-03-02 14:29:30 -080082CMD_SSHKEY = "project_sshkey"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070083
84
Kevin Cheng3031f8a2018-05-16 13:21:51 -070085# pylint: disable=too-many-statements
Keun Soo Yimb293fdb2016-09-21 16:03:44 -070086def _ParseArgs(args):
87 """Parse args.
88
89 Args:
90 args: Argument list passed from main.
91
92 Returns:
93 Parsed args.
94 """
Kevin Cheng3031f8a2018-05-16 13:21:51 -070095 usage = ",".join([
Sam Chiue669ef72018-10-16 16:23:37 +080096 setup_args.CMD_SETUP,
97 create_args.CMD_CREATE,
Kevin Chengab0b36b2018-08-02 14:38:30 -070098 CMD_CREATE_CUTTLEFISH,
99 CMD_CREATE_GOLDFISH,
Kevin Chengeb85e862018-10-09 15:35:13 -0700100 delete_args.CMD_DELETE,
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700101 ])
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700102 parser = argparse.ArgumentParser(
103 description=__doc__,
104 formatter_class=argparse.RawDescriptionHelpFormatter,
Sam Chiu42ac7c52018-10-22 12:27:34 +0800105 usage="acloud {" + usage + "} ...")
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700106 subparsers = parser.add_subparsers()
107 subparser_list = []
108
Kevin Chengb5963882018-05-09 00:06:27 -0700109 # Command "create_cf", create cuttlefish instances
110 create_cf_parser = subparsers.add_parser(CMD_CREATE_CUTTLEFISH)
111 create_cf_parser.required = False
112 create_cf_parser.set_defaults(which=CMD_CREATE_CUTTLEFISH)
113 create_cf_parser.add_argument(
114 "--build_target",
115 type=str,
116 dest="build_target",
117 help="Android build target, should be a cuttlefish target name.")
118 create_cf_parser.add_argument(
119 "--branch",
120 type=str,
121 dest="branch",
122 help="Android branch, e.g. git_master")
123 create_cf_parser.add_argument(
124 "--build_id",
125 type=str,
126 dest="build_id",
127 help="Android build id, e.g. 2145099, P2804227")
128 create_cf_parser.add_argument(
129 "--kernel_build_id",
130 type=str,
131 dest="kernel_build_id",
132 required=False,
133 help="Android kernel build id, e.g. 4586590. This is to test a new"
134 " kernel build with a particular Android build (--build_id). If not"
135 " specified, the kernel that's bundled with the Android build would"
136 " be used.")
Kevin Chengb5963882018-05-09 00:06:27 -0700137
Kevin Cheng3087af52018-08-13 13:26:50 -0700138 create_args.AddCommonCreateArgs(create_cf_parser)
Kevin Chengb5963882018-05-09 00:06:27 -0700139 subparser_list.append(create_cf_parser)
140
141 # Command "create_gf", create goldfish instances
142 # In order to create a goldfish device we need the following parameters:
143 # 1. The emulator build we wish to use, this is the binary that emulates
144 # an android device. See go/emu-dev for more
145 # 2. A system-image. This is the android release we wish to run on the
146 # emulated hardware.
147 create_gf_parser = subparsers.add_parser(CMD_CREATE_GOLDFISH)
148 create_gf_parser.required = False
149 create_gf_parser.set_defaults(which=CMD_CREATE_GOLDFISH)
150 create_gf_parser.add_argument(
151 "--build_target",
152 type=str,
153 dest="build_target",
154 help="Android build target, should be a goldfish target name.")
155 create_gf_parser.add_argument(
156 "--branch",
157 type=str,
158 dest="branch",
159 help="Android branch, e.g. git_master")
160 create_gf_parser.add_argument(
161 "--build_id",
162 type=str,
163 dest="build_id",
164 help="Android build id, e.g. 4669424, P2804227")
165 create_gf_parser.add_argument(
166 "--emulator_build_id",
167 type=str,
168 dest="emulator_build_id",
169 required=False,
170 help="Emulator build used to run the images. e.g. 4669466.")
171 create_gf_parser.add_argument(
172 "--gpu",
173 type=str,
174 dest="gpu",
175 required=False,
176 default=None,
177 help="GPU accelerator to use if any."
178 " e.g. nvidia-tesla-k80, omit to use swiftshader")
179 create_gf_parser.add_argument(
Kevin Chengbced4af2018-06-26 10:35:01 -0700180 "--base_image",
181 type=str,
182 dest="base_image",
183 required=False,
184 help="Name of the goldfish base image to be used to create the instance. "
185 "This will override stable_goldfish_host_image_name from config. "
186 "e.g. emu-dev-cts-061118")
Kevin Chengb5963882018-05-09 00:06:27 -0700187
Kevin Cheng3087af52018-08-13 13:26:50 -0700188 create_args.AddCommonCreateArgs(create_gf_parser)
Kevin Chengb5963882018-05-09 00:06:27 -0700189 subparser_list.append(create_gf_parser)
190
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700191 # Command "cleanup"
192 cleanup_parser = subparsers.add_parser(CMD_CLEANUP)
193 cleanup_parser.required = False
194 cleanup_parser.set_defaults(which=CMD_CLEANUP)
195 cleanup_parser.add_argument(
196 "--expiration_mins",
197 type=int,
198 dest="expiration_mins",
199 required=True,
200 help="Garbage collect all gce instances, gce images, cached disk "
201 "images that are older than |expiration_mins|.")
202 subparser_list.append(cleanup_parser)
203
Fang Deng69498c32017-03-02 14:29:30 -0800204 # Command "project_sshkey"
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700205 sshkey_parser = subparsers.add_parser(CMD_SSHKEY)
206 sshkey_parser.required = False
207 sshkey_parser.set_defaults(which=CMD_SSHKEY)
208 sshkey_parser.add_argument(
209 "--user",
210 type=str,
211 dest="user",
212 default=getpass.getuser(),
213 help="The user name which the sshkey belongs to, default to: %s." %
214 getpass.getuser())
215 sshkey_parser.add_argument(
216 "--ssh_rsa_path",
217 type=str,
218 dest="ssh_rsa_path",
219 required=True,
Fang Deng69498c32017-03-02 14:29:30 -0800220 help="Absolute path to the file that contains the public rsa key "
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700221 "that will be added as project-wide ssh key.")
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700222 subparser_list.append(sshkey_parser)
223
Kevin Chengeb85e862018-10-09 15:35:13 -0700224 # Command "create"
225 subparser_list.append(create_args.GetCreateArgParser(subparsers))
226
Kevin Chengee6030f2018-06-26 10:55:30 -0700227 # Command "setup"
228 subparser_list.append(setup_args.GetSetupArgParser(subparsers))
229
Kevin Chengeb85e862018-10-09 15:35:13 -0700230 # Command "Delete"
231 subparser_list.append(delete_args.GetDeleteArgParser(subparsers))
232
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700233 # Add common arguments.
Kevin Chengb21d7712018-05-24 14:54:55 -0700234 for subparser in subparser_list:
235 acloud_common.AddCommonArguments(subparser)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700236
237 return parser.parse_args(args)
238
239
herbertxueb617e8a2018-08-22 10:02:19 +0800240# TODO(b/112803893): Delete this method once the new create method has been completed.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700241def _TranslateAlias(parsed_args):
242 """Translate alias to Launch Control compatible values.
243
244 This method translates alias to Launch Control compatible values.
245 - branch: "git_" prefix will be added if branch name doesn't have it.
246 - build_target: For example, "phone" will be translated to full target
247 name "git_x86_phone-userdebug",
248
249 Args:
250 parsed_args: Parsed args.
251
252 Returns:
253 Parsed args with its values being translated.
254 """
Kevin Cheng3087af52018-08-13 13:26:50 -0700255 if parsed_args.which == create_args.CMD_CREATE:
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700256 if (parsed_args.branch and
257 not parsed_args.branch.startswith(constants.BRANCH_PREFIX)):
258 parsed_args.branch = constants.BRANCH_PREFIX + parsed_args.branch
259 parsed_args.build_target = constants.BUILD_TARGET_MAPPING.get(
260 parsed_args.build_target, parsed_args.build_target)
261 return parsed_args
262
263
herbertxue2625b042018-08-16 23:28:20 +0800264# pylint: disable=too-many-branches
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700265def _VerifyArgs(parsed_args):
266 """Verify args.
267
268 Args:
269 parsed_args: Parsed args.
270
271 Raises:
272 errors.CommandArgError: If args are invalid.
273 """
herbertxue2625b042018-08-16 23:28:20 +0800274 if parsed_args.which == create_args.CMD_CREATE:
275 create_args.VerifyArgs(parsed_args)
276
Kevin Cheng3087af52018-08-13 13:26:50 -0700277 if (parsed_args.which == create_args.CMD_CREATE
278 and parsed_args.avd_type == constants.TYPE_GCE):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700279 if (parsed_args.spec and parsed_args.spec not in constants.SPEC_NAMES):
280 raise errors.CommandArgError(
281 "%s is not valid. Choose from: %s" %
282 (parsed_args.spec, ", ".join(constants.SPEC_NAMES)))
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700283 if not ((parsed_args.build_id and parsed_args.build_target)
284 or parsed_args.gce_image or parsed_args.local_disk_image):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700285 raise errors.CommandArgError(
286 "At least one of the following should be specified: "
287 "--build_id and --build_target, or --gce_image, or "
288 "--local_disk_image.")
289 if bool(parsed_args.build_id) != bool(parsed_args.build_target):
290 raise errors.CommandArgError(
291 "Must specify --build_id and --build_target at the same time.")
Kevin Chengb5963882018-05-09 00:06:27 -0700292
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700293 if parsed_args.which == CMD_CREATE_CUTTLEFISH:
Kevin Chengb5963882018-05-09 00:06:27 -0700294 if not parsed_args.build_id or not parsed_args.build_target:
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700295 raise errors.CommandArgError(
296 "Must specify --build_id and --build_target")
Kevin Chengb5963882018-05-09 00:06:27 -0700297
298 if parsed_args.which == CMD_CREATE_GOLDFISH:
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700299 if not parsed_args.emulator_build_id and not parsed_args.build_id:
300 raise errors.CommandArgError("Must specify either "
301 "--emulator_build_id or --build_id")
302 if not parsed_args.build_target:
303 raise errors.CommandArgError("Must specify --build_target")
Kevin Chengb5963882018-05-09 00:06:27 -0700304
305 if parsed_args.which in [
Kevin Cheng3087af52018-08-13 13:26:50 -0700306 create_args.CMD_CREATE, CMD_CREATE_CUTTLEFISH, CMD_CREATE_GOLDFISH
Kevin Chengb5963882018-05-09 00:06:27 -0700307 ]:
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700308 if (parsed_args.serial_log_file
309 and not parsed_args.serial_log_file.endswith(".tar.gz")):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700310 raise errors.CommandArgError(
311 "--serial_log_file must ends with .tar.gz")
Kevin Cheng3031f8a2018-05-16 13:21:51 -0700312 if (parsed_args.logcat_file
313 and not parsed_args.logcat_file.endswith(".tar.gz")):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700314 raise errors.CommandArgError(
315 "--logcat_file must ends with .tar.gz")
316
317
Sam Chiu29d858f2018-08-14 20:06:25 +0800318def _SetupLogging(log_file, verbose):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700319 """Setup logging.
320
Sam Chiu29d858f2018-08-14 20:06:25 +0800321 This function define the logging policy in below manners.
322 - without -v , -vv ,--log_file:
323 Only display critical log and print() message on screen.
324
325 - with -v:
326 Display INFO log and set StreamHandler to acloud parent logger to turn on
327 ONLY acloud modules logging.(silence all 3p libraries)
328
329 - with -vv:
330 Display INFO/DEBUG log and set StreamHandler to root logger to turn on all
331 acloud modules and 3p libraries logging.
332
333 - with --log_file.
334 Dump logs to FileHandler with DEBUG level.
335
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700336 Args:
Sam Chiu29d858f2018-08-14 20:06:25 +0800337 log_file: String, if not None, dump the log to log file.
338 verbose: Int, if verbose = 1(-v), log at INFO level and turn on
339 logging on libraries to a StreamHandler.
340 If verbose = 2(-vv), log at DEBUG level and turn on logging on
341 all libraries and 3rd party libraries to a StreamHandler.
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700342 """
Sam Chiu29d858f2018-08-14 20:06:25 +0800343 # Define logging level and hierarchy by verbosity.
344 shandler_level = None
345 logger = None
346 if verbose == 0:
347 shandler_level = logging.CRITICAL
348 logger = logging.getLogger(ACLOUD_LOGGER)
349 elif verbose == 1:
350 shandler_level = logging.INFO
351 logger = logging.getLogger(ACLOUD_LOGGER)
352 elif verbose > 1:
353 shandler_level = logging.DEBUG
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700354 logger = logging.getLogger()
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700355
Sam Chiu29d858f2018-08-14 20:06:25 +0800356 # Add StreamHandler by default.
357 shandler = logging.StreamHandler()
358 shandler.setFormatter(logging.Formatter(LOGGING_FMT))
359 shandler.setLevel(shandler_level)
360 logger.addHandler(shandler)
361 # Set the default level to DEBUG, the other handlers will handle
362 # their own levels via the args supplied (-v and --log_file).
363 logger.setLevel(logging.DEBUG)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700364
Sam Chiu29d858f2018-08-14 20:06:25 +0800365 # Add FileHandler if log_file is provided.
Sam Chiufde41e92018-08-07 18:37:02 +0800366 if log_file:
Sam Chiu29d858f2018-08-14 20:06:25 +0800367 fhandler = logging.FileHandler(filename=log_file)
368 fhandler.setFormatter(logging.Formatter(LOGGING_FMT))
369 fhandler.setLevel(logging.DEBUG)
370 logger.addHandler(fhandler)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700371
372
373def main(argv):
374 """Main entry.
375
376 Args:
377 argv: A list of system arguments.
378
379 Returns:
380 0 if success. None-zero if fails.
381 """
382 args = _ParseArgs(argv)
Sam Chiu29d858f2018-08-14 20:06:25 +0800383 _SetupLogging(args.log_file, args.verbose)
herbertxueb617e8a2018-08-22 10:02:19 +0800384 # Translation of the branch will happen in AvdSpec(), skip it for now.
385 #args = _TranslateAlias(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700386 _VerifyArgs(args)
387
Sam Chiuc64f3432018-08-17 11:19:06 +0800388 cfg = config.GetAcloudConfig(args)
Kevin Cheng3087af52018-08-13 13:26:50 -0700389 # TODO: Move this check into the functions it is actually needed.
Fang Dengcef4b112017-03-02 11:20:17 -0800390 # Check access.
Kevin Cheng3087af52018-08-13 13:26:50 -0700391 # device_driver.CheckAccess(cfg)
Fang Dengcef4b112017-03-02 11:20:17 -0800392
Kevin Chengee6030f2018-06-26 10:55:30 -0700393 report = None
Kevin Cheng3087af52018-08-13 13:26:50 -0700394 if (args.which == create_args.CMD_CREATE
395 and args.avd_type == constants.TYPE_GCE):
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700396 report = device_driver.CreateAndroidVirtualDevices(
397 cfg,
398 args.build_target,
399 args.build_id,
400 args.num,
401 args.gce_image,
402 args.local_disk_image,
403 cleanup=not args.no_cleanup,
404 serial_log_file=args.serial_log_file,
Kevin Chengb5963882018-05-09 00:06:27 -0700405 logcat_file=args.logcat_file,
Kevin Cheng86d43c72018-08-30 10:59:14 -0700406 autoconnect=args.autoconnect,
407 report_internal_ip=args.report_internal_ip)
Kevin Cheng3087af52018-08-13 13:26:50 -0700408 elif args.which == create_args.CMD_CREATE:
Kevin Chengc3d0d5e2018-08-14 14:22:44 -0700409 create.Run(args)
Kevin Chengb5963882018-05-09 00:06:27 -0700410 elif args.which == CMD_CREATE_CUTTLEFISH:
411 report = create_cuttlefish_action.CreateDevices(
412 cfg=cfg,
413 build_target=args.build_target,
414 build_id=args.build_id,
415 kernel_build_id=args.kernel_build_id,
416 num=args.num,
417 serial_log_file=args.serial_log_file,
418 logcat_file=args.logcat_file,
Kevin Cheng86d43c72018-08-30 10:59:14 -0700419 autoconnect=args.autoconnect,
420 report_internal_ip=args.report_internal_ip)
Kevin Chengb5963882018-05-09 00:06:27 -0700421 elif args.which == CMD_CREATE_GOLDFISH:
422 report = create_goldfish_action.CreateDevices(
423 cfg=cfg,
424 build_target=args.build_target,
425 build_id=args.build_id,
426 emulator_build_id=args.emulator_build_id,
427 gpu=args.gpu,
428 num=args.num,
429 serial_log_file=args.serial_log_file,
430 logcat_file=args.logcat_file,
Kevin Cheng84d3eed2018-08-16 15:16:00 -0700431 autoconnect=args.autoconnect,
Kevin Cheng86d43c72018-08-30 10:59:14 -0700432 branch=args.branch,
433 report_internal_ip=args.report_internal_ip)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700434 elif args.which == CMD_DELETE:
Kevin Chengeb85e862018-10-09 15:35:13 -0700435 report = delete.Run(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700436 elif args.which == CMD_CLEANUP:
437 report = device_driver.Cleanup(cfg, args.expiration_mins)
438 elif args.which == CMD_SSHKEY:
439 report = device_driver.AddSshRsa(cfg, args.user, args.ssh_rsa_path)
Kevin Chengee6030f2018-06-26 10:55:30 -0700440 elif args.which == setup_args.CMD_SETUP:
herbertxue34776bb2018-07-03 21:57:48 +0800441 setup.Run(args)
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700442 else:
443 sys.stderr.write("Invalid command %s" % args.which)
444 return 2
445
Kevin Chengee6030f2018-06-26 10:55:30 -0700446 if report:
447 report.Dump(args.report_file)
448 if report.errors:
449 msg = "\n".join(report.errors)
450 sys.stderr.write("Encountered the following errors:\n%s\n" % msg)
451 return 1
Keun Soo Yimb293fdb2016-09-21 16:03:44 -0700452 return 0
Tri Vo8e292532016-10-01 16:55:51 -0700453
454
455if __name__ == "__main__":
456 main(sys.argv[1:])