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