1 # Copyright 2014 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.
8 from catapult_base
import cloud_storage
9 from telemetry
import decorators
10 from telemetry
.internal
.util
import path
13 def _GetBinPath(binary_name
, arch_name
, platform_name
):
15 path
.GetTelemetryDir(), 'bin', platform_name
, arch_name
, binary_name
)
18 def _IsInCloudStorage(binary_name
, arch_name
, platform_name
):
19 return os
.path
.exists(
20 _GetBinPath(binary_name
, arch_name
, platform_name
) + '.sha1')
24 def FindLocallyBuiltPath(binary_name
):
25 """Finds the most recently built |binary_name|."""
28 chrome_root
= path
.GetChromiumSrcDir()
29 required_mode
= os
.X_OK
30 if binary_name
.endswith('.apk'):
31 required_mode
= os
.R_OK
32 for build_dir
, build_type
in path
.GetBuildDirectories():
33 candidate
= os
.path
.join(chrome_root
, build_dir
, build_type
, binary_name
)
34 if os
.path
.isfile(candidate
) and os
.access(candidate
, required_mode
):
35 candidate_mtime
= os
.stat(candidate
).st_mtime
36 if candidate_mtime
> command_mtime
:
38 command_mtime
= candidate_mtime
43 def FindPath(binary_name
, arch_name
, platform_name
):
44 """Returns the path to the given binary name, pulling from the cloud if
46 if platform_name
== 'win':
48 command
= FindLocallyBuiltPath(binary_name
)
49 if not command
and _IsInCloudStorage(binary_name
, arch_name
, platform_name
):
50 cloud_storage
.GetIfChanged(
51 _GetBinPath(binary_name
, arch_name
, platform_name
),
52 cloud_storage
.PUBLIC_BUCKET
)
53 command
= _GetBinPath(binary_name
, arch_name
, platform_name
)
55 # Ensure the downloaded file is actually executable.
56 if command
and os
.path
.exists(command
):
58 stat
.S_IRUSR | stat
.S_IWUSR | stat
.S_IXUSR | stat
.S_IRGRP
)
59 if not command
and platform_name
== 'win' and arch_name
!= 'AMD64':
60 # This is an awful, awful hack to temporarily fix cloud_storage downloads
61 # on XP until the binary_manager is finished and migrated to.
62 # Please don't try this at home.
63 return FindPath(binary_name
, 'AMD64', platform_name
)
65 # Return an absolute path consistently.
67 command
= os
.path
.abspath(command
)