# Copyright (C) 2022 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_tp_tables.gni")

assert(enable_perfetto_trace_processor_sqlite)

source_set("table_functions") {
  sources = [
    "ancestor.cc",
    "ancestor.h",
    "connected_flow.cc",
    "connected_flow.h",
    "dataframe_query_plan_decoder.cc",
    "dataframe_query_plan_decoder.h",
    "descendant.cc",
    "descendant.h",
    "dfs_weight_bounded.cc",
    "dfs_weight_bounded.h",
    "experimental_annotated_stack.cc",
    "experimental_annotated_stack.h",
    "experimental_flamegraph.cc",
    "experimental_flamegraph.h",
    "experimental_flat_slice.cc",
    "experimental_flat_slice.h",
    "experimental_slice_layout.cc",
    "experimental_slice_layout.h",
    "flamegraph_construction_algorithms.cc",
    "flamegraph_construction_algorithms.h",
    "table_info.cc",
    "table_info.h",
  ]
  if (enable_perfetto_winscope) {
    sources += [
      "winscope_proto_to_args_with_defaults.cc",
      "winscope_proto_to_args_with_defaults.h",
      "winscope_surfaceflinger_hierarchy_paths.cc",
      "winscope_surfaceflinger_hierarchy_paths.h",
    ]
  }
  deps = [
    ":tables",
    "../../../../../gn:default_deps",
    "../../../../../gn:sqlite",
    "../../../../../include/perfetto/trace_processor:basic_types",
    "../../../../../protos/perfetto/trace_processor:metrics_impl_zero",
    "../../../../base",
    "../../../../protozero",
    "../../../containers",
    "../../../dataframe",
    "../../../dataframe",
    "../../../importers/proto:full",
    "../../../importers/proto:minimal",
    "../../../sqlite",
    "../../../storage",
    "../../../tables",
    "../../../types",
    "../../../util:descriptors",
    "../../../util:proto_to_args_parser",
    "../../engine",
  ]
  if (enable_perfetto_winscope) {
    deps += [
      "../../../../../protos/perfetto/trace/android:winscope_regular_zero",
      "../../../importers/proto/winscope:full",
      "../../../util:winscope_proto_mapping",
    ]
  }
  public_deps = [ ":interface" ]
}

source_set("interface") {
  sources = [
    "static_table_function.cc",
    "static_table_function.h",
  ]
  deps = [
    "../../../../../gn:default_deps",
    "../../../../../include/perfetto/trace_processor:basic_types",
    "../../../../base",
    "../../../dataframe",
  ]
}

perfetto_tp_tables("tables") {
  sources = [ "tables.py" ]
  deps = [ "../../../tables:tables_python" ]
}

source_set("unittests") {
  testonly = true
  sources = [
    "ancestor_unittest.cc",
    "connected_flow_unittest.cc",
    "descendant_unittest.cc",
    "experimental_flat_slice_unittest.cc",
    "experimental_slice_layout_unittest.cc",
  ]
  deps = [
    ":table_functions",
    ":tables",
    "../../../../../gn:default_deps",
    "../../../../../gn:gtest_and_gmock",
    "../../../../../gn:sqlite",
    "../../../../base:test_support",
    "../../../containers",
    "../../../dataframe",
    "../../../importers/common",
    "../../../perfetto_sql/engine",
    "../../../sqlite",
    "../../../storage",
    "../../../tables",
    "../../../types",
  ]
}
