Chromium Code Reviews| Index: build/android/devil/devil_env.py |
| diff --git a/build/android/devil/devil_env.py b/build/android/devil/devil_env.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4f9186ca8cd350f1111217bd0dbc6cd2267c9e96 |
| --- /dev/null |
| +++ b/build/android/devil/devil_env.py |
| @@ -0,0 +1,115 @@ |
| +# Copyright 2015 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +import logging |
| +import os |
| +import sys |
| +import threading |
| + |
| +# TODO(jbudorick): Update this once dependency_manager moves to catapult. |
| +_TELEMETRY_PATH = os.path.abspath(os.path.join( |
| + os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, |
| + 'tools', 'telemetry')) |
| +sys.path.append(_TELEMETRY_PATH) |
| +from catapult_base import dependency_manager # pylint: disable=import-error |
| + |
| + |
| +instance = None |
| + |
| + |
| +class _Environment(object): |
| + |
| + def __init__(self, config_files): |
|
perezju
2015/09/14 09:13:58
Suggestion, make it something like:
class _Enviro
jbudorick
2015/09/14 13:12:39
Hm, this is an interesting idea. I'll try it & get
|
| + dm = dependency_manager.DependencyManager( |
| + [dependency_manager.BaseConfig(c) for c in config_files]) |
| + platform = 'linux_android' |
| + |
| + self._android_sdk_path = dm.FetchPath('android_sdk', platform) |
| + self._adb_path = ( |
| + dm.FetchPath('adb_path', platform) |
| + or os.path.join(self._android_sdk_path, 'platform-tools', 'adb')) |
| + |
| + build_tools_contents = os.listdir( |
| + os.path.join(self._android_sdk_path, 'build-tools')) |
| + if not build_tools_contents: |
| + self._android_sdk_build_tools_path = None |
| + else: |
| + if len(build_tools_contents) > 1: |
| + build_tools_contents.sort() |
|
perezju
2015/09/14 09:13:58
if there are multiple build_tools, how do they typ
jbudorick
2015/09/14 13:12:39
I've never seen multiple, but they're typically na
|
| + logging.warning( |
| + 'More than one set of build-tools provided by the Android SDK: %s', |
| + ','.join(build_tools_contents)) |
| + logging.warning('Defaulting to %s', build_tools_contents[-1]) |
| + self._android_sdk_build_tools_path = os.path.join( |
| + self._android_sdk_path, 'build-tools', build_tools_contents[-1]) |
| + |
| + self._forwarder_host_path = dm.FetchPath('forwarder_host', platform) |
| + self._forwarder_device_path = dm.FetchPath('forwarder_device', platform) |
| + |
| + self._md5sum_host_path = dm.FetchPath('md5sum_host', platform) |
| + self._md5sum_device_path = dm.FetchPath('md5sum_device', platform) |
| + |
| + self._pymock_path = dm.FetchPath('pymock', platform) |
| + |
| + @property |
| + def adb_path(self): |
| + return self._adb_path |
| + |
| + @property |
| + def android_sdk_path(self): |
| + return self._android_sdk_path |
| + |
| + @property |
| + def android_sdk_build_tools_path(self): |
| + return self._android_sdk_build_tools_path |
| + |
| + @property |
| + def forwarder_host_path(self): |
| + return self._forwarder_host_path |
| + |
| + @property |
| + def forwarder_device_path(self): |
| + return self._forwarder_device_path |
| + |
| + @property |
| + def md5sum_host_path(self): |
| + return self._md5sum_host_path |
| + |
| + @property |
| + def md5sum_device_path(self): |
| + return self._md5sum_device_path |
| + |
| + @property |
| + def pymock_path(self): |
| + return self._pymock_path |
| + |
| + |
| +_env_init_lock = threading.Lock() |
| + |
| +def Initialize(config_files): |
| + with _env_init_lock: |
| + global instance # pylint: disable=global-statement |
| + if not instance: |
| + instance = _Environment(config_files) |
| + |
| +def InitializeForTests(): |
| + test_configs = [ |
| + os.path.abspath(os.path.join( |
| + os.path.dirname(__file__), os.pardir, 'devil_config.json')) |
| + ] |
| + Initialize(test_configs) |
| + |
| +def GenerateDynamicConfig(deps): |
| + return { |
| + 'config_type': 'BaseConfig', |
| + 'dependencies': { |
| + k: { |
| + 'file_info': { |
| + 'linux_android': { |
| + 'local_paths': v |
| + } |
| + } |
| + } for k, v in deps.iteritems() |
| + } |
| + } |