Exemplo n.º 1
0
    def __init__(self, browser_type=None):
        optparse.Values.__init__(self)

        self.browser_type = browser_type
        self.browser_executable = None
        self.chrome_root = path_module.GetChromiumSrcDir()
        self.device = None
        self.cros_ssh_identity = None

        self.extensions_to_load = []

        # If set, copy the generated profile to this path on exit.
        self.output_profile_path = None

        self.cros_remote = None

        self.profiler = None
        self.verbosity = 0

        self.browser_options = BrowserOptions()
        self.output_file = None

        self.android_blacklist_file = None
        self.android_rndis = False
        self.no_performance_mode = False
Exemplo n.º 2
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)
Exemplo n.º 3
0
def FindBootstrapDependencies(base_dir):
  deps_file = os.path.join(base_dir, DEPS_FILE)
  if not os.path.exists(deps_file):
    return []
  deps_paths = bootstrap.ListAllDepsPaths(deps_file)
  return set(os.path.realpath(os.path.join(
      path.GetChromiumSrcDir(), '..', deps_path))
      for deps_path in deps_paths)
Exemplo n.º 4
0
def FindAllAvailableBrowsers(finder_options, device):
    """Finds all the desktop mandoline browsers available on this machine."""
    if not isinstance(device, desktop_device.DesktopDevice):
        return []

    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    # Look for a browser in the standard chrome build locations.
    if finder_options.chrome_root:
        chrome_root = finder_options.chrome_root
    else:
        chrome_root = path.GetChromiumSrcDir()

    if sys.platform.startswith('linux'):
        mandoline_app_name = 'mandoline'
    elif sys.platform.startswith('win'):
        mandoline_app_name = 'mandoline.exe'
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given and we can handle it.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        normalized_executable = os.path.expanduser(
            finder_options.browser_executable)
        if path.IsExecutable(normalized_executable):
            browser_directory = os.path.dirname(
                finder_options.browser_executable)
            browsers.append(
                PossibleDesktopMandolineBrowser('exact', finder_options,
                                                normalized_executable,
                                                browser_directory))
        else:
            raise exceptions.PathMissingError(
                '%s specified by --browser-executable does not exist',
                normalized_executable)

    def AddIfFound(browser_type, build_dir, type_dir, app_name):
        browser_directory = os.path.join(chrome_root, build_dir, type_dir)
        app = os.path.join(browser_directory, app_name)
        if path.IsExecutable(app):
            browsers.append(
                PossibleDesktopMandolineBrowser(browser_type, finder_options,
                                                app, browser_directory))
            return True
        return False

    # Add local builds.
    for build_dir, build_type in path.GetBuildDirectories():
        AddIfFound('mandoline-' + build_type.lower(), build_dir, build_type,
                   mandoline_app_name)

    return browsers
Exemplo n.º 5
0
def _IsIosSimulatorAvailable():
    """Determines whether an iOS simulator is present in the local checkout.

  Assumes the iOS simulator (iossim) and Chromium have already been built.

  Returns:
    True if at least one simulator is found, otherwise False.
  """
    for build_dir in IOSSIM_BUILD_DIRECTORIES:
        iossim_path = os.path.join(path.GetChromiumSrcDir(), 'out', build_dir,
                                   'iossim')
        chromium_path = os.path.join(path.GetChromiumSrcDir(), 'out',
                                     build_dir, 'Chromium.app')

        # If the iOS simulator and Chromium app are present, return True
        if os.path.exists(iossim_path) and os.path.exists(chromium_path):
            return True

    return False
Exemplo n.º 6
0
  def _GetVariationsBrowserArgs(self, finder_options):
    chrome_root = finder_options.chrome_root
    if chrome_root is None:
      chrome_root = path_module.GetChromiumSrcDir()

    variations_dir = os.path.join(chrome_root, 'testing', 'variations')
    possible_browser = browser_finder.FindBrowser(finder_options)
    if not possible_browser:
      return []

    return []
Exemplo n.º 7
0
    def _GetVariationsBrowserArgs(self, finder_options, current_args):
        chrome_root = finder_options.chrome_root
        if chrome_root is None:
            chrome_root = path_module.GetChromiumSrcDir()

        variations_dir = os.path.join(chrome_root, 'testing', 'variations')
        possible_browser = browser_finder.FindBrowser(finder_options)
        if not possible_browser:
            return []

        return fieldtrial_util.GenerateArgs(
            os.path.join(variations_dir, 'fieldtrial_testing_config.json'),
            self.FixupTargetOS(possible_browser.target_os), current_args)
Exemplo n.º 8
0
def FindLocallyBuiltPath(binary_name):
  """Finds the most recently built |binary_name|."""
  command = None
  command_mtime = 0
  chrome_root = path.GetChromiumSrcDir()
  required_mode = os.X_OK
  if binary_name.endswith('.apk'):
    required_mode = os.R_OK
  for build_dir, build_type in path.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
Exemplo n.º 9
0
def FindPythonDependencies(module_path):
  logging.info('Finding Python dependencies of %s' % module_path)

  sys_path = sys.path
  sys.path = list(sys_path)
  try:
    # Load the module to inherit its sys.path modifications.
    sys.path.insert(0, os.path.abspath(os.path.dirname(module_path)))
    imp.load_source(
        os.path.splitext(os.path.basename(module_path))[0], module_path)

    # Analyze the module for its imports.
    graph = modulegraph.ModuleGraph()
    graph.run_script(module_path)

    # Filter for only imports in Chromium.
    for node in graph.nodes():
      if not node.filename:
        continue
      module_path = os.path.realpath(node.filename)

      _, incoming_edges = graph.get_edges(node)
      message = 'Discovered %s (Imported by: %s)' % (
          node.filename, ', '.join(
              d.filename for d in incoming_edges
              if d is not None and d.filename is not None))
      logging.info(message)

      # This check is done after the logging/printing above to make sure that
      # we also print out the dependency edges that include python packages
      # that are not in chromium.
      if not path.IsSubpath(module_path, path.GetChromiumSrcDir()):
        continue

      yield module_path
      if node.packagepath is not None:
        for p in node.packagepath:
          yield p

  finally:
    sys.path = sys_path
Exemplo n.º 10
0
def _FindAllPossibleBrowsers(finder_options, android_platform):
  if not android_platform or not CanFindAvailableBrowsers():
    return []

  possible_browsers = []

  if finder_options.chrome_root:
    chrome_root = finder_options.chrome_root
  else:
    chrome_root = path.GetChromiumSrcDir()

  # Add local builds.
  for build_dir, build_type in path.GetBuildDirectories():
    build_path = os.path.join(chrome_root, build_dir, build_type)
    local_apk = os.path.join(build_path, 'apks', 'Mandoline.apk')
    if os.path.exists(local_apk):
      possible_browsers.append(PossibleAndroidMandolineBrowser(
          'android-mandoline-' + build_type.lower(), finder_options,
          android_platform, build_path, local_apk))

  return possible_browsers
Exemplo n.º 11
0
def FindPythonDependencies(module_path):
    logging.info('Finding Python dependencies of %s' % module_path)

    # Load the module to inherit its sys.path modifications.
    imp.load_source(
        os.path.splitext(os.path.basename(module_path))[0], module_path)

    # Analyze the module for its imports.
    finder = modulefinder.ModuleFinder()
    finder.run_script(module_path)

    # Filter for only imports in Chromium.
    for module in finder.modules.itervalues():
        # If it's an __init__.py, module.__path__ gives the package's folder.
        module_path = module.__path__[0] if module.__path__ else module.__file__
        if not module_path:
            continue

        module_path = os.path.realpath(module_path)
        if not path.IsSubpath(module_path, path.GetChromiumSrcDir()):
            continue

        yield module_path
Exemplo n.º 12
0
def FindAllAvailableBrowsers(finder_options, device):
    """Finds all the desktop browsers available on this machine."""
    if not isinstance(device, desktop_device.DesktopDevice):
        return []

    browsers = []

    if not CanFindAvailableBrowsers():
        return []

    has_x11_display = True
    if (sys.platform.startswith('linux') and os.getenv('DISPLAY') == None):
        has_x11_display = False

    # Look for a browser in the standard chrome build locations.
    if finder_options.chrome_root:
        chrome_root = finder_options.chrome_root
    else:
        chrome_root = path.GetChromiumSrcDir()

    flash_bin_dir = os.path.join(chrome_root, 'third_party', 'adobe', 'flash',
                                 'binaries', 'ppapi')

    chromium_app_names = []
    if sys.platform == 'darwin':
        chromium_app_names.append('Chromium.app/Contents/MacOS/Chromium')
        chromium_app_names.append(
            'Google Chrome.app/Contents/MacOS/Google Chrome')
        content_shell_app_name = 'Content Shell.app/Contents/MacOS/Content Shell'
        flash_bin = 'PepperFlashPlayer.plugin'
        flash_path = os.path.join(flash_bin_dir, 'mac', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'mac_64', flash_bin)
    elif sys.platform.startswith('linux'):
        chromium_app_names.append('chrome')
        content_shell_app_name = 'content_shell'
        flash_bin = 'libpepflashplayer.so'
        flash_path = os.path.join(flash_bin_dir, 'linux', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'linux_x64', flash_bin)
    elif sys.platform.startswith('win'):
        chromium_app_names.append('chrome.exe')
        content_shell_app_name = 'content_shell.exe'
        flash_bin = 'pepflashplayer.dll'
        flash_path = os.path.join(flash_bin_dir, 'win', flash_bin)
        flash_path_64 = os.path.join(flash_bin_dir, 'win_x64', flash_bin)
    else:
        raise Exception('Platform not recognized')

    # Add the explicit browser executable if given and we can handle it.
    if (finder_options.browser_executable
            and CanPossiblyHandlePath(finder_options.browser_executable)):
        normalized_executable = os.path.expanduser(
            finder_options.browser_executable)
        if path.IsExecutable(normalized_executable):
            browser_directory = os.path.dirname(
                finder_options.browser_executable)
            browsers.append(
                PossibleDesktopBrowser('exact', finder_options,
                                       normalized_executable, flash_path,
                                       False, browser_directory))
        else:
            raise exceptions.PathMissingError(
                '%s specified by --browser-executable does not exist' %
                normalized_executable)

    def AddIfFound(browser_type, build_dir, type_dir, app_name, content_shell):
        browser_directory = os.path.join(chrome_root, build_dir, type_dir)
        app = os.path.join(browser_directory, app_name)
        if path.IsExecutable(app):
            is_64 = browser_type.endswith('_x64')
            browsers.append(
                PossibleDesktopBrowser(browser_type,
                                       finder_options,
                                       app,
                                       flash_path_64 if is_64 else flash_path,
                                       content_shell,
                                       browser_directory,
                                       is_local_build=True))
            return True
        return False

    # Add local builds
    for build_dir, build_type in path.GetBuildDirectories():
        for chromium_app_name in chromium_app_names:
            AddIfFound(build_type.lower(), build_dir, build_type,
                       chromium_app_name, False)
        AddIfFound('content-shell-' + build_type.lower(), build_dir,
                   build_type, content_shell_app_name, True)

    reference_build_root = os.path.join(chrome_root, 'chrome', 'tools', 'test',
                                        'reference_build')

    # Mac-specific options.
    if sys.platform == 'darwin':
        mac_canary_root = '/Applications/Google Chrome Canary.app/'
        mac_canary = mac_canary_root + 'Contents/MacOS/Google Chrome Canary'
        mac_system_root = '/Applications/Google Chrome.app'
        mac_system = mac_system_root + '/Contents/MacOS/Google Chrome'
        mac_reference_root = reference_build_root + '/chrome_mac/Google Chrome.app/'
        mac_reference = mac_reference_root + 'Contents/MacOS/Google Chrome'
        if path.IsExecutable(mac_canary):
            browsers.append(
                PossibleDesktopBrowser('canary', finder_options, mac_canary,
                                       None, False, mac_canary_root))

        if path.IsExecutable(mac_system):
            browsers.append(
                PossibleDesktopBrowser('system', finder_options, mac_system,
                                       None, False, mac_system_root))
        if path.IsExecutable(mac_reference):
            browsers.append(
                PossibleDesktopBrowser('reference', finder_options,
                                       mac_reference, None, False,
                                       mac_reference_root))

    # Linux specific options.
    if sys.platform.startswith('linux'):
        # Look for a google-chrome instance.
        found = False
        try:
            with open(os.devnull, 'w') as devnull:
                found = subprocess.call(['google-chrome', '--version'],
                                        stdout=devnull,
                                        stderr=devnull) == 0
        except OSError:
            pass
        if found:
            browsers.append(
                PossibleDesktopBrowser('system', finder_options,
                                       'google-chrome', None, False,
                                       '/opt/google/chrome'))
        linux_reference_root = os.path.join(reference_build_root,
                                            'chrome_linux')
        linux_reference = os.path.join(linux_reference_root, 'chrome')
        if path.IsExecutable(linux_reference):
            browsers.append(
                PossibleDesktopBrowser('reference', finder_options,
                                       linux_reference, None, False,
                                       linux_reference_root))

    # Win32-specific options.
    if sys.platform.startswith('win'):
        app_paths = (
            ('system', os.path.join('Google', 'Chrome', 'Application')),
            ('canary', os.path.join('Google', 'Chrome SxS', 'Application')),
            ('reference', os.path.join(reference_build_root, 'chrome_win')),
        )

        for browser_name, app_path in app_paths:
            for chromium_app_name in chromium_app_names:
                app_path = os.path.join(app_path, chromium_app_name)
                app_path = path.FindInstalledWindowsApplication(app_path)
                if app_path:
                    browsers.append(
                        PossibleDesktopBrowser(browser_name, finder_options,
                                               app_path, None, False,
                                               os.path.dirname(app_path)))

    has_ozone_platform = False
    for arg in finder_options.browser_options.extra_browser_args:
        if "--ozone-platform" in arg:
            has_ozone_platform = True

    if len(browsers) and not has_x11_display and not has_ozone_platform:
        logging.warning(
            'Found (%s), but you do not have a DISPLAY environment set.' %
            ','.join([b.browser_type for b in browsers]))
        return []

    return browsers
Exemplo n.º 13
0
 def NormalizePath(p):
     p = p.replace('/', os.path.sep)
     return os.path.realpath(os.path.join(path.GetChromiumSrcDir(), p))
Exemplo n.º 14
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)