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.
7 from telemetry import decorators
8 from telemetry.core import util
9 from telemetry.page import cloud_storage
12 def _GetBinPath(binary_name, platform_name):
13 # TODO(tonyg): Add another nesting level for architecture_name.
14 return os.path.join(util.GetTelemetryDir(), 'bin', platform_name, binary_name)
17 def _IsInCloudStorage(binary_name, platform_name):
18 return os.path.exists(_GetBinPath(binary_name, platform_name) + '.sha1')
22 def FindLocallyBuiltPath(binary_name):
23 """Finds the most recently built |binary_name|."""
26 chrome_root = util.GetChromiumSrcDir()
27 required_mode = os.X_OK
28 if binary_name.endswith('.apk'):
29 required_mode = os.R_OK
30 for build_dir, build_type in util.GetBuildDirectories():
31 candidate = os.path.join(chrome_root, build_dir, build_type, binary_name)
32 if os.path.isfile(candidate) and os.access(candidate, required_mode):
33 candidate_mtime = os.stat(candidate).st_mtime
34 if candidate_mtime > command_mtime:
36 command_mtime = candidate_mtime
41 def FindPath(binary_name, platform_name):
42 """Returns the path to the given binary name, pulling from the cloud if
44 if platform_name == 'win':
46 command = FindLocallyBuiltPath(binary_name)
47 if not command and _IsInCloudStorage(binary_name, platform_name):
48 cloud_storage.GetIfChanged(_GetBinPath(binary_name, platform_name))
49 command = _GetBinPath(binary_name, platform_name)