# Copyright 2016 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("//remoting/build/config/remoting_build.gni")

import("//build/config/zip.gni")

build_deb_script = "build_deb.py"
deb_filename =
    "$root_build_dir/" + exec_script(build_deb_script,
                                     [
                                       "-p",
                                       "-s",
                                       rebase_path("//", root_build_dir),
                                     ],
                                     "string",
                                     [ "build-deb.sh" ])
changes_filename =
    "$root_build_dir/" + get_path_info(deb_filename, "name") + ".changes"

packaging_outputs = [
  deb_filename,
  changes_filename,
]

zip("remoting_me2me_host_archive") {
  # Store the installer package(s) into a zip file so there is a
  # consistent filename to reference for build archiving (i.e. in
  # FILES.cfg). This also avoids possible conflicts with "wildcard"
  # package handling in other build/signing scripts.
  inputs = packaging_outputs
  output = "$root_build_dir/remoting-me2me-host-linux.zip"
  deps = [
    ":remoting_me2me_host_copy",
  ]
}

copy("remoting_me2me_host_copy") {
  # Copy the debian package file, which has version info in it,
  # to a consistewnt filename for use on Chromoting swarming bots.
  sources = [
    deb_filename,
  ]
  outputs = [
    "$root_build_dir/remoting-me2me-host.deb",
  ]
  public_deps = [
    ":remoting_me2me_host_deb_installer",
  ]
}

action("remoting_me2me_host_deb_installer") {
  script = build_deb_script
  inputs = [
    build_deb_script,
    "Makefile",
    "debian/chrome-remote-desktop.init",
    "debian/chrome-remote-desktop.pam",
    "debian/compat",
    "debian/control",
    "debian/copyright",
    "debian/postinst",
    "debian/preinst",
    "debian/rules",
  ]
  outputs = packaging_outputs
  sources = [
    "build-deb.sh",
  ]
  args = [
    "-s",
    rebase_path("//", root_build_dir),
    "-o",
    ".",
  ]

  deps = [
    "//remoting/host:remoting_me2me_host",
    "//remoting/host:remoting_native_messaging_host",
    "//remoting/host:remoting_native_messaging_manifests",
    "//remoting/host:remoting_start_host",
    "//remoting/host/it2me:remote_assistance_host",
    "//remoting/host/linux:remoting_user_session",
    "//remoting/resources",
    "//third_party/icu:icudata",
  ]
}