# Copyright (C) 2019 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("../../../gn/perfetto.gni")
import("../../../gn/perfetto_cc_proto_descriptor.gni")
import("../../../gn/test.gni")
import("../../../gn/wasm.gni")

# Prevent that this file is accidentally included in embedder builds.
assert(enable_perfetto_trace_processor)
assert(enable_perfetto_trace_processor_sqlite)

# This source_set is used both by WASM (for the function-call-based query
# interface) and by the :httpd module for the HTTP interface.
source_set("rpc") {
  sources = [
    "query_result_serializer.cc",
    "rpc.cc",
    "rpc.h",
  ]
  deps = [
    "..:lib",
    "..:metatrace",
    "../../../gn:default_deps",
    "../../../include/perfetto/trace_processor",
    "../../../protos/perfetto/trace_processor:zero",
    "../../../protos/perfetto/trace_summary:zero",
    "../../base",
    "../../base:version",
    "../../protozero",
    "../../protozero:proto_ring_buffer",
  ]
  public_deps = [
    "../../../include/perfetto/ext/trace_processor/rpc:query_result_serializer",
  ]
}

if (is_perfetto_build_generator || perfetto_build_standalone) {
  # Static library target for RPC code. Needed for BigTrace in Google3.
  # TODO(b/278208757): remove this when we migrate to using rpc_shell.
  static_library("trace_processor_rpc") {
    public_deps = [ ":rpc" ]
  }
}

source_set("stdiod") {
  sources = [
    "stdiod.cc",
    "stdiod.h",
  ]
  deps = [
    ":rpc",
    "..:lib",
    "../../../gn:default_deps",
    "../../base",
  ]
}

perfetto_unittest_source_set("unittests") {
  testonly = true
  sources = [ "query_result_serializer_unittest.cc" ]
  deps = [
    ":rpc",
    "..:lib",
    "../../../gn:default_deps",
    "../../../gn:gtest_and_gmock",
    "../../../protos/perfetto/trace_processor:zero",
    "../../base",
    "../../protozero",
  ]
}

if (enable_perfetto_trace_processor_httpd) {
  source_set("httpd") {
    sources = [
      "httpd.cc",
      "httpd.h",
    ]
    deps = [
      ":rpc",
      "../../../gn:default_deps",
      "../../../include/perfetto/trace_processor",
      "../../../protos/perfetto/trace_processor:zero",
      "../../base",
      "../../base/http",
      "../../protozero",
    ]
  }
}

if (enable_perfetto_ui && is_wasm) {
  source_set("wasm_bridge") {
    sources = [ "wasm_bridge.cc" ]
    deps = [
      ":rpc",
      "../../../gn:default_deps",
      "../../../include/perfetto/trace_processor",
      "../../base",
    ]
  }
}

if (enable_perfetto_benchmarks) {
  source_set("benchmarks") {
    testonly = true
    deps = [
      ":rpc",
      "..:lib",
      "../../../gn:benchmark",
      "../../../gn:default_deps",
      "../../../gn:sqlite",
      "../../base",
    ]
    sources = [ "query_result_serializer_benchmark.cc" ]
  }
}
