# Copyright (C) 2017 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/fuzzer.gni")
import("../../gn/ipc_library.gni")
import("../../gn/proto_library.gni")

# For use_libfuzzer.
if (perfetto_build_standalone || perfetto_build_with_android) {
  import("//gn/standalone/sanitizers/vars.gni")
} else {
  import("//build/config/sanitizers/sanitizers.gni")
}

# This build file should not be leaked into all embedders. Only select
# projects should be depending on our IPC layer.
assert(perfetto_build_with_ipc_layer)

source_set("ipc") {
  public_configs = [ "../../gn:default_config" ]
  public_deps = [
    "../../include/perfetto/ipc",
    "../base:unix_socket",
  ]
  deps = [
    ":wire_protocol",
    "../../gn:default_deps",
    "../base",
  ]
  sources = [
    "buffered_frame_deserializer.cc",
    "client_impl.cc",
    "deferred.cc",
    "host_impl.cc",
    "host_impl.h",
    "service_proxy.cc",
    "virtual_destructors.cc",
  ]
}

perfetto_fuzzer_test("buffered_frame_deserializer_fuzzer") {
  sources = [
    "buffered_frame_deserializer_fuzzer.cc",
  ]
  deps = [
    ":ipc",
    ":wire_protocol",
    "../../gn:default_deps",
  ]
}

source_set("unittests") {
  testonly = true
  deps = [
    ":ipc",
    ":test_messages",
    ":wire_protocol",
    "../../gn:default_deps",
    "../../gn:gtest_deps",
    "../base",
    "../base:test_support",
  ]
  sources = [
    "buffered_frame_deserializer_unittest.cc",
    "client_impl_unittest.cc",
    "deferred_unittest.cc",
    "host_impl_unittest.cc",
    "test/ipc_integrationtest.cc",
  ]
}

proto_library("wire_protocol") {
  generate_python = false
  sources = [
    "wire_protocol.proto",
  ]
  proto_in_dir = perfetto_root_path
  proto_out_dir = perfetto_root_path
}

ipc_library("test_messages") {
  sources = [
    "test/client_unittest_messages.proto",
    "test/deferred_unittest_messages.proto",
    "test/greeter_service.proto",
  ]
  proto_in_dir = perfetto_root_path
  proto_out_dir = perfetto_root_path
}