# Copyright 2018 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/sanitizers/sanitizers.gni")
import("//third_party/abseil-cpp/absl.gni")

absl_source_set("stacktrace") {
  sources = [
    "internal/stacktrace_aarch64-inl.inc",
    "internal/stacktrace_arm-inl.inc",
    "internal/stacktrace_config.h",
    "internal/stacktrace_emscripten-inl.inc",
    "internal/stacktrace_generic-inl.inc",
    "internal/stacktrace_powerpc-inl.inc",
    "internal/stacktrace_riscv-inl.inc",
    "internal/stacktrace_unimplemented-inl.inc",
    "internal/stacktrace_win32-inl.inc",
    "internal/stacktrace_x86-inl.inc",
    "stacktrace.cc",
  ]
  public = [ "stacktrace.h" ]
  deps = [
    ":debugging_internal",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:dynamic_annotations",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
  ]
}

absl_test("stacktrace_test") {
  sources = [ "stacktrace_test.cc" ]
  deps = [
    ":stacktrace",
    "//third_party/abseil-cpp/absl/base:core_headers",
  ]
}

absl_source_set("symbolize") {
  sources = [
    "symbolize.cc",
    "symbolize_darwin.inc",
    "symbolize_elf.inc",
    "symbolize_emscripten.inc",
    "symbolize_unimplemented.inc",
    "symbolize_win32.inc",
  ]
  public = [
    "internal/symbolize.h",
    "symbolize.h",
  ]
  deps = [
    ":debugging_internal",
    ":demangle_internal",
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:dynamic_annotations",
    "//third_party/abseil-cpp/absl/base:malloc_internal",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
    "//third_party/abseil-cpp/absl/strings",
    "//third_party/abseil-cpp/absl/strings:string_view",
  ]

  # TODO(mbonadei): The bazel file has:
  #   -DEFAULTLIB:dbghelp.lib
  # evaluate if this needs to be added here as well.
}

absl_source_set("examine_stack") {
  sources = [ "internal/examine_stack.cc" ]
  public = [ "internal/examine_stack.h" ]
  visibility = [
    ":*",
    "//third_party/abseil-cpp/absl/log/internal:*",
  ]
  deps = [
    ":stacktrace",
    ":symbolize",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
  ]
}

absl_source_set("failure_signal_handler") {
  sources = [ "failure_signal_handler.cc" ]
  public = [ "failure_signal_handler.h" ]
  deps = [
    ":examine_stack",
    ":stacktrace",
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
  ]
}

absl_source_set("debugging_internal") {
  sources = [
    "internal/address_is_readable.cc",
    "internal/elf_mem_image.cc",
    "internal/vdso_support.cc",
  ]
  public = [
    "internal/address_is_readable.h",
    "internal/elf_mem_image.h",
    "internal/vdso_support.h",
  ]
  visibility = [ ":*" ]
  deps = [
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:dynamic_annotations",
    "//third_party/abseil-cpp/absl/base:errno_saver",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
  ]
}

absl_source_set("demangle_internal") {
  sources = [ "internal/demangle.cc" ]
  public = [ "internal/demangle.h" ]
  visibility = [
    "//third_party/abseil-cpp/absl/container:*",
    "//third_party/abseil-cpp/absl/debugging:*",
  ]
  deps = [
    ":demangle_rust",
    "//third_party/abseil-cpp/absl/base",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:nullability",
    "//third_party/abseil-cpp/absl/numeric:bits",
  ]
}

# Disabled because this test relies on RTTI
# absl_test("demangle_test") {
#   sources = [ "internal/demangle_test.cc" ]
#   deps = [
#     ":demangle_internal",
#     ":stack_consumption",
#     "//third_party/abseil-cpp/absl/base:config",
#     "//third_party/abseil-cpp/absl/base:core_headers",
#     "//third_party/abseil-cpp/absl/log",
#     "//third_party/abseil-cpp/absl/memory",
#   ]
# }

absl_source_set("bounded_utf8_length_sequence") {
  public = [ "internal/bounded_utf8_length_sequence.h" ]
  deps = [
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/numeric:bits",
  ]
}

absl_test("bounded_utf8_length_sequence_test") {
  sources = [ "internal/bounded_utf8_length_sequence_test.cc" ]
  deps = [
    ":bounded_utf8_length_sequence",
    "//third_party/abseil-cpp/absl/base:config",
  ]
}

absl_source_set("decode_rust_punycode") {
  sources = [ "internal/decode_rust_punycode.cc" ]
  public = [ "internal/decode_rust_punycode.h" ]
  deps = [
    ":bounded_utf8_length_sequence",
    ":utf8_for_code_point",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:nullability",
  ]
}

absl_test("decode_rust_punycode_test") {
  sources = [ "internal/decode_rust_punycode_test.cc" ]
  deps = [
    ":decode_rust_punycode",
    "//third_party/abseil-cpp/absl/base:config",
  ]
}

absl_source_set("demangle_rust") {
  sources = [ "internal/demangle_rust.cc" ]
  public = [ "internal/demangle_rust.h" ]
  deps = [
    ":decode_rust_punycode",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
  ]
}

absl_test("demangle_rust_test") {
  sources = [ "internal/demangle_rust_test.cc" ]
  deps = [
    ":demangle_rust",
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
  ]
}

absl_source_set("utf8_for_code_point") {
  sources = [ "internal/utf8_for_code_point.cc" ]
  public = [ "internal/utf8_for_code_point.h" ]
  deps = [ "//third_party/abseil-cpp/absl/base:config" ]
}

absl_test("utf8_for_code_point_test") {
  sources = [ "internal/utf8_for_code_point_test.cc" ]
  deps = [
    ":utf8_for_code_point",
    "//third_party/abseil-cpp/absl/base:config",
  ]
}

absl_source_set("leak_check") {
  sources = [ "leak_check.cc" ]
  public = [ "leak_check.h" ]
  deps = [
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
  ]
}

absl_source_set("stack_consumption") {
  testonly = true
  sources = [ "internal/stack_consumption.cc" ]
  public = [ "internal/stack_consumption.h" ]
  deps = [
    "//third_party/abseil-cpp/absl/base:config",
    "//third_party/abseil-cpp/absl/base:core_headers",
    "//third_party/abseil-cpp/absl/base:raw_logging_internal",
  ]
  visibility = [ ":*" ]
}
