# 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")

action("remoting_me2me_host_archive") {
  # TODO(GYP) TODO(crbug.com/622415) This needs work and testing.

  # TODO(GYP) At the very least, we need to add in the localized strings.

  _installer_mac_files = [
    "do_signing.sh",
    "do_signing.props",
    "ChromotingHost.pkgproj",
    "ChromotingHostService.pkgproj",
    "ChromotingHostUninstaller.pkgproj",
    "LaunchAgents/org.chromium.chromoting.plist",
    "PrivilegedHelperTools/org.chromium.chromoting.me2me.sh",
    "Scripts/keystone_install.sh",
    "Scripts/remoting_postflight.sh",
    "Scripts/remoting_preflight.sh",
    "Keystone/GoogleSoftwareUpdate.pkg",
    "//chrome/installer/mac/pkg-dmg",
  ]

  inputs = _installer_mac_files

  zip_path = "$root_build_dir/remoting-me2me-host-mac.zip"

  outputs = [
    "$root_build_dir/remoting-me2me-host-mac.zip",
  ]

  script = "//remoting/host/installer/build-installer-archive.py"

  args = [
           rebase_path("$target_gen_dir/remoting_installation", root_build_dir),
           rebase_path(zip_path, root_build_dir),
           "--source-file-roots",
           rebase_path("//remoting/host/installer/mac/", root_build_dir),
           rebase_path("//chrome/installer/mac", root_build_dir),
           "--source-files",
         ] + rebase_path(_installer_mac_files, root_build_dir) + [
           "--generated-files",
           "remoting_host_prefpane.prefPane",
           "remoting_me2me_host.app",
           "native_messaging_host.app",
           "remote_assistance_host.app",
           "remoting_host_uninstaller.app",
           "remoting/com.google.chrome.remote_desktop.json",
           "remoting/com.google.chrome.remote_assistance.json",
           "--generated-files-dst",
           "PreferencePanes/$prefpane_bundle_name",
           "PrivilegedHelperTools/$host_bundle_name",
           "PrivilegedHelperTools/$host_bundle_name/Contents/MacOS/$native_messaging_host_bundle_name",
           "PrivilegedHelperTools/$host_bundle_name/Contents/MacOS/$remote_assistance_host_bundle_name",
           "Applications/$host_uninstaller_name.app",
           "Config/com.google.chrome.remote_desktop.json",
           "Config/com.google.chrome.remote_assistance.json",
           "--defs",
           "VERSION=$chrome_version_full",
           "VERSION_SHORT=$chrome_version_major.$chrome_version_minor.$chrome_version_build",
           "VERSION_MAJOR=$chrome_version_major",
           "VERSION_MINOR=$chrome_version_minor",
           "HOST_NAME=$host_name",
           "HOST_BUNDLE_NAME=$me2me_host_bundle_name",
           "HOST_SERVICE_NAME=$host_service_name",
           "HOST_UNINSTALLER_NAME=$host_uninstaller_name",
           "HOST_PKG=$host_name",
           "HOST_SERVICE_PKG=$host_service_name_nospace",
           "HOST_UNINSTALLER_PKG=$host_uninstaller_name_nospace",
           "BUNDLE_ID_HOST=$bundle_prefix.$host_name_nospace",
           "BUNDLE_ID_HOST_SERVICE=$bundle_prefix.$host_service_name_nospace",
           "BUNDLE_ID_HOST_UNINSTALLER=$bundle_prefix.$host_uninstaller_name_nospace",
           "DMG_VOLUME_NAME=$host_name $chrome_version_full",
           "DMG_FILE_NAME=$host_name_nospace-$chrome_version_full",
           "NATIVE_MESSAGING_HOST_BUNDLE_NAME=$native_messaging_host_bundle_name",
           "REMOTE_ASSISTANCE_HOST_BUNDLE_NAME=$remote_assistance_host_bundle_name",
           "PREFPANE_BUNDLE_NAME=$prefpane_bundle_name",
         ]

  deps = [
    ":remoting_host_uninstaller",
    "//remoting/host:remoting_me2me_host",
    "//remoting/host:remoting_native_messaging_host",
    "//remoting/host:remoting_native_messaging_manifests",
    "//remoting/host/it2me:remote_assistance_host",
    "//remoting/host/mac:remoting_host_prefpane.prefPane",
  ]
}

_uninstaller_plist = "uninstaller/remoting_uninstaller-Info.plist"

# remoting_uninstaller-InfoPlist.strings
foreach(locale, remoting_locales_with_underscores) {
  bundle_data("remoting_uninstaller_strings_${locale}_bundle_data") {
    sources = [
      "$root_gen_dir/remoting/host/remoting_uninstaller-InfoPlist.strings/$locale.lproj/InfoPlist.strings",
    ]
    outputs = [
      "{{bundle_resources_dir}}/$locale.lproj/{{source_file_part}}",
    ]
    deps = [
      "//remoting/host:remoting_infoplist_strings",
    ]
  }
}

mac_app_bundle("remoting_host_uninstaller") {
  info_plist = _uninstaller_plist
  extra_substitutions = [
    "BUNDLE_ID=$uninstaller_bundle_id",
    "VERSION_FULL=$remoting_version_full",
    "VERSION_SHORT=$remoting_version_short",
    "MACOSX_DEPLOYMENT_TARGET=10.7",
  ]

  sources = [
    "uninstaller/remoting_uninstaller.h",
    "uninstaller/remoting_uninstaller.mm",
    "uninstaller/remoting_uninstaller_app.h",
    "uninstaller/remoting_uninstaller_app.mm",
  ]

  libs = [
    "Cocoa.framework",
    "CoreFoundation.framework",
    "Security.framework",
  ]

  deps = [
    ":remoting_host_uninstaller_resources",
    ":remoting_host_uninstaller_xibs",
    "//base",
    "//remoting/host:remoting_infoplist_strings",
    "//remoting/host/mac:constants",
  ]
  foreach(locale, remoting_locales_with_underscores) {
    deps += [ ":remoting_uninstaller_strings_${locale}_bundle_data" ]
  }
}

mac_xib_bundle_data("remoting_host_uninstaller_xibs") {
  sources = [
    "uninstaller/remoting_uninstaller.xib",
  ]
}

bundle_data("remoting_host_uninstaller_resources") {
  sources = [
    "uninstaller/remoting_uninstaller.icns",
  ]

  outputs = [
    "{{bundle_resources_dir}}/{{source_file_part}}",
  ]
}
