chromium/tools/perf/chrome_telemetry_build/BUILD.gn

# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/config/chromeos/ui_mode.gni")
import("//build/config/compiler/compiler.gni")
if (is_android) {
  # Pull in enable_chrome_android_internal and public_android_sdk
  import("//build/config/android/config.gni")
  import("//tools/perf/chrome_telemetry_build/android_browser_types.gni")
}

if (is_chromeos_device) {
  import("//build/config/chromeos/rules.gni")

  generate_runner_script("cros_update_wrapper") {
    generated_script = "$root_build_dir/bin/cros_update_wrapper"
    if (is_chromeos_ash) {
      deploy_chrome = true
    } else {
      deploy_lacros = true
      skip_generating_board_args = true
    }
    if (!is_chromeos_ash || also_build_lacros_chrome_for_architecture != "") {
      data = [
        # A script needed to launch Lacros in testing environment.
        "//build/lacros/mojo_connection_lacros_launcher.py",
      ]
    }
  }
}

group("telemetry_chrome_test") {
  testonly = true

  data_deps = [
    ":telemetry_chrome_test_without_chrome",
    "//third_party/perfetto/src/trace_processor:trace_processor_shell",
  ]
  data = []

  if (!is_fuchsia && !is_android && !is_castos && !is_ios) {
    data_deps += [ "//chrome" ]
  }

  if (is_win) {
    data_deps += [ "//chrome:reorder_imports" ]
  }

  if (is_linux || is_chromeos) {
    data_deps += [ "//third_party/breakpad:dump_syms" ]

    # CrOS currently has issues with the locally compiled version of
    # crashpad_database_util, so only include it on traditional Linux
    # platforms.
    if (is_linux) {
      data_deps +=
          [ "//third_party/crashpad/crashpad/tools:crashpad_database_util" ]
    }
  }

  if (is_mac) {
    data_deps += [
      "//chrome:chrome_framework",
      "//chrome:chrome_helper_app_default",
      "//third_party/breakpad:dump_syms",
      "//third_party/crashpad/crashpad/tools:crashpad_database_util",
    ]
  }

  if (is_chromeos_device) {
    data_deps += [ ":cros_update_wrapper" ]
  }

  if (is_chromeos_ash && is_chromeos_device) {
    data_deps += [
      "//:chromiumos_preflight",
      "//chromeos:cros_chrome_deploy",
      "//chromeos:cros_test_wrapper",
    ]
  }

  if (is_win) {
    data_deps += [
      "//build/win:copy_cdb_to_output",
      "//third_party/crashpad/crashpad/tools:crashpad_database_util",
    ]
  }
}

# These telemetry_chrome_test_* targets exist to reduce the amount of data
# included in swarming isolates. Including a bunch of different versions of
# Chrome and their unstripped .so files that aren't actually used adds gigabytes
# of data to the isolate, which in turn adds a non-trivial amount of swarming
# overhead. A new one should be added each time a new type of APK is supported
# and its suffix added to android_browser_types.gni.
if (is_android) {
  _bitness_if_needed = ""
  _webview_bitness_if_needed = ""
  if (android_64bit_target_cpu && !skip_secondary_abi_for_cq) {
    _bitness_if_needed = "_64_32"
    _webview_bitness_if_needed = "_32_64"
  }
  group("telemetry_chrome_test_android_chrome") {
    testonly = true

    data_deps = [
      ":telemetry_chrome_test",
      "//chrome/android:chrome_public_apk",
    ]
  }

  group("telemetry_chrome_test_android_monochrome") {
    testonly = true

    data_deps = [
      ":telemetry_chrome_test",
      "//chrome/android:monochrome${_bitness_if_needed}_public_apk",
    ]
  }

  group("telemetry_chrome_test_android_monochrome_bundle") {
    testonly = true

    data_deps = [
      ":telemetry_chrome_test",
      "//chrome/android:monochrome${_bitness_if_needed}_public_bundle",
    ]
  }

  group("telemetry_chrome_test_android_webview") {
    testonly = true

    data_deps = [
      ":telemetry_chrome_test",
      "//android_webview:system_webview${_webview_bitness_if_needed}_apk",
      "//android_webview/test:webview_instrumentation_apk",
      "//android_webview/tools/system_webview_shell:system_webview_shell_apk",
    ]
  }

  if (enable_chrome_android_internal) {
    import("//clank/telemetry_browser_types.gni")

    template("telemetry_chrome_test_clank_template") {
      forward_variables_from(invoker, [ "telemetry_target_suffix" ])
      group(target_name) {
        testonly = true
        data_deps = [
          ":telemetry_chrome_test",
          "//clank:telemetry_clank_test${telemetry_target_suffix}",
        ]
      }
    }

    foreach(_target_suffix, telemetry_clank_browser_target_suffixes) {
      telemetry_chrome_test_clank_template(
          "telemetry_chrome_test${_target_suffix}") {
        telemetry_target_suffix = _target_suffix
      }
    }
  }
}

group("telemetry_chrome_test_without_chrome") {
  testonly = true

  data = [
    "//build/android/pylib/",  # chromium_config.py uses pylib to look for Java
    "//components/crash/content/tools/generate_breakpad_symbols.py",
    "//tools/perf/chrome_telemetry_build/",
    "//tools/perf/core/",  # chrome_telemetry_build/ depends on core/
  ]
  data_deps = [
    "//testing:test_scripts_shared",
    "//third_party/catapult:telemetry_chrome_test_support",
    "//tools/metrics:metrics_python_tests",
  ]

  # Cr-Fuchsia doesn't support breakpad.
  if (!is_win && !is_fuchsia) {
    data_deps += [
      # This is defined for Windows, but is unused by Telemetry on
      # Windows, and including it can have issues when cross-compiling
      # for Arm-based Windows.
      "//third_party/breakpad:dump_syms",

      # These explicitly not defined for Windows builds in Breakpad.
      "//third_party/breakpad:minidump_dump",
      "//third_party/breakpad:minidump_stackwalk",
    ]
  }

  if (is_win) {
    data_deps += [
      # This is a stand-in for minidump_stackwalk on Windows since
      # minidump_stackwalk is not defined on Windows.
      "//third_party/crashpad/crashpad/tools:dump_minidump_annotations",
    ]
  }

  if (is_mac) {
    data += [
      # Required for the hermetic otool binary, which is required for
      # symbolizing minidumps on Mac.
      "//build/mac_files/xcode_binaries/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/",
    ]
  }

  if (is_android) {
    data += [
      # TODO(httpss://crbug.com/833808): Remove this once bots always set
      # CHROMIUM_OUTPUT_DIR correctly. Currently, this is necessary in order
      # for //build/android/pylib/constants/__init__.py to detect the output
      # directory, which tombstones.py depends on.
      "$root_out_dir/build.ninja",

      # These dependencies are necessary for running Telemetry tests in an
      # Android emulator.
      "//third_party/android_toolchain/ndk/simpleperf/",
      "//third_party/android_sdk/public/",
      "//tools/android/avd/proto/",
    ]
    data_deps += [
      "//build/android:devil_chromium_py",
      "//build/android:stack_tools",
    ]
  } else if (!is_fuchsia) {
    data_deps += [ "//third_party/catapult/telemetry:bitmaptools" ]
  }
}