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

declare_args() {
  # SDK path to use. When empty this will use the default SDK based on the
  # value of use_ios_simulator.
  ios_sdk_path = ""
  ios_sdk_name = ""
  ios_sdk_version = ""
  ios_sdk_platform = ""
  xcode_version = ""
  xcode_build = ""
  machine_os_build = ""

  use_ios_simulator = target_cpu == "x86" || target_cpu == "x64"

  # Version of iOS that we're targeting.
  ios_deployment_target = "9.0"

  # The iOS Code signing identity to use
  # TODO(GYP), TODO(sdfresne): Consider having a separate
  # ios_enable_code_signing_flag=<bool> flag to make the invocation clearer.
  ios_enable_code_signing = true
  ios_code_signing_identity = ""
}

if (ios_sdk_path == "") {
  # Compute default target.
  if (use_ios_simulator) {
    ios_sdk_name = "iphonesimulator"
    ios_sdk_platform = "iPhoneSimulator"
  } else {
    ios_sdk_name = "iphoneos"
    ios_sdk_platform = "iPhoneOS"
  }
  _ios_sdk_result =
      exec_script("//build/config/mac/sdk_info.py", [ ios_sdk_name ], "scope")
  ios_sdk_path = _ios_sdk_result.sdk_path
  ios_sdk_version = _ios_sdk_result.sdk_version
  ios_sdk_build = _ios_sdk_result.sdk_build
  xcode_version = _ios_sdk_result.xcode_version
  xcode_build = _ios_sdk_result.xcode_build
  machine_os_build = _ios_sdk_result.machine_os_build
  if (use_ios_simulator) {
    # This is weird, but Xcode sets DTPlatformBuild to an empty field for
    # simulator builds.
    ios_platform_build = ""
  } else {
    ios_platform_build = ios_sdk_build
  }
}

if (use_ios_simulator) {
  # Always disable code signing on the simulator
  ios_enable_code_signing = false
  ios_code_signing_identity = ""
}

if (ios_enable_code_signing) {
  # If an identity is not provided, look for one on the host
  if (ios_code_signing_identity == "") {
    _ios_identities = exec_script("find_signing_identity.py", [], "list lines")
    ios_code_signing_identity = _ios_identities[0]
  }

  if (ios_code_signing_identity == "") {
    print("Tried to prepare a device build without specifying a code signing")
    print("identity and could not detect one automatically either.")
    print("TIP: Simulator builds don't require code signing...")
    assert(false)
  }
}