chromium/chromecast/BUILD.gn

# Copyright 2015 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//build/buildflag_header.gni")
import("//build/config/cronet/config.gni")
import("//build/config/features.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//build/config/ui.gni")
import("//chromecast/build/tests/cast_test.gni")
import("//chromecast/chromecast.gni")
import("//chromecast/resource_sizes/chromecast_resource_sizes.gni")
import("//media/media_options.gni")
import("//tools/grit/repack.gni")
import("//v8/gni/v8.gni")

if (chromecast_branding != "public") {
  import("//chromecast/internal/chromecast_internal.gni")
}

if (is_android) {
  import("//build/config/android/rules.gni")
  import("//components/module_installer/android/module_desc_java.gni")
}

declare_args() {
  cast_test_extra_flags = ""
  vendor_cast_media_gtest_excludes = []
}

assert(!is_cronet_build)

# Depends on all non-test targets that should be built by the Chromecast
# internal build infrastructure.
group("all") {
  data_deps = []
  deps = [ "//chromecast/build:archive" ]
  if (is_android) {
    if (chromecast_branding == "public") {
      deps += [ ":cast_shell_apk" ]
    } else {
      foreach(device_type, android_device_types) {
        deps += [ ":cast_browser_${device_type}_bundle_module" ]
      }
    }
  } else if (!is_fuchsia) {
    data_deps += [
      ":cast_browser",
      ":cast_shell",
    ]
  }
  if (is_linux) {
    deps += [ "//chromecast/tracing" ]
  }
  if (chromecast_branding != "public") {
    deps += [ "//chromecast/internal:all" ]
  }
  if (enable_external_mojo_services) {
    deps += [ "//chromecast/external_mojo/external_service_support:standalone_mojo_broker" ]
  }

  # No other targets should depend on this target, since it's just a convenience
  # target for the Chromecast internal build infrastructure.
  visibility = []
  testonly = true
}

# This is a config which is applied on all cast_* targets (which should be all
# code under chromecast/).
config("cast_config") {
  cflags = [ "-Wshadow" ]
}

config("iot_service") {
  if (iot_service_rpath != "") {
    ldflags = [ "-Wl,-rpath=${iot_service_rpath}" ]
  }
}

if (!is_fuchsia) {
  chromecast_resource_sizes_test("resource_sizes_chromecast") {
    data_deps = [
      ":cast_shell",
      ":cast_shell_pak",
      ":chromecast_locales_pak",
    ]
  }
}

# A list of all public test() binaries. This is an organizational target that
# cannot be depended upon or built directly. Build cast_test_lists instead.
cast_test_group("cast_tests") {
  filters = []
  tests = [
    "//base:base_unittests",
    "//cc:cc_unittests",
    "//chromecast/base:cast_base_unittests",
    "//chromecast/base/component:cast_component_unittests",
    "//chromecast/common:cast_common_unittests",
    "//chromecast/crypto:cast_crypto_unittests",
    "//chromecast/device/bluetooth:cast_bluetooth_unittests",
    "//chromecast/metrics:cast_metrics_unittest",
    "//chromecast/net:cast_net_unittests",
    "//chromecast/shared:cast_shared_unittests",
    "//chromecast/system/reboot:cast_reboot_unittests",
    "//components/viz:viz_unittests",
    "//crypto:crypto_unittests",
    "//media:media_unittests",
    "//media/midi:midi_unittests",
    "//net:net_unittests",
    "//sql:sql_unittests",
    "//storage:storage_unittests",
    "//ui/base:ui_base_unittests",
  ]

  if (!is_fuchsia) {
    tests += [
      "//chromecast/ui/display_settings:cast_display_settings_unittests",
      "//content/test:content_unittests",
    ]
  }

  if (!is_cast_audio_only) {
    tests += [ "//gpu:gpu_unittests" ]

    if (use_aura && !is_fuchsia) {
      tests += [ "//chromecast/graphics:cast_graphics_unittests" ]
    }
  }

  if (use_v4l2_codec) {
    tests += [ "//media/gpu:video_decode_accelerator_tests" ]
  }

  if (is_linux) {
    tests += [
      "//chromecast/crash:cast_crash_unittests",
      "//sandbox/linux:sandbox_linux_unittests",
    ]

    sandbox_linux_unittests_filter = {
      test_name = "sandbox_linux_unittests"

      # TODO(b/148974697): re-enable this.
      gtest_excludes = [ "BaselinePolicy.SystemEperm" ]
    }
    filters += [ sandbox_linux_unittests_filter ]
  }

  # TODO(crbug.com/40835751): `media_use_ffmpeg` should not largely affect top-level
  # test list. Better create another flag to do this or handle the ffmpeg flag
  # in //chromecast/media/cma/decoder.
  if (media_use_ffmpeg && !is_fuchsia) {
    tests += [
      "//chromecast/cast_core:cast_cast_core_unittests",
      "//chromecast/media:cast_media_unittests",
    ]

    cast_media_unittests_filter = {
      test_name = "cast_media_unittests"

      gtest_excludes = vendor_cast_media_gtest_excludes

      # --test-launcher-jobs=1 => so internal code can bind to port
      args = [ "--test-launcher-jobs=1" ]
    }
    filters += [ cast_media_unittests_filter ]
  }

  if (is_linux) {
    tests += [ "//chromecast/media/cma/backend:cast_audio_backend_unittests" ]
    cast_audio_backend_unittests_filter = {
      test_name = "cast_audio_backend_unittests"

      # --test-launcher-jobs=1 => so mixer service receiver can bind.
      args = [
        "--test-launcher-jobs=1",
        "--mixer-service-endpoint=/tmp/cast_audio_backend_unittest-mixer",
        "--mixer-service-port=12855",
      ]
    }
    filters += [ cast_audio_backend_unittests_filter ]
  }

  if (is_android) {
    tests += [ "//chromecast/media/cma/backend/android:cast_android_cma_backend_unittests" ]
  }

  if (!is_android && !is_fuchsia) {
    tests += [
      "//ipc:ipc_tests",
      "//url:url_unittests",
    ]

    if (media_use_ffmpeg) {
      tests += [
        ":cast_shell_browsertests",
        ":cast_shell_unittests",
      ]

      cast_shell_browsertests_filter = {
        test_name = "cast_shell_browsertests"

        # --enable-local-file-accesses => to load sample media files
        # --test-launcher-jobs=1 => so internal code can bind to port
        args = [
          "--no-sandbox",
          "--enable-local-file-accesses",
          "--test-launcher-jobs=1",
          "--enable-hardware-overlays=",
        ]

        gtest_excludes = []

        # TODO(b/112440248): This test was failing:
        #   * On v1 and Cast Audio devices since 2017-03-15.
        #   * On desktop builds since 2018-08-22
        # Also see: b/36238710, b/36239051, hotlist/461351
        gtest_excludes += [ "RendererPrelauncherTest.ReusedRenderer" ]

        if (!is_cast_desktop_build) {
          args += [ "--use-gpu-in-tests" ]

          # TODO(derekjchow): Make these tests pass on Chromecast devices.
          #    Once all of the CastMediaBlockerTest.* have been un-DISABLEd and
          #    are running successfully, revisit these tests and see if they pass
          #    on devices. (crbug/665118, internal b/32023194)
          gtest_excludes += [
            "CastMediaBlockerBrowserTest.Video_BlockUnblock",
            "CastMediaBlockerBrowserTest.Audio_BlockUnblock",

            # This browser test can only be run inside of a source checkout.
            "CastWebContentsBrowserTest.*",
          ]
        }

        if (!is_cast_desktop_build && !is_cast_audio_only &&
            !enable_assistant) {
          # TODO(mbjorge): The VideoPlaybackMp4 test is failing on v1 devices.
          # Temporarily disable it as part of an effort to re-green the unittests.
          # Re-enable once the tests have been fixed. Limitations in the filter
          # system mean this is getting temporarily disabled on all video devices,
          # though it is only failing on v1.
          # b/36723698, hotlist/461351
          gtest_excludes += [ "CastNavigationBrowserTest.VideoPlaybackMp4" ]
        }

        # TODO(mbjorge): Temporarily disable AudioPlaybackWavPcm because it is
        # failing on device. As part of an effort to re-green the unittests,
        # current (2017-03-15) failures are being disabled to get back to a
        # green state. Re-enable once the tests have been fixed.
        # b/36239152, hotlist/461351
        if (enable_assistant && !is_cast_desktop_build) {
          gtest_excludes += [ "CastNavigationBrowserTest.AudioPlaybackWavPcm" ]
        }
      }
      filters += [ cast_shell_browsertests_filter ]
    }

    ipc_tests_filter = {
      test_name = "ipc_tests"

      # --test-launcher-jobs=1 => so internal code can bind to port
      args = [ "--test-launcher-jobs=1" ]
    }
    filters += [ ipc_tests_filter ]

    url_unittests_filter = {
      test_name = "url_unittests"

      if (target_os == "linux" && !is_cast_desktop_build) {
        # DoAppendUTF8Invalid fails because of dcheck_always_on flag in Eng builds
        gtest_excludes = [ "URLCanonTest.DoAppendUTF8Invalid" ]
      }
    }
    filters += [ url_unittests_filter ]
  }

  base_unittests_filter = {
    test_name = "base_unittests"
    gtest_excludes = []
    if (target_os == "linux") {
      if (is_cast_desktop_build) {
        # Disable PartitionAllocDeathTest.* (b/67975693)
        gtest_excludes += [ "PartitionAllocDeathTest.*" ]
      } else {
        # Disable ProcessMetricsTest.GetNumberOfThreads (b/15610509)
        # Disable ProcessUtilTest.* (need to define OS_ANDROID)
        # Disable SystemMetrics2Test.GetSystemMemoryInfo (buffers>0 can't be guaranteed)
        # Disable PostTasksViaTaskRunner/* to green up devices (b/62246873)
        # Disable WorkerDetaches to green up devices (b/62246873)
        gtest_excludes += [
          "ProcessMetricsTest.GetNumberOfThreads",
          "ProcessUtilTest.*",
          "SystemMetrics2Test.GetSystemMemoryInfo",
          "OneTraitsExecutionModePair/ThreadPoolImplTest.PostTasksViaTaskRunner/*",
          "TaskSchedulerWorkerTest.WorkerDetaches",
        ]
      }

      if (is_cast_audio_only) {
        # Also disable TimeFormattingTest on audio-only builds, since we don't
        # include the necessary info in icudtl.dat.
        gtest_excludes += [ "TimeFormattingTest.*" ]
      }
    }
  }
  filters += [ base_unittests_filter ]

  cc_unittests_filter = {
    test_name = "cc_unittests"

    # Temporarily disable all test cases (b/113324890)
    gtest_excludes = [ "*" ]

    if (!is_cast_desktop_build) {
      #Disable ToColorSpace/ColorTransformPixelTest*  (b/64346790)
      #Disable ImageBackgroundFilter* (b/64346875)
      #Disable LayerTreeHostTilesTestPartialInvalidation* (b/65844132)
      gtest_excludes += [
        "ToColorSpace/ColorTransformPixelTest.*",
        "ImageBackgroundFilter.*",
        "LayerTreeHostTilesTestPartialInvalidation.*",
      ]
    }
  }
  filters += [ cc_unittests_filter ]

  viz_unittests_filter = {
    test_name = "viz_unittests"

    # TODO(crbug.com/1338342): Make these tests pass.
    gtest_excludes = [
      "PromotedTrueFalse/MultiUnderlayPromotedTest.UnderlaysBlendPrimaryPlane/0",
      "UnderlayCastTest.BlackOutsideOverlayContentBounds",
      "UnderlayCastTest.FullScreenOverlayContentBounds",
      "UnderlayCastTest.OverlayOccludedContentBounds",
      "UnderlayCastTest.OverlayOccludedUnionContentBounds",
      "UnderlayCastTest.OverlayPromotionWithMaskFilter",
      "UnderlayCastTest.ReplacementQuad",
      "UnderlayCastTest.RoundContentBounds",
      "UnderlayCastTest.RoundOverlayContentBounds",
    ]
  }
  filters += [ viz_unittests_filter ]

  # content_unittests are not run on Fuchsia.
  if (!is_fuchsia) {
    content_unittests_filter = {
      test_name = "content_unittests"

      # IsSupportedVideoConfig_VP9TransferFunctions fails on all cast builds since
      # the cast IsSupportedVideoConfigs ignore the transfer function parameter.
      # (b/36984215).
      gtest_excludes = [ "*.IsSupportedVideoConfig_VP9TransferFunctions" ]
      if (target_os == "linux" && !is_cast_desktop_build) {
        # DesktopCaptureDeviceTest.*: No capture device on Eureka
        # Disable PepperGamepadHostTest.WaitForReply (pepper not supported on Eureka)
        # Disable RenderWidgetHostTest.Background because we disable the
        # blacklist to enable WebGL (b/16142554)
        gtest_excludes += [
          "LegacyDomStorageDatabaseTest.TestCanOpenAndReadWebCoreDatabase",
          "DesktopCaptureDeviceTest.Capture",
          "GamepadProviderTest.PollingAccess",
          "PepperGamepadHostTest.WaitForReply",
          "RenderWidgetHostTest.Background",
        ]
      }
      if (is_cast_audio_only) {
        # No way to display URL's on audio only cast devices.
        gtest_excludes += [ "NavigationEntryTest.NavigationEntryURLs" ]
      }
      if (enable_assistant && !is_cast_desktop_build) {
        # Temporarily disable DefaultConstructor on assistant device builds. Cause
        # of failure is unclear, but it's highly likely it's related to them being
        # DEATH tests. These were passing until the is_official_build flag was
        # enabled. These tests are considered non-critical in this context.
        # (b/62469368)
        gtest_excludes += [ "WebBluetoothDeviceIdTest.DefaultConstructor" ]
      }
    }
    filters += [ content_unittests_filter ]
  }

  media_unittests_filter = {
    test_name = "media_unittests"
    if (target_os == "linux" && !is_cast_desktop_build) {
      # Disable VP9 related tests (b/18593324)
      #   PipelineIntegrationTest.BasicPlayback_MediaSource_VP9_WebM
      #   PipelineIntegrationTest.BasicPlayback_VideoOnly_VP9_WebM
      #   PipelineIntegrationTest.BasicPlayback_VP9*
      #   PipelineIntegrationTest.P444_VP9_WebM
      # Disable VP8A tests (b/18593324)
      #   PipelineIntegrationTest.BasicPlayback_VP8A*
      # Disable OpusAudioDecoderTest/AudioDecoderTest.ProduceAudioSamples/0 (unit
      # test fails when Opus decoder uses fixed-point)
      # Due to b/16456550, disable the following four test cases:
      #   AudioOutputControllerTest.PlayDivertSwitchDeviceRevertClose
      #   AudioOutputControllerTest.PlaySwitchDeviceClose
      #   AudioStreamHandlerTest.Play
      #   SoundsManagerTest.Play
      # Disable AudioStreamHandlerTest.ConsecutivePlayRequests (b/16539293)
      gtest_excludes = [
        "AudioOutputControllerTest.PlayDivertSwitchDeviceRevertClose",
        "AudioOutputControllerTest.PlaySwitchDeviceClose",
        "AudioStreamHandlerTest.Play",
        "AudioStreamHandlerTest.ConsecutivePlayRequests",
        "PipelineIntegrationTest.BasicPlayback_MediaSource_VP9_WebM",
        "PipelineIntegrationTest.BasicPlayback_VideoOnly_VP9_WebM",
        "PipelineIntegrationTest.BasicPlayback_VP9*",
        "PipelineIntegrationTest.P444_VP9_WebM",
        "PipelineIntegrationTest.BasicPlayback_VP8A*",
        "OpusAudioDecoderTest/AudioDecoderTest.ProduceAudioSamples/0",
        "SoundsManagerTest.Play",
      ]
    } else if (target_os == "android" || is_cast_desktop_build) {
      # Disable PipelineIntegrationTest.BasicPlayback_MediaSource_VP9_WebM (not supported)
      gtest_excludes =
          [ "PipelineIntegrationTest.BasicPlayback_MediaSource_VP9_WebM" ]
    }
  }
  filters += [ media_unittests_filter ]

  net_unittests_filter = {
    test_name = "net_unittests"
    if (using_sanitizer) {
      # TODO(mbjorge): net_unittests do not complete when run with sanitizers,
      # (in particular, TSAN and UBSAN), resulting in build machines getting stuck
      # for many hours. Disable them for now, since these are getting run on
      # Chromium bots anyway. (internal b/31279943)
      gtest_excludes = [ "*" ]
    } else if (target_os == "linux" && !is_cast_desktop_build) {
      # Run net_unittests first to avoid random failures due to slow python startup
      # PacFileFetcherImplTest.HttpMimeType is flaking (b/19848784)
      # Running a batch of net_unittests has high overhead. Run tests in batches of 50 to reduce number of batches (b/23156294).
      gtest_excludes = [ "PacFileFetcherImplTest.HttpMimeType" ]
      args = [ "--test-launcher-batch-limit=50" ]
    } else if (is_cast_desktop_build || target_os == "android") {
      # CTLogVerifierTest.VerifiesValidConsistencyProofsFromReferenceGenerator
      # times out occasionally, paricularly on the CQ bots; disable to reduce
      # CQ flakiness (crbug/598406) (b/29415636).
      # Running a batch of net_unittests has high overhead, so
      # run tests in batches of 25 to reduce number of batches (b/23156294).
      gtest_excludes = [ "CTLogVerifierTest.VerifiesValidConsistencyProofsFromReferenceGenerator" ]
      args = [ "--test-launcher-batch-limit=25" ]
    }
  }
  filters += [ net_unittests_filter ]
}

# Creates the build and run lists for all test targets.
cast_test_group_list("cast_test_lists") {
  build_list_path = "$root_out_dir/tests/build_test_list.txt"
  runtime_deps_path = "$root_out_dir/tests/runtime_deps.json"
  run_list_path = "$root_out_dir/tests/run_test_list.txt"

  additional_options = [
    "--ozone-platform=headless --test-launcher-bot-mode $cast_test_extra_flags",
  ]

  test_groups = [ ":cast_tests" ]

  if (chromecast_branding != "public") {
    test_groups += internal_cast_test_groups
  }
}

if (is_android) {
  cast_test_group("cast_junit_tests") {
    test_type = "junit"
    tests = [
      "//base:base_junit_tests",
      "//chromecast/base:cast_base_junit_tests",
      "//chromecast/browser/android:cast_shell_junit_tests",
      "//content/public/android:content_junit_tests",
      "//net/android:net_junit_tests",
      "//testing/android/junit:junit_unit_tests",
      "//ui:ui_junit_tests",
    ]
  }

  cast_test_group_list("cast_junit_test_lists") {
    test_type = "junit"
    build_list_path = "$root_out_dir/junit/build_junit_test_list.txt"
    runtime_deps_path = "$root_out_dir/junit/runtime_deps.json"
    run_list_path = "$root_out_dir/junit/run_junit_test_list.txt"
    test_groups = [ ":cast_junit_tests" ]
    if (chromecast_branding != "public") {
      test_groups += [ "//chromecast/internal:internal_cast_junit_tests" ]
    }
  }
}

if (!is_fuchsia) {
  test("cast_shell_unittests") {
    deps = [
      ":cast_shell_lib",
      "//chromecast/app:test_support",
      "//chromecast/app:unittests",
      "//chromecast/browser:unittests",
      "//ui/gl:test_support",
    ]
  }

  test("cast_shell_browsertests") {
    deps = [
      # These browser tests always use the simple implementation, since we only
      # need to test web content primitives and not all of Cast receiver.
      ":cast_shell_lib_simple",
      "//chromecast/app:test_support",
      "//chromecast/bindings:browsertests",
      "//chromecast/browser:browsertests",
    ]

    data_deps = [ ":chromecast_locales_pak" ]
  }

  group("cast_shell_lib") {
    if (chromecast_branding != "public") {
      deps = [
        ":cast_shell_lib_base",
        "//chromecast/internal/shell",
      ]
    } else {
      deps = [ ":cast_shell_lib_simple" ]
    }
  }

  group("cast_shell_lib_base") {
    data_deps = [ ":cast_shell_pak" ]

    deps = [
      "//chromecast/app",
      "//chromecast/base:default_create_sys_info",
      "//chromecast/browser",
      "//chromecast/common",
      "//chromecast/renderer",
    ]
  }

  group("cast_shell_lib_simple") {
    deps = [
      ":cast_shell_lib_base",
      "//chromecast/browser:prefs_simple",
      "//chromecast/browser:simple_client",
      "//chromecast/browser:simple_main_parts",
      "//chromecast/renderer:simple_client",
    ]
  }

  cast_executable("cast_shell") {
    sources = [ "app/cast_main.cc" ]

    deps = [
      ":cast_shell_lib",
      ":chromecast_locales_pak",
      "//chromecast/app",
      "//content/public/app",
      "//third_party/widevine/cdm",
    ]
  }

  cast_executable("cast_browser") {
    sources = [ "app/cast_main.cc" ]

    deps = [
      ":cast_shell_lib_simple",
      ":chromecast_locales_pak",
      "//chromecast/app",
      "//content/public/app",
      "//third_party/widevine/cdm",
    ]
  }

  repack("cast_shell_pak") {
    sources = [
      "$root_gen_dir/chromecast/app/shell_resources.pak",
      "$root_gen_dir/components/cast/named_message_port_connector/named_message_port_connector_resources.pak",
      "$root_gen_dir/content/content_resources.pak",
      "$root_gen_dir/content/gpu_resources.pak",
      "$root_gen_dir/mojo/public/js/mojo_bindings_resources.pak",
      "$root_gen_dir/net/net_resources.pak",
      "$root_gen_dir/third_party/blink/public/resources/blink_resources.pak",
      "$root_gen_dir/third_party/blink/public/resources/blink_scaled_resources_100_percent.pak",
      "$root_gen_dir/third_party/blink/public/strings/blink_strings_en-US.pak",
      "$root_gen_dir/ui/resources/ui_resources_100_percent.pak",
      "$root_gen_dir/ui/resources/webui_resources.pak",
      "$root_gen_dir/ui/strings/app_locale_settings_en-US.pak",
      "$root_gen_dir/ui/strings/ax_strings_en-US.pak",
      "$root_gen_dir/ui/strings/ui_strings_en-US.pak",
    ]

    output = "$root_out_dir/assets/cast_shell.pak"

    deps = [
      "//chromecast/app:resources",
      "//components/cast/named_message_port_connector:resources",
      "//content:content_resources",
      "//content/browser/resources/gpu:resources",
      "//mojo/public/js:resources",
      "//net:net_resources",
      "//third_party/blink/public:resources",
      "//third_party/blink/public:scaled_resources_100_percent",
      "//third_party/blink/public/strings",
      "//ui/resources",
      "//ui/strings",
    ]
  }

  # Intermediate targets that repack grit resources by locale. For each locale
  # in |cast_locales| (see //chromecast/chromecast.gni), all resources
  # are packed into a single .pak file in an output directory. These targets
  # should not be depended on directly; depend on ":chromecast_locales_pak"
  # instead.
  foreach(locale, cast_locales) {
    repack("_cast_repack_${locale}") {
      visibility = [ ":chromecast_locales_pak" ]
      output = "$root_out_dir/chromecast_locales/${locale}.pak"
      mark_as_data = true
      sources =
          [ "$root_gen_dir/chromecast/app/chromecast_settings_${locale}.pak" ]
      deps = [ "//chromecast/app:chromecast_settings" ]

      if (chromecast_branding != "public") {
        sources += [
          "$root_gen_dir/chromecast/internal/castui/app_strings_${locale}.pak",
        ]
        deps += [ "//chromecast/internal/castui:cast_ui_app_strings" ]
      }
    }
  }

  # A meta-target which repacks resources by locale.
  group("chromecast_locales_pak") {
    public_deps = []
    foreach(locale, cast_locales) {
      public_deps += [ ":_cast_repack_${locale}" ]
    }
  }
}  # !is_fuchsia

buildflag_header("chromecast_buildflags") {
  header = "chromecast_buildflags.h"
  _command_line_flags = string_join(",", default_command_line_flags)
  flags = [
    "DEFAULT_COMMAND_LINE_FLAGS=\"$_command_line_flags\"",
    "DISABLE_SECURE_FLAC_OPUS_DECODING=$disable_secure_flac_and_opus_decoding",
    "ENABLE_ASSISTANT=$enable_assistant",
    "ENABLE_EXTERNAL_MOJO_SERVICES=$enable_external_mojo_services",
    "ENABLE_PLAYREADY=$enable_playready",
    "ENABLE_VIDEO_CAPTURE_SERVICE=$enable_video_capture_service",
    "IS_CAST_AUDIO_ONLY=$is_cast_audio_only",
    "IS_CAST_DESKTOP_BUILD=$is_cast_desktop_build",
    "USE_ANDROID_USER_AGENT=$use_android_user_agent",
    "USE_CHROMECAST_CDMS=$use_chromecast_cdms",
    "ENABLE_CHROMIUM_RUNTIME_CAST_RENDERER=$enable_chromium_runtime_cast_renderer",
  ]
}

if (is_android) {
  android_assets("cast_shell_apk_assets") {
    sources = [ "$root_out_dir/assets/cast_shell.pak" ]

    deps = [
      ":cast_shell_apk_locale_assets",
      ":cast_shell_pak",
      "//gin:v8_snapshot_assets",
      "//third_party/icu:icu_assets",
    ]
    disable_compression = true
  }

  android_assets("cast_shell_apk_locale_assets") {
    renaming_sources = []
    renaming_destinations = []

    foreach(locale, cast_locales) {
      renaming_sources += [ "$root_out_dir/chromecast_locales/${locale}.pak" ]
      renaming_destinations += [ "stored-locales/${locale}.pak" ]
    }

    deps = [ ":chromecast_locales_pak" ]

    treat_as_locale_paks = true
    disable_compression = true
  }

  android_apk("cast_shell_apk") {
    enable_lint = true
    lint_baseline_file = "android/lint-baseline.xml"
    lint_suppressions_file = "android/lint-suppressions.xml"

    apk_name = "CastShell"
    android_manifest = "$root_gen_dir/cast_shell_manifest/AndroidManifest.xml"
    android_manifest_dep = "//chromecast/browser/android:cast_shell_manifest"

    min_sdk_version = 24
    target_sdk_version = 33

    shared_libraries = [ "//chromecast/android:libcast_shell_android" ]
    srcjar_deps =
        [ "//chromecast/android:libcast_shell_android__jni_registration" ]

    deps = [
      ":cast_shell_apk_assets",
      "//base:base_java",
      "//build/android:build_java",
      "//chromecast/android:libcast_shell_android",
      "//chromecast/browser/android:cast_shell_java",
      "//components/crash/core/app:chrome_crashpad_handler_named_as_so",
      "//third_party/jni_zero:jni_zero_java",
    ]

    loadable_modules = [ "$root_out_dir/libchrome_crashpad_handler.so" ]

    command_line_flags_file = "castshell-command-line"

    product_config_java_packages = [ "org.chromium.chromecast.shell" ]
  }

  if (chromecast_branding != "public") {
    foreach(device_type, android_device_types) {
      android_app_bundle_module("cast_browser_${device_type}_bundle_module") {
        is_base_module = false
        base_module_target = "//chromecast/internal/service/main/android:cast_service_${device_type}_bundle_module"

        android_manifest = "$root_gen_dir/cast_browser_${device_type}_manifest.AndroidManifest.xml"
        android_manifest_dep =
            "//chromecast/browser/android:cast_browser_${device_type}_manifest"

        min_sdk_version = 24
        target_sdk_version = 33

        module_name = "cast_browser"

        # |package_id| is required because the default one conflicts with the base
        # modules' ID (0x7f).
        package_id = 125

        shared_libraries = [ "//chromecast/android:libcast_browser_android" ]
        srcjar_deps =
            [ "//chromecast/android:libcast_browser_android__jni_registration" ]
        deps = [
          "//base:base_java",
          "//build/android:build_java",
          "//chromecast/browser/android:cast_browser_java",
          "//components/crash/core/app:chrome_crashpad_handler_named_as_so",
          "//components/viz/service:service_java",
          "//third_party/crashpad/crashpad/handler:crashpad_handler_trampoline",
          "//third_party/jni_zero:jni_zero_java",
        ]

        loadable_modules = [
          "$root_out_dir/libchrome_crashpad_handler.so",
          "$root_out_dir/libcrashpad_handler_trampoline.so",
        ]

        # TODO(b/228506503): remove the exclusion rule after cast_service and
        # cast_browser depend on different resource targets.
        resource_exclusion_regex = "cast_web_contents_activity.xml"

        # TODO(b/222780347): Enable when compile errors are resolved on release
        # builds.
        proguard_enabled = false
        generate_native_libraries_java = true
      }
    }
  }
}