xref: /aosp_15_r20/external/cronet/build/android/pylib/base/environment_factory.py (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1# Copyright 2014 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5
6from pylib import constants
7from pylib.local.device import local_device_environment
8from pylib.local.machine import local_machine_environment
9
10try:
11  # local_emulator_environment depends on //tools.
12  # If a client pulls in the //build subtree but not the //tools
13  # one, fail at emulator environment creation time.
14  from pylib.local.emulator import local_emulator_environment
15except ImportError:
16  local_emulator_environment = None
17
18
19def CreateEnvironment(args, output_manager, error_func):
20
21  if args.environment == 'local':
22    if args.command not in constants.LOCAL_MACHINE_TESTS:
23      if args.avd_config:
24        if not local_emulator_environment:
25          error_func('emulator environment requested but not available.')
26          raise RuntimeError('error_func must call exit inside.')
27        return local_emulator_environment.LocalEmulatorEnvironment(
28            args, output_manager, error_func)
29      return local_device_environment.LocalDeviceEnvironment(
30          args, output_manager, error_func)
31    return local_machine_environment.LocalMachineEnvironment(
32        args, output_manager, error_func)
33
34  error_func('Unable to create %s environment.' % args.environment)
35  raise RuntimeError('error_func must call exit inside.')
36