# 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.

root_dist_dir = "$root_build_dir/dist"

copy("sky_shell") {
  if (is_android) {
    sources = [
      "$root_build_dir/apks/SkyShell.apk",
      "$root_build_dir/flutter.mojo",
      "$root_build_dir/symbols/libflutter_library.so",
    ]

    deps = [
      "//sky/shell",
      "//sky/shell/platform/mojo",
    ]
  } else if (is_mac) {
    sources = [
      "$root_build_dir/SkyShell.app",
    ]

    deps = [
      "//sky/shell:shell_struct",
    ]
  } else if (is_fnl) {
    sources = [
      "$root_build_dir/flutter.mojo",
    ]

    deps = [
      "//sky/shell/platform/mojo",
    ]
  } else if (!is_ios) {
    sources = [
      "$root_build_dir/flutter.mojo",
      "$root_build_dir/icudtl.dat",
      "$root_build_dir/sky_shell",
      "$root_build_dir/symbols/libflutter_library.so",
    ]

    deps = [
      "//sky/shell",
      "//sky/shell/platform/mojo",
      "//sky/shell/platform/mojo",
      "//third_party/icu:icudata",
    ]
  } else {
    sources = []
    deps = []
  }

  sky_snapshot_dir =
      get_label_info("//sky/tools/sky_snapshot($host_toolchain)", "root_out_dir")

  sources += [ "$sky_snapshot_dir/sky_snapshot" ]

  deps += [
    "//sky/tools/sky_snapshot($host_toolchain)",
  ]

  outputs = [ "$root_dist_dir/shell/{{source_file_part}}" ]
}

if (is_android) {
  action("sky_engine") {
    script = "//sky/tools/dist_dart_pkg.py"

    source = "$root_gen_dir/dart-pkg/sky_engine"
    dest = "$root_dist_dir/packages/sky_engine"

    inputs = [ source ]
    outputs = [ dest ]

    args = [
      "--source",
      rebase_path(source),
      "--dest",
      rebase_path(dest),
    ]

    deps = [
      "//sky/packages/sky_engine",
    ]
  }

  action("sky_services") {
    script = "//sky/tools/dist_dart_pkg.py"

    source = "$root_gen_dir/dart-pkg/sky_services"
    dest = "$root_dist_dir/packages/sky_services"

    inputs = [ source ]
    outputs = [ dest ]

    args = [
      "--source",
      rebase_path(source),
      "--dest",
      rebase_path(dest),
    ]

    deps = [
      "//sky/packages/sky_services",
    ]
  }
}

group("dist") {
  deps = []

  if (!is_ios && !is_mac) {
    deps += [ ":sky_shell" ]
  }

  if (is_android) {
    deps += [
      ":sky_engine",
      ":sky_services",
      "//build/android/ant:keystore",
    ]
  }
}
