| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import os | 5 import os |
| 6 import stat | 6 import stat |
| 7 | 7 |
| 8 from telemetry import decorators | 8 from telemetry import decorators |
| 9 from telemetry.util import cloud_storage | 9 from telemetry.util import cloud_storage |
| 10 from telemetry.util import path | 10 from telemetry.util import path |
| 11 | 11 |
| 12 | 12 |
| 13 def _GetBinPath(binary_name, platform_name): | 13 def _GetBinPath(binary_name, arch_name, platform_name): |
| 14 # TODO(tonyg): Add another nesting level for architecture_name. | 14 return os.path.join( |
| 15 return os.path.join(path.GetTelemetryDir(), 'bin', platform_name, binary_name) | 15 path.GetTelemetryDir(), 'bin', platform_name, arch_name, binary_name) |
| 16 | 16 |
| 17 | 17 |
| 18 def _IsInCloudStorage(binary_name, platform_name): | 18 def _IsInCloudStorage(binary_name, arch_name, platform_name): |
| 19 return os.path.exists(_GetBinPath(binary_name, platform_name) + '.sha1') | 19 return os.path.exists( |
| 20 _GetBinPath(binary_name, arch_name, platform_name) + '.sha1') |
| 20 | 21 |
| 21 | 22 |
| 22 @decorators.Cache | 23 @decorators.Cache |
| 23 def FindLocallyBuiltPath(binary_name): | 24 def FindLocallyBuiltPath(binary_name): |
| 24 """Finds the most recently built |binary_name|.""" | 25 """Finds the most recently built |binary_name|.""" |
| 25 command = None | 26 command = None |
| 26 command_mtime = 0 | 27 command_mtime = 0 |
| 27 chrome_root = path.GetChromiumSrcDir() | 28 chrome_root = path.GetChromiumSrcDir() |
| 28 required_mode = os.X_OK | 29 required_mode = os.X_OK |
| 29 if binary_name.endswith('.apk'): | 30 if binary_name.endswith('.apk'): |
| 30 required_mode = os.R_OK | 31 required_mode = os.R_OK |
| 31 for build_dir, build_type in path.GetBuildDirectories(): | 32 for build_dir, build_type in path.GetBuildDirectories(): |
| 32 candidate = os.path.join(chrome_root, build_dir, build_type, binary_name) | 33 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 if os.path.isfile(candidate) and os.access(candidate, required_mode): |
| 34 candidate_mtime = os.stat(candidate).st_mtime | 35 candidate_mtime = os.stat(candidate).st_mtime |
| 35 if candidate_mtime > command_mtime: | 36 if candidate_mtime > command_mtime: |
| 36 command = candidate | 37 command = candidate |
| 37 command_mtime = candidate_mtime | 38 command_mtime = candidate_mtime |
| 38 return command | 39 return command |
| 39 | 40 |
| 40 | 41 |
| 41 @decorators.Cache | 42 @decorators.Cache |
| 42 def FindPath(binary_name, platform_name): | 43 def FindPath(binary_name, arch_name, platform_name): |
| 43 """Returns the path to the given binary name, pulling from the cloud if | 44 """Returns the path to the given binary name, pulling from the cloud if |
| 44 necessary.""" | 45 necessary.""" |
| 45 if platform_name == 'win': | 46 if platform_name == 'win': |
| 46 binary_name += '.exe' | 47 binary_name += '.exe' |
| 47 command = FindLocallyBuiltPath(binary_name) | 48 command = FindLocallyBuiltPath(binary_name) |
| 48 if not command and _IsInCloudStorage(binary_name, platform_name): | 49 if not command and _IsInCloudStorage(binary_name, arch_name, platform_name): |
| 49 cloud_storage.GetIfChanged(_GetBinPath(binary_name, platform_name)) | 50 cloud_storage.GetIfChanged( |
| 50 command = _GetBinPath(binary_name, platform_name) | 51 _GetBinPath(binary_name, arch_name, platform_name)) |
| 52 command = _GetBinPath(binary_name, arch_name, platform_name) |
| 51 | 53 |
| 52 # Ensure the downloaded file is actually executable. | 54 # Ensure the downloaded file is actually executable. |
| 53 if command and os.path.exists(command): | 55 if command and os.path.exists(command): |
| 54 os.chmod(command, | 56 os.chmod(command, |
| 55 stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP) | 57 stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP) |
| 56 | 58 |
| 57 # Return an absolute path consistently. | 59 # Return an absolute path consistently. |
| 58 if command: | 60 if command: |
| 59 command = os.path.abspath(command) | 61 command = os.path.abspath(command) |
| 60 return command | 62 return command |
| OLD | NEW |