Chromium Code Reviews| Index: build/android/pylib/constants.py |
| diff --git a/build/android/pylib/constants.py b/build/android/pylib/constants.py |
| index 9ae9878ebd1a7edd8c72332a813d2f5c1a6d7d5f..13ad109a09fbc408c70d4b0ce3f0e1f9c29637bc 100644 |
| --- a/build/android/pylib/constants.py |
| +++ b/build/android/pylib/constants.py |
| @@ -5,11 +5,22 @@ |
| """Defines a set of constants shared by test runners and other scripts.""" |
| import collections |
| +import logging |
| import os |
| import subprocess |
| import sys |
| +def _Memoize(func): |
| + def Wrapper(): |
| + try: |
| + return func._result |
|
frankf
2013/12/18 18:30:27
just curious: why not use hasattr instead of try/e
|
| + except AttributeError: |
| + func._result = func() |
| + return func._result |
| + return Wrapper |
| + |
| + |
| DIR_SOURCE_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), |
| os.pardir, os.pardir, os.pardir)) |
| ISOLATE_DEPS_DIR = os.path.join(DIR_SOURCE_ROOT, 'isolate_deps_dir') |
| @@ -158,7 +169,8 @@ def GetOutDirectory(build_type=None): |
| GetBuildType() if build_type is None else build_type)) |
| -def _GetADBPath(): |
| +@_Memoize |
| +def GetAdbPath(): |
| if os.environ.get('ANDROID_SDK_ROOT'): |
| return 'adb' |
| # If envsetup.sh hasn't been sourced and there's no adb in the path, |
| @@ -168,12 +180,10 @@ def _GetADBPath(): |
| subprocess.call(['adb', 'version'], stdout=devnull, stderr=devnull) |
| return 'adb' |
| except OSError: |
| - print >> sys.stderr, 'No adb found in $PATH, fallback to checked in binary.' |
| + logging.debug('No adb found in $PATH, fallback to checked in binary.') |
| return os.path.join(ANDROID_SDK_ROOT, 'platform-tools', 'adb') |
| -ADB_PATH = _GetADBPath() |
| - |
| # Exit codes |
| ERROR_EXIT_CODE = 1 |
| WARNING_EXIT_CODE = 88 |