# Copyright 2020 The ANGLE Project 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("../../../gni/angle.gni")

declare_args() {
  # Determines if we build the capture_replay_tests. Off by default.
  angle_build_capture_replay_tests = false

  # Set the trace directory. Default is traces
  angle_capture_replay_test_trace_dir = "traces"

  angle_capture_replay_composite_file_id = 1
}

if (angle_build_capture_replay_tests) {
  assert(angle_with_capture_by_default, "Must build with capture by default.")

  angle_trace_fixture("angle_capture_replay_tests_fixture") {
    gl_header = "angle_trace_gl.h"
    public_deps = [
      "$angle_root:libEGL",
      "$angle_root/util:angle_util",
    ]
  }

  # TODO (nguyenmh): http://anglebug.com/4758:
  # turn angle_executable into angle_test when adding android support
  import(
      "${angle_capture_replay_test_trace_dir}/traces${angle_capture_replay_composite_file_id}.gni")

  # Build each trace into a module. Use a short name to work around file path limits on Windows.
  _trace_counter = 1
  _traces = []
  foreach(_trace_data, trace_data) {
    _trace = _trace_data[0]
    _target = "cr_trace_" + _trace_counter
    _trace_counter += 1
    angle_trace(_target) {
      trace_name = _trace
      trace_dir = angle_capture_replay_test_trace_dir
      trace_ctx = _trace_data[1]
      sources = _trace_data[2]
      fixture = ":angle_capture_replay_tests_fixture"
      output_name = _trace
    }

    _traces += [ ":${_target}" ]
  }

  angle_executable("capture_replay_tests") {
    testonly = true
    sources = [
      "${angle_capture_replay_test_trace_dir}/CompositeTests${angle_capture_replay_composite_file_id}.cpp",
      "${angle_capture_replay_test_trace_dir}/CompositeTests${angle_capture_replay_composite_file_id}.h",
      "CaptureReplayTests.cpp",
    ]
    deps = [
             ":angle_capture_replay_tests_fixture",
             "$angle_root:angle_common",
             "$angle_root:angle_compression",
           ] + _traces
    configs += [
      "$angle_root:library_name_config",
      "$angle_root:libANGLE_config",
    ]
    defines = []

    suppressed_configs += [ "$angle_root:constructor_and_destructor_warnings" ]

    # Disable optimization to avoid optimizing huge files.
    _trace_folder_relative_path = "./" + angle_capture_replay_test_trace_dir
    _data_path = rebase_path(_trace_folder_relative_path, root_out_dir)
    defines = [
      "ANGLE_CAPTURE_REPLAY_TEST_DATA_DIR=\"${_data_path}\"",
      "ANGLE_CAPTURE_REPLAY_COMPOSITE_TESTS_HEADER=" +
          angle_capture_replay_test_trace_dir +
          "/CompositeTests${angle_capture_replay_composite_file_id}.h",
      "ANGLE_REPLAY_EXPORT=",
    ]
    include_dirs = [ "." ]
  }
} else {
  group("capture_replay_tests") {
  }
}
