# Copyright 2013 The Flutter Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//flutter/impeller/tools/impeller.gni")
import("//flutter/shell/version/version.gni")
import("//third_party/flatbuffers/flatbuffers.gni")

config("runtime_stage_config") {
  configs = [ "//flutter/impeller:impeller_public_config" ]
  include_dirs = [ "$root_gen_dir/flutter" ]
}

flatbuffers("importer_flatbuffers") {
  flatbuffers = [ "scene.fbs" ]
  public_configs = [ ":runtime_stage_config" ]
  public_deps = [ "//third_party/flatbuffers" ]
}

impeller_component("conversions") {
  sources = [
    "conversions.cc",
    "conversions.h",
  ]

  public_deps = [
    ":importer_flatbuffers",
    "../../base",
    "../../geometry",
    "//flutter/fml",
  ]
}

impeller_component("importer_lib") {
  # Current versions of libcxx have deprecated some of the UTF-16 string
  # conversion APIs.
  defines = [ "_LIBCPP_DISABLE_DEPRECATION_WARNINGS" ]

  sources = [
    "importer.h",
    "importer_gltf.cc",
    "switches.cc",
    "switches.h",
    "types.h",
    "vertices_builder.cc",
    "vertices_builder.h",
  ]

  public_deps = [
    ":conversions",
    ":importer_flatbuffers",
    "../../base",
    "../../compiler:utilities",
    "../../geometry",
    "//flutter/fml",

    # All third_party deps must be reflected below in the scenec_license
    # target.
    "//third_party/tinygltf",
  ]
}

generated_file("scenec_license") {
  source_path = rebase_path(".", "//flutter")
  git_url = "https://github.com/flutter/engine/tree/$engine_version"
  outputs = [ "$target_gen_dir/LICENSE.scenec.md" ]
  contents = [
    "# scenec",
    "",
    "This tool is used by the Flutter SDK to import 3D geometry.",
    "",
    "Source code for this tool: [flutter/engine/$source_path]($git_url/$source_path).",
    "",
    "## Licenses",
    "",
    "### scenec",
    "",
    read_file("//flutter/sky/packages/sky_engine/LICENSE", "string"),
    "",

    # These licenses are ignored by the main license checker, since they are not
    # shipped to end-application binaries and only shipped as part of developer
    # tooling in scenec. Add them here.
    "## Additional open source licenses",
    "",
    "### tinygltf",
    "",
    read_file("//third_party/tinygltf/LICENSE", "string"),
  ]
}

group("importer") {
  deps = [
    ":scenec",
    ":scenec_license",
  ]
}

impeller_component("scenec") {
  target_type = "executable"

  sources = [ "scenec_main.cc" ]

  deps = [ ":importer_lib" ]

  metadata = {
    entitlement_file_path = [ "scenec" ]
  }
}

impeller_component("importer_unittests") {
  testonly = true

  output_name = "scenec_unittests"

  sources = [ "importer_unittests.cc" ]

  deps = [
    ":importer_lib",
    "../../fixtures",
    "../../geometry:geometry_asserts",
    "//flutter/testing:testing_lib",
  ]
}
