def FetchBinaryDependencies(
    platform, client_configs, fetch_reference_chrome_binary):
  """ Fetch all binary dependenencies for the given |platform|.

  Note: we don't fetch browser binaries by default because the size of the
  binary is about 2Gb, and it requires cloud storage permission to
  chrome-telemetry bucket.

  Args:
    platform: an instance of telemetry.core.platform
    client_configs: A list of paths (string) to dependencies json files.
    fetch_reference_chrome_binary: whether to fetch reference chrome binary for
      the given platform.
  """
  configs = [
      dependency_manager.BaseConfig(TELEMETRY_PROJECT_CONFIG),
  ]
  dep_manager = dependency_manager.DependencyManager(configs)
  os_name = platform.GetOSName()
  # If we're running directly on a Chrome OS device, fetch the binaries for
  # linux instead, which should be compatible with CrOS. Otherwise, if we're
  # running remotely on CrOS, fetch the binaries for the host platform like
  # we do with android below.
  if _IsChromeOSLocalMode(os_name):
    os_name = 'linux'
  target_platform = '%s_%s' % (os_name, platform.GetArchName())
  dep_manager.PrefetchPaths(target_platform)

  host_platform = None
  fetch_devil_deps = False
  if os_name in ('android', 'chromeos'):
    host_platform = '%s_%s' % (
        py_utils.GetHostOsName(), py_utils.GetHostArchName())
    dep_manager.PrefetchPaths(host_platform)
    if os_name == 'android':
      if host_platform == 'linux_x86_64':
        fetch_devil_deps = True
      else:
        logging.error('Devil only supports 64 bit linux as a host platform. '
                      'Android tests may fail.')

  if fetch_reference_chrome_binary:
    _FetchReferenceBrowserBinary(platform)

  # For now, handle client config separately because the BUILD.gn & .isolate of
  # telemetry tests in chromium src failed to include the files specified in its
  # client config.
  # (https://github.com/catapult-project/catapult/issues/2192)
  # For now this is ok because the client configs usually don't include cloud
  # storage infos.
  # TODO(crbug.com/1111556): remove the logic of swallowing exception once the
  # issue is fixed on Chromium side.
  if client_configs:
    manager = dependency_manager.DependencyManager(
        list(dependency_manager.BaseConfig(c) for c in client_configs))
    try:
      manager.PrefetchPaths(target_platform)
      if host_platform is not None:
        manager.PrefetchPaths(host_platform)

    except dependency_manager.NoPathFoundError as e:
      logging.error('Error when trying to prefetch paths for %s: %s',
                    target_platform, e)

  if fetch_devil_deps:
    devil_env.config.Initialize()
    devil_env.config.PrefetchPaths(arch=platform.GetArchName())
    devil_env.config.PrefetchPaths()