Ejemplo n.º 1
0
def FindDependencies(target_paths, options):
    # Verify arguments.
    for target_path in target_paths:
        if not os.path.exists(target_path):
            raise ValueError('Path does not exist: %s' % target_path)

    dependencies = path_set.PathSet()

    # Including Telemetry's major entry points will (hopefully) include Telemetry
    # and all its dependencies. If the user doesn't pass any arguments, we just
    # have Telemetry.
    dependencies |= FindPythonDependencies(
        os.path.realpath(
            os.path.join(path.GetTelemetryDir(), 'telemetry',
                         'benchmark_runner.py')))
    dependencies |= FindPythonDependencies(
        os.path.realpath(
            os.path.join(path.GetTelemetryDir(), 'telemetry', 'testing',
                         'run_tests.py')))
    dependencies |= FindBootstrapDependencies(path.GetTelemetryDir())

    # Add dependencies.
    for target_path in target_paths:
        base_dir = os.path.dirname(os.path.realpath(target_path))

        dependencies.add(base_dir)
        dependencies |= FindBootstrapDependencies(base_dir)
        dependencies |= FindPythonDependencies(target_path)
        if options.include_page_set_data:
            dependencies |= FindPageSetDependencies(base_dir)

    # Remove excluded files.
    dependencies -= FindExcludedFiles(set(dependencies), options)

    return dependencies
Ejemplo n.º 2
0
def _InstallWinRing0():
    """WinRing0 is used for reading MSRs."""
    executable_dir = os.path.dirname(sys.executable)

    python_is_64_bit = sys.maxsize > 2**32
    dll_file_name = 'WinRing0x64.dll' if python_is_64_bit else 'WinRing0.dll'
    dll_path = os.path.join(executable_dir, dll_file_name)

    os_is_64_bit = platform.machine().endswith('64')
    driver_file_name = 'WinRing0x64.sys' if os_is_64_bit else 'WinRing0.sys'
    driver_path = os.path.join(executable_dir, driver_file_name)

    # Check for WinRing0 and download if needed.
    if not (os.path.exists(dll_path) and os.path.exists(driver_path)):
        win_binary_dir = os.path.join(path.GetTelemetryDir(), 'bin', 'win',
                                      'AMD64')
        zip_path = os.path.join(win_binary_dir, 'winring0.zip')
        cloud_storage.GetIfChanged(zip_path,
                                   bucket=cloud_storage.PUBLIC_BUCKET)
        try:
            with zipfile.ZipFile(zip_path, 'r') as zip_file:
                error_message = (
                    'Failed to extract %s into %s. If python claims that '
                    'the zip file is locked, this may be a lie. The problem may be '
                    'that python does not have write permissions to the destination '
                    'directory.')
                # Install DLL.
                if not os.path.exists(dll_path):
                    try:
                        zip_file.extract(dll_file_name, executable_dir)
                    except:
                        logging.error(error_message %
                                      (dll_file_name, executable_dir))
                        raise

                # Install kernel driver.
                if not os.path.exists(driver_path):
                    try:
                        zip_file.extract(driver_file_name, executable_dir)
                    except:
                        logging.error(error_message %
                                      (driver_file_name, executable_dir))
                        raise
        finally:
            os.remove(zip_path)
Ejemplo n.º 3
0
INTERNAL_BUCKET = 'chrome-telemetry'
TELEMETRY_OUTPUT = 'chrome-telemetry-output'

# Uses ordered dict to make sure that bucket's key-value items are ordered from
# the most open to the most restrictive.
BUCKET_ALIASES = collections.OrderedDict((
    ('public', PUBLIC_BUCKET),
    ('partner', PARTNER_BUCKET),
    ('internal', INTERNAL_BUCKET),
    ('output', TELEMETRY_OUTPUT),
))

BUCKET_ALIAS_NAMES = BUCKET_ALIASES.keys()


_GSUTIL_PATH = os.path.join(path.GetTelemetryDir(), 'third_party', 'gsutilz',
                            'gsutil')

# TODO(tbarzic): A workaround for http://crbug.com/386416 and
#     http://crbug.com/359293. See |_RunCommand|.
_CROS_GSUTIL_HOME_WAR = '/home/chromeos-test/'


class CloudStorageError(Exception):
  @staticmethod
  def _GetConfigInstructions():
    command = _GSUTIL_PATH
    if util.IsRunningOnCrosDevice():
      command = 'HOME=%s %s' % (_CROS_GSUTIL_HOME_WAR, _GSUTIL_PATH)
    return ('To configure your credentials:\n'
            '  1. Run "%s config" and follow its instructions.\n'
Ejemplo n.º 4
0
# Copyright 2015 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 json
import os
import platform
import sys
import unittest

from telemetry.internal.util import find_dependencies
from telemetry.internal.util import path

_TELEMETRY_DEPS_PATH = os.path.join(path.GetTelemetryDir(), 'telemetry',
                                    'TELEMETRY_DEPS')


def _GetCurrentTelemetryDependencies():
    parser = find_dependencies.FindDependenciesCommand.CreateParser()
    find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None)
    options, args = parser.parse_args([''])
    options.positional_args = args
    return find_dependencies.FindDependencies([], options=options)


def _GetRestrictedTelemetryDeps():
    with open(_TELEMETRY_DEPS_PATH, 'r') as f:
        telemetry_deps = json.load(f)

    # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain
    # the relative path in chromium/src/.
Ejemplo n.º 5
0
def ZipDependencies(target_paths, dependencies, options):
    base_dir = os.path.dirname(os.path.realpath(path.GetChromiumSrcDir()))

    with zipfile.ZipFile(options.zip, 'w', zipfile.ZIP_DEFLATED) as zip_file:
        # Add dependencies to archive.
        for dependency_path in dependencies:
            path_in_archive = os.path.join(
                'telemetry', os.path.relpath(dependency_path, base_dir))
            zip_file.write(dependency_path, path_in_archive)

        # Add symlinks to executable paths, for ease of use.
        for target_path in target_paths:
            link_info = zipfile.ZipInfo(
                os.path.join('telemetry', os.path.basename(target_path)))
            link_info.create_system = 3  # Unix attributes.
            # 010 is regular file, 0111 is the permission bits rwxrwxrwx.
            link_info.external_attr = 0100777 << 16  # Octal.

            relative_path = os.path.relpath(target_path, base_dir)
            link_script = (
                '#!/usr/bin/env python\n\n'
                'import os\n'
                'import sys\n\n\n'
                'script = os.path.join(os.path.dirname(__file__), \'%s\')\n'
                'os.execv(sys.executable, [sys.executable, script] + sys.argv[1:])'
                % relative_path)

            zip_file.writestr(link_info, link_script)

        # Add gsutil to the archive, if it's available. The gsutil in
        # depot_tools is modified to allow authentication using prodaccess.
        # TODO: If there's a gsutil in telemetry/third_party/, bootstrap_deps
        # will include it. Then there will be two copies of gsutil at the same
        # location in the archive. This can be confusing for users.
        gsutil_path = os.path.realpath(cloud_storage.FindGsutil())
        if cloud_storage.SupportsProdaccess(gsutil_path):
            gsutil_base_dir = os.path.join(os.path.dirname(gsutil_path),
                                           os.pardir)
            gsutil_dependencies = path_set.PathSet()
            gsutil_dependencies.add(os.path.dirname(gsutil_path))
            # Also add modules from depot_tools that are needed by gsutil.
            gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'boto'))
            gsutil_dependencies.add(
                os.path.join(gsutil_base_dir, 'fancy_urllib'))
            gsutil_dependencies.add(
                os.path.join(gsutil_base_dir, 'retry_decorator'))
            gsutil_dependencies -= FindExcludedFiles(set(gsutil_dependencies),
                                                     options)

            # Also add upload.py to the archive from depot_tools, if it is available.
            # This allows us to post patches without requiring a full depot_tools
            # install. There's no real point in including upload.py if we do not
            # also have gsutil, which is why this is inside the gsutil block.
            gsutil_dependencies.add(os.path.join(gsutil_base_dir, 'upload.py'))

            for dependency_path in gsutil_dependencies:
                path_in_archive = os.path.join(
                    'telemetry',
                    os.path.relpath(path.GetTelemetryDir(), base_dir),
                    'third_party',
                    os.path.relpath(dependency_path, gsutil_base_dir))
                zip_file.write(dependency_path, path_in_archive)
# Copyright 2015 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 json
import os
import unittest

from telemetry.internal.util import find_dependencies
from telemetry.internal.util import path


_TELEMETRY_DEPS_PATH = os.path.join(
    path.GetTelemetryDir(), 'telemetry', 'TELEMETRY_DEPS')


def _GetCurrentTelemetryDependencies():
  parser = find_dependencies.FindDependenciesCommand.CreateParser()
  find_dependencies.FindDependenciesCommand.AddCommandLineArgs(parser, None)
  options, args = parser.parse_args([''])
  options.positional_args = args
  return find_dependencies.FindDependencies([], options=options)


def _GetRestrictedTelemetryDeps():
  with open(_TELEMETRY_DEPS_PATH, 'r') as f:
    telemetry_deps = json.load(f)

  # Normalize paths in telemetry_deps since TELEMETRY_DEPS file only contain
  # the relative path in chromium/src/.
  def NormalizePath(p):
Ejemplo n.º 7
0
def _GetBinPath(binary_name, arch_name, platform_name):
    return os.path.join(path.GetTelemetryDir(), 'bin', platform_name,
                        arch_name, binary_name)