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 5import os 6 7from devil import devil_env 8from devil.utils import lazy 9 10with devil_env.SysPath(devil_env.DEPENDENCY_MANAGER_PATH): 11 import dependency_manager # pylint: disable=import-error 12 13 14def GetPath(build_tool): 15 try: 16 return devil_env.config.LocalPath(build_tool) 17 except dependency_manager.NoPathFoundError: 18 pass 19 20 try: 21 return _PathInLocalSdk(build_tool) 22 except dependency_manager.NoPathFoundError: 23 pass 24 25 return devil_env.config.FetchPath(build_tool) 26 27 28def _PathInLocalSdk(build_tool): 29 build_tools_path = _build_tools_path.read() 30 return (os.path.join(build_tools_path, build_tool) if build_tools_path 31 else None) 32 33 34def _FindBuildTools(): 35 android_sdk_path = devil_env.config.LocalPath('android_sdk') 36 if not android_sdk_path: 37 return None 38 39 build_tools_contents = os.listdir( 40 os.path.join(android_sdk_path, 'build-tools')) 41 42 if not build_tools_contents: 43 return None 44 else: 45 if len(build_tools_contents) > 1: 46 build_tools_contents.sort() 47 return os.path.join(android_sdk_path, 'build-tools', 48 build_tools_contents[-1]) 49 50 51_build_tools_path = lazy.WeakConstant(_FindBuildTools) 52