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. 4 5import os 6 7from telemetry import decorators 8from telemetry.core import util 9from telemetry.page import cloud_storage 10 11 12def _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) 15 16 17def _IsInCloudStorage(binary_name, platform_name): 18 return os.path.exists(_GetBinPath(binary_name, platform_name) + '.sha1') 19 20 21@decorators.Cache 22def FindLocallyBuiltPath(binary_name): 23 """Finds the most recently built |binary_name|.""" 24 command = None 25 command_mtime = 0 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: 35 command = candidate 36 command_mtime = candidate_mtime 37 return command 38 39 40@decorators.Cache 41def FindPath(binary_name, platform_name): 42 """Returns the path to the given binary name, pulling from the cloud if 43 necessary.""" 44 if platform_name == 'win': 45 binary_name += '.exe' 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) 50 return command 51