# Copyright 2014 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/python.gni")
import("//testing/test.gni")

# Used by linux-gcc-rel to ensure gcc doesn't choke on clang-only flags.
if (!is_clang) {
  executable("empty_main") {
    sources = [ "empty_main.cc" ]

    # The bot should only check that an empty file builds fine with gcc.
    # There's no need to check that libc++ builds with a (possibly very old)
    # version of gcc.
    # No need to remove "//build/config/compiler:runtime_library" from configs
    # (to remove its subconfig "//build/config/c++:runtime_library") since
    # empty_main.cc does not include any headers.
    no_default_deps = true
  }
}

# Targets needed for isolate script to execute.
group("test_scripts_shared") {
  data_deps = [
    # Used for reporting exceptions and test script metrics to RDB.
    "//build/util:proto",

    # Used for reporting test results to RDB.
    "//build/util:test_results",
  ]

  data = [
    "//testing/test_env.py",
    "//testing/xvfb.py",
    "//testing/scripts/common.py",
  ]
}

script_test("test_env_py_unittests") {
  script = "//testing/scripts/run_isolated_script_test.py"
  args = [
    "@WrappedPath(" +
        rebase_path("//testing/test_env_unittest.py", root_build_dir) + ")",
    "--script-type=bare",
  ]
  data = [
    "//testing/test_env_test_script.py",
    "//testing/test_env_unittest.py",
    "//testing/test_env_user_script.py",
  ]
  data_deps = [ ":test_scripts_shared" ]
}

script_test("xvfb_py_unittests") {
  script = "//testing/scripts/run_isolated_script_test.py"
  args = [
    "@WrappedPath(" +
        rebase_path("//testing/xvfb_unittest.py", root_build_dir) + ")",
    "--script-type=bare",
  ]
  data = [
    "//testing/xvfb_test_script.py",
    "//testing/xvfb_unittest.py",
  ]
  data_deps = [ ":test_scripts_shared" ]
}

group("run_perf_test") {
  data = [
    "//testing/scripts/common.py",
    "//testing/scripts/run_performance_tests.py",
    "//tools/perf/generate_legacy_perf_dashboard_json.py",
    "//tools/perf/core/__init__.py",
    "//tools/perf/core/path_util.py",
    "//tools/perf/core/results_merger.py",
  ]

  data_deps = [
    ":test_scripts_shared",
    "//third_party/catapult/tracing:convert_chart_json",
  ]

  if (is_android) {
    # Required when running with bundles (to run "bundletool").
    data_deps += [ "//third_party/jdk:java_data" ]
  }
}

group("pytype_dependencies") {
  data = [
    "//build/util/lib/results/",
    "//testing/pytype_common/",
  ]
}

group("testing_pytype") {
  data = [
    "//testing/run_pytype.py",

    "//testing/unexpected_passes_common/",
    "//testing/flake_suppressor_common/",
    "//third_party/blink/tools/",
    "//third_party/catapult/third_party/typ/",
  ]

  data_deps = [ ":pytype_dependencies" ]
}

group("fuchsia_pytype") {
  testonly = true
  data = [
    "//build/fuchsia/test/",
    "//build/util/lib/common/",
  ]
  data_deps = [ ":pytype_dependencies" ]
}

python_library("run_isolated_script_test") {
  testonly = true
  pydeps_file = "//testing/scripts/run_isolated_script_test.pydeps"
  data = [ "//.vpython3" ]
}
