# Copyright 2014 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("//build/config/chrome_build.gni")
import("//build/util/version.gni")

remoting_version_file = "//remoting/VERSION"

_version_py_abspath = "//build/util/version.py"
if (is_chrome_branded) {
  _remoting_branding_abspath = "//remoting/branding_Chrome"
} else {
  _remoting_branding_abspath = "//remoting/branding_Chromium"
}

# Set these files as being input dependencies to the scripts, so the build will
# be re-run if the files change.
remoting_version_files = [
  remoting_version_file,
  _remoting_branding_abspath,
]

_remoting_version_path = rebase_path(remoting_version_file, root_build_dir)
_remoting_branding_path =
    rebase_path(_remoting_branding_abspath, root_build_dir)

_template = "mac_host_bundle = \"@MAC_HOST_BUNDLE_NAME@\" "
_template +=
    "mac_native_messaging_bundle = \"@MAC_NATIVE_MESSAGING_HOST_BUNDLE_NAME@\" "
_template += "mac_remote_assistance_bundle = \"@MAC_REMOTE_ASSISTANCE_HOST_BUNDLE_NAME@\" "
_template += "prefpane_bundle_name = \"@MAC_PREFPANE_BUNDLE_NAME@\" "
_template += "host_bundle_name = \"@MAC_HOST_BUNDLE_NAME@\" "
_template += "host_name= \"@MAC_HOST_PACKAGE_NAME@\" "
_template += "host_service_name = \"@DAEMON_FILE_NAME@\" "
_template += "bundle_prefix = \"@MAC_UNINSTALLER_BUNDLE_PREFIX@\" "
_template += "host_uninstaller_name = \"@MAC_UNINSTALLER_NAME@\" "
_template += "version_patch = \"@REMOTING_PATCH@\" "

if (is_mac) {
  _template += "host_bundle_id = \"@MAC_HOST_BUNDLE_ID@\" "
  _template += "native_messaging_host_bundle_id = \"@MAC_NATIVE_MESSAGING_HOST_BUNDLE_ID@\""
  _template += "prefpane_bundle_id = \"@MAC_PREFPANE_BUNDLE_ID@\" "
  _template += "remote_assistance_host_bundle_id = \"@MAC_REMOTE_ASSISTANCE_HOST_BUNDLE_ID@\" "
  _template += "uninstaller_bundle_id = \"@MAC_UNINSTALLER_BUNDLE_ID@\""
}

_result = exec_script(_version_py_abspath,
                      [
                        "-f",
                        _remoting_branding_path,
                        "-f",
                        _remoting_version_path,
                        "-t",
                        _template,
                      ],
                      "scope",
                      remoting_version_files)

prefpane_bundle_name = _result.prefpane_bundle_name
host_bundle_name = _result.host_bundle_name
host_name = _result.host_name
host_service_name = _result.host_service_name
bundle_prefix = _result.bundle_prefix
host_uninstaller_name = _result.host_uninstaller_name
me2me_host_bundle_name = _result.mac_host_bundle
native_messaging_host_bundle_name = _result.mac_native_messaging_bundle
remote_assistance_host_bundle_name = _result.mac_remote_assistance_bundle
remoting_version_patch = _result.version_patch
remoting_version_short =
    "$chrome_version_major.$remoting_version_patch.$chrome_version_build"
remoting_version_full = "$remoting_version_short.$chrome_version_patch"

if (is_mac) {
  host_bundle_id = _result.host_bundle_id
  native_messaging_host_bundle_id = _result.native_messaging_host_bundle_id
  prefpane_bundle_id = _result.prefpane_bundle_id
  remote_assistance_host_bundle_id = _result.remote_assistance_host_bundle_id
  uninstaller_bundle_id = _result.uninstaller_bundle_id

  host_name_nospace = exec_script("//remoting/tools/remove_spaces.py",
                                  [ "$host_name" ],
                                  "trim string")
  host_service_name_nospace = exec_script("//remoting/tools/remove_spaces.py",
                                          [ "$host_service_name" ],
                                          "trim string")
  host_uninstaller_name_nospace =
      exec_script("//remoting/tools/remove_spaces.py",
                  [ "$host_uninstaller_name" ],
                  "trim string")
}
