chromium/tools/memory/partition_allocator/BUILD.gn

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

import("//base/allocator/partition_allocator/partition_alloc.gni")

# Only support x86_64 Linux as the system calls used are Linux-specific. No
# point in building this if PartitionAlloc is not the allocator used.
_tcache_tool_supported = ((target_cpu == "x64" && is_linux) || is_mac) &&
                         use_partition_alloc_as_malloc

if (_tcache_tool_supported) {
  source_set("pa_tool_utils") {
    sources = [
      "inspect_utils.cc",
      "inspect_utils.h",
    ]

    if (is_linux) {
      sources += [ "inspect_utils_linux.cc" ]
    } else if (is_mac) {
      sources += [ "inspect_utils_mac.cc" ]
    }

    deps = [ "//base" ]
  }
  executable("pa_tcache_inspect") {
    sources = [ "pa_tcache_inspect.cc" ]
    deps = [
      ":pa_tool_utils",
      "//base",
    ]

    if (target_os == "mac") {
      inputs = [ "sectaskaccess_info.plist" ]
      ldflags = [
        "-sectcreate",
        "__TEXT",
        "__info_plist",
        rebase_path(inputs[0], root_build_dir),
      ]
    }
  }
  executable("pa_buckets_inspect") {
    sources = [ "pa_buckets_inspect.cc" ]
    deps = [
      ":pa_tool_utils",
      "//base",
    ]
  }
  executable("pa_dump_heap") {
    sources = [ "pa_dump_heap.cc" ]
    deps = [
      ":pa_tool_utils",
      "//base",
      "//third_party/snappy:snappy",
    ]

    if (target_os == "mac") {
      inputs = [ "sectaskaccess_info.plist" ]
      ldflags = [
        "-sectcreate",
        "__TEXT",
        "__info_plist",
        rebase_path(inputs[0], root_build_dir),
      ]
    }
  }
}

group("all") {
  if (_tcache_tool_supported) {
    deps = [
      ":pa_buckets_inspect",
      ":pa_tcache_inspect",
    ]
  }
}