Clean up check for dependency_info.
[chromium-blink-merge.git] / tools / telemetry / catapult_base / support_binaries.py
blobb6de487b15e592fbfe6cc1c49e5dce0086c06f44
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.
5 import logging
6 import os
7 import stat
9 from catapult_base import cloud_storage
10 from telemetry.internal.util import path
13 def _GetBinPath(binary_name, arch_name, platform_name):
14 return os.path.join(
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')
23 def FindLocallyBuiltPath(binary_name):
24 """Finds the most recently built |binary_name|."""
25 command = None
26 command_mtime = 0
27 chrome_root = path.GetChromiumSrcDir()
28 required_mode = os.X_OK
29 if binary_name.endswith('.apk'):
30 required_mode = os.R_OK
31 for build_dir, build_type in path.GetBuildDirectories():
32 candidate = os.path.join(chrome_root, build_dir, build_type, binary_name)
33 if os.path.isfile(candidate) and os.access(candidate, required_mode):
34 candidate_mtime = os.stat(candidate).st_mtime
35 if candidate_mtime > command_mtime:
36 command = candidate
37 command_mtime = candidate_mtime
38 return command
41 def FindPath(binary_name, arch_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, arch_name, platform_name):
48 logging.info('checking cloud_storage')
49 command = _GetBinPath(binary_name, arch_name, platform_name)
50 cloud_storage.GetIfChanged(
51 command, cloud_storage.PUBLIC_BUCKET)
53 # Ensure the downloaded file is actually executable.
54 if command and os.path.exists(command):
55 os.chmod(command,
56 stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP)
57 if not command and platform_name == 'win' and arch_name != 'AMD64':
58 # This is an awful, awful hack to temporarily fix cloud_storage downloads
59 # on XP until the binary_manager is finished and migrated to.
60 # Please don't try this at home.
61 return FindPath(binary_name, 'AMD64', platform_name)
63 # Return an absolute path consistently.
64 if command:
65 command = os.path.abspath(command)
66 logging.info('SupportBinaries found path: %s for binary: %s on arch: %s and '
67 'platform :%s' % (command, binary_name, arch_name,
68 platform_name))
69 return command