| Index: tools/telemetry/telemetry/util/support_binaries.py
|
| diff --git a/tools/telemetry/telemetry/util/support_binaries.py b/tools/telemetry/telemetry/util/support_binaries.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..dbc7293472ab8094649b89a58e2805858be2cd64
|
| --- /dev/null
|
| +++ b/tools/telemetry/telemetry/util/support_binaries.py
|
| @@ -0,0 +1,62 @@
|
| +# Copyright (c) 2014 The Chromium Authors. All rights reserved.
|
| +# Use of this source code is governed by a BSD-style license that can be
|
| +# found in the LICENSE file.
|
| +
|
| +import os
|
| +
|
| +from telemetry import decorators
|
| +from telemetry.core import util
|
| +from telemetry.page import cloud_storage
|
| +
|
| +
|
| +def _GetBinPath(binary_name, platform_name):
|
| + # TODO(tonyg): Add another nesting level for architecture_name.
|
| + return os.path.join(util.GetTelemetryDir(), 'bin', platform_name, binary_name)
|
| +
|
| +
|
| +def _IsInCloudStorage(binary_name, platform_name):
|
| + return os.path.exists(_GetBinPath(binary_name, platform_name) + '.sha1')
|
| +
|
| +
|
| +def _UpdateFromCloudStorage(binary_name, platform_name):
|
| + for bucket in [cloud_storage.INTERNAL_BUCKET,
|
| + cloud_storage.PARTNER_BUCKET,
|
| + cloud_storage.PUBLIC_BUCKET]:
|
| + try:
|
| + cloud_storage.GetIfChanged(
|
| + _GetBinPath(binary_name, platform_name), bucket)
|
| + return
|
| + except cloud_storage.CloudStorageError:
|
| + continue
|
| +
|
| +
|
| +@decorators.Cache
|
| +def FindLocallyBuiltPath(binary_name):
|
| + """Finds the most recently built |binary_name|."""
|
| + command = None
|
| + command_mtime = 0
|
| + chrome_root = util.GetChromiumSrcDir()
|
| + required_mode = os.X_OK
|
| + if binary_name.endswith('.apk'):
|
| + required_mode = os.R_OK
|
| + for build_dir, build_type in util.GetBuildDirectories():
|
| + candidate = os.path.join(chrome_root, build_dir, build_type, binary_name)
|
| + if os.path.isfile(candidate) and os.access(candidate, required_mode):
|
| + candidate_mtime = os.stat(candidate).st_mtime
|
| + if candidate_mtime > command_mtime:
|
| + command = candidate
|
| + command_mtime = candidate_mtime
|
| + return command
|
| +
|
| +
|
| +@decorators.Cache
|
| +def FindPath(binary_name, platform_name):
|
| + """Returns the path to the given binary name, pulling from the cloud if
|
| + necessary."""
|
| + if platform_name == 'win':
|
| + binary_name += '.exe'
|
| + command = FindLocallyBuiltPath(binary_name)
|
| + if not command and _IsInCloudStorage(binary_name, platform_name):
|
| + _UpdateFromCloudStorage(binary_name, platform_name)
|
| + command = _GetBinPath(binary_name, platform_name)
|
| + return command
|
|
|