# Copyright 2015 The Chromium 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("//chromecast/chromecast.gni")
import("//testing/test.gni")
import("//tools/grit/grit_rule.gni")

cast_source_set("app") {
  sources = [
    "cast_main_delegate.cc",
    "cast_main_delegate.h",
  ]

  deps = [
    ":cast_crash_client",
    "//base",
    "//chromecast/base",
    "//chromecast/browser",
    "//chromecast/common",
    "//chromecast/renderer",
    "//chromecast/utility",
    "//components/crash/core/common:crash_key",
    "//content/public/app:both",
    "//content/public/browser",
    "//content/public/common",
    "//ui/base",
  ]

  if (!is_fuchsia) {
    # TODO(crbug.com/753619): Enable crash reporting on Fuchsia.
    deps += [ "//components/crash/content/app" ]
  }
}

cast_source_set("cast_crash_client") {
  sources = [
    "android/cast_crash_reporter_client_android.cc",
    "android/cast_crash_reporter_client_android.h",
    "android/crash_handler.cc",
    "android/crash_handler.h",
    "linux/cast_crash_reporter_client.cc",
    "linux/cast_crash_reporter_client.h",
  ]

  deps = [
    "//base",
    "//chromecast/base",
    "//chromecast/common",
    "//content/public/common",
  ]

  if (!is_fuchsia) {
    # TODO(crbug.com/753619): Enable crash reporting on Fuchsia.
    deps += [
      "//chromecast/crash",
      "//components/crash/content/app",
    ]
  }

  if (is_android) {
    deps += [
      "//chromecast/base:cast_version",
      "//chromecast/browser:jni_headers",
      "//third_party/breakpad:client",
    ]
  }
}

cast_source_set("test_support") {
  testonly = true
  sources = [
    "cast_test_launcher.cc",
  ]

  deps = [
    ":app",
    "//base",
    "//base/test:test_support",
    "//chromecast/base",
    "//content/test:test_support",
    "//ipc",
    "//mojo/edk/embedder:headers",
  ]
}

cast_source_set("unittests") {
  testonly = true
  sources = [
    "linux/cast_crash_reporter_client_unittest.cc",
  ]

  deps = [
    "//base",
    "//base/test:test_support",
    "//chromecast/base:test_support",
    "//testing/gtest",
  ]

  if (!is_fuchsia) {
    deps += [
      # TODO(crbug.com/753619): Enable crash reporting on Fuchsia.
      ":cast_crash_client",
      "//chromecast/crash",
      "//chromecast/crash:test_support",
    ]
  }
}

grit("resources") {
  source = "//chromecast/app/resources/shell_resources.grd"

  resource_ids = "//chromecast/app/resources/resource_ids"

  outputs = [
    "grit/shell_resources.h",
    "shell_resources.pak",
  ]
}

grit("chromecast_settings") {
  source = "//chromecast/app/resources/chromecast_settings.grd"
  resource_ids = "//chromecast/app/resources/resource_ids"

  outputs = [
    "grit/chromecast_settings.h",
  ]
  foreach(locale, cast_locales) {
    outputs += [ "chromecast_settings_${locale}.pak" ]
  }

  deps = [
    ":verify_cast_locales",
  ]
}

# This target ensures that Chromecast developers are notified when locales
# change. If this target is breaking the build, the CAST_LOCALES list in
# //chromecast/app/verify_cast_locales.py must be updated to match
# |cast_locales|. Please see that file for more details. This action will be
# run on fresh builds, and whenever |cast_locales| is updated.
action("verify_cast_locales") {
  script = "//chromecast/app/verify_cast_locales.py"

  # This file will be stamped on success, preventing an unnecessary rebuild.
  stamp_file = "$target_gen_dir/cast_locales_verified"
  args = [
    "-s",
    rebase_path(stamp_file, "$root_out_dir"),
  ]

  args += cast_locales

  outputs = [
    stamp_file,
  ]
}