blob: 9be71bcb5e81da2db80e436c59594880a00b9a90 [file] [log] [blame]
# 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.
import("//build/config/mac/base_rules.gni")
# Generates Info.plist files for Mac apps and frameworks.
#
# Arguments
#
# info_plist:
# string, the path to an plist file that will be included in the final
# Info.plist generated.
#
# executable_name:
# string, name of the generated target used for the product
# and executable name as specified in the output Info.plist.
#
# extra_substitutions:
# (optional) string array, 'key=value' pairs for extra fields which are
# specified in a source Info.plist template.
template("mac_info_plist") {
assert(defined(invoker.info_plist) != defined(invoker.info_plist_target),
"Only one of info_plist or info_plist_target may be specified in " +
target_name)
if (defined(invoker.info_plist)) {
_info_plist = invoker.info_plist
} else {
_info_plist_target_output = get_target_outputs(invoker.info_plist_target)
_info_plist = _info_plist_target_output[0]
}
info_plist(target_name) {
format = "xml1"
extra_substitutions = []
if (defined(invoker.extra_substitutions)) {
extra_substitutions = invoker.extra_substitutions
}
extra_substitutions += [
"MAC_SDK_BUILD=$mac_sdk_build",
"MAC_SDK_NAME=$mac_sdk_name$mac_sdk_version",
]
plist_templates = [
"//build/config/mac/BuildInfo.plist",
_info_plist,
]
if (defined(invoker.info_plist_target)) {
deps = [
invoker.info_plist_target,
]
}
forward_variables_from(invoker,
[
"testonly",
"executable_name",
])
}
}
# Template to compile and package Mac XIB files as bundle data.
#
# Arguments
#
# sources:
# list of string, sources to comiple
#
# output_path:
# (optional) string, the path to use for the outputs list in the
# bundle_data step. If unspecified, defaults to bundle_resources_dir.
template("mac_xib_bundle_data") {
_target_name = target_name
_compile_target_name = _target_name + "_compile_ibtool"
compile_xibs(_compile_target_name) {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":$_target_name" ]
sources = invoker.sources
ibtool_flags = [
"--minimum-deployment-target",
mac_deployment_target,
# TODO(rsesek): Enable this once all the bots are on Xcode 7+.
# "--target-device",
# "mac",
]
}
bundle_data(_target_name) {
forward_variables_from(invoker,
[
"testonly",
"visibility",
])
public_deps = [
":$_compile_target_name",
]
sources = get_target_outputs(":$_compile_target_name")
_output_path = "{{bundle_resources_dir}}"
if (defined(invoker.output_path)) {
_output_path = invoker.output_path
}
outputs = [
"$_output_path/{{source_file_part}}",
]
}
}
# Template to package a shared library into a Mac framework bundle.
#
# This template provides two targets to control whether the framework is
# merely built when targets depend on it, or whether it is linked as well:
# "$target_name" and "$target_name+link".
#
# See the //build/config/mac/base_rules.gni:framework_bundle for a discussion
# and examples.
#
# Arguments
#
# info_plist:
# (optional) string, path to the Info.plist file that will be used for
# the bundle.
#
# info_plist_target:
# (optional) string, if the info_plist is generated from an action,
# rather than a regular source file, specify the target name in lieu
# of info_plist. The two arguments are mutually exclusive.
#
# output_name:
# (optional) string, name of the generated framework without the
# .framework suffix. If omitted, defaults to target_name.
#
# framework_version:
# (optional) string, version of the framework. Typically this is a
# single letter, like "A". If omitted, the Versions/ subdirectory
# structure will not be created, and build output will go directly
# into the framework subdirectory.
#
# extra_substitutions:
# (optional) string array, 'key=value' pairs for extra fields which are
# specified in a source Info.plist template.
#
# See "gn help shared_library" for more information on arguments supported
# by shared library target.
template("mac_framework_bundle") {
assert(defined(invoker.deps),
"Dependencies must be specified for $target_name")
_info_plist_target = target_name + "_info_plist"
mac_info_plist(_info_plist_target) {
executable_name = target_name
if (defined(invoker.output_name)) {
executable_name = invoker.output_name
}
forward_variables_from(invoker,
[
"extra_substitutions",
"info_plist",
"info_plist_target",
"testonly",
])
}
_info_plist_bundle_data = _info_plist_target + "_bundle_data"
bundle_data(_info_plist_bundle_data) {
forward_variables_from(invoker, [ "testonly" ])
sources = get_target_outputs(":$_info_plist_target")
outputs = [
"{{bundle_resources_dir}}/Info.plist",
]
public_deps = [
":$_info_plist_target",
]
}
framework_bundle(target_name) {
forward_variables_from(invoker, "*", [ "info_plist" ])
if (!defined(deps)) {
deps = []
}
deps += [ ":$_info_plist_bundle_data" ]
}
}
# Template to create a Mac executable application bundle.
#
# Arguments
#
# info_plist:
# (optional) string, path to the Info.plist file that will be used for
# the bundle.
#
# info_plist_target:
# (optional) string, if the info_plist is generated from an action,
# rather than a regular source file, specify the target name in lieu
# of info_plist. The two arguments are mutually exclusive.
#
# output_name:
# (optional) string, name of the generated app without the
# .app suffix. If omitted, defaults to target_name.
#
# extra_configs:
# (optional) list of label, additional configs to apply to the
# executable target.
#
# extra_substitutions:
# (optional) string array, 'key=value' pairs for extra fields which are
# specified in a source Info.plist template.
template("mac_app_bundle") {
_target_name = target_name
_output_name = target_name
if (defined(invoker.output_name)) {
_output_name = invoker.output_name
}
_executable_target = target_name + "_executable"
_executable_bundle_data = _executable_target + "_bundle_data"
_info_plist_target = target_name + "_info_plist"
mac_info_plist(_info_plist_target) {
executable_name = _output_name
forward_variables_from(invoker,
[
"extra_substitutions",
"info_plist",
"info_plist_target",
"testonly",
])
}
executable(_executable_target) {
visibility = [ ":$_executable_bundle_data" ]
forward_variables_from(invoker,
"*",
[
"assert_no_deps",
"data_deps",
"info_plist",
"output_name",
"visibility",
])
if (defined(extra_configs)) {
configs += extra_configs
}
output_name = _output_name
output_dir = "$target_out_dir/$_executable_target"
}
bundle_data(_executable_bundle_data) {
visibility = [ ":$_target_name" ]
forward_variables_from(invoker, [ "testonly" ])
sources = [
"$target_out_dir/$_executable_target/$_output_name",
]
outputs = [
"{{bundle_executable_dir}}/$_output_name",
]
public_deps = [
":$_executable_target",
]
}
_info_plist_bundle_data = _info_plist_target + "_bundle_data"
bundle_data(_info_plist_bundle_data) {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":$_target_name" ]
sources = get_target_outputs(":$_info_plist_target")
outputs = [
"{{bundle_root_dir}}/Info.plist",
]
public_deps = [
":$_info_plist_target",
]
}
create_bundle(_target_name) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
"public_deps",
"testonly",
])
if (!defined(deps)) {
deps = []
}
deps += [
":$_executable_bundle_data",
":$_info_plist_bundle_data",
]
bundle_root_dir = "$root_out_dir/${_output_name}.app/Contents"
bundle_resources_dir = "$bundle_root_dir/Resources"
bundle_executable_dir = "$bundle_root_dir/MacOS"
}
}
# Template to package a loadable_module into a .plugin bundle.
#
# This takes no extra arguments that differ from a loadable_module.
template("mac_plugin_bundle") {
assert(defined(invoker.deps),
"Dependencies must be specified for $target_name")
_target_name = target_name
_loadable_module_target = _target_name + "_loadable_module"
_loadable_module_bundle_data = _loadable_module_target + "_bundle_data"
_output_name = _target_name
if (defined(invoker.output_name)) {
_output_name = invoker.output_name
}
loadable_module(_loadable_module_target) {
visibility = [ ":$_loadable_module_bundle_data" ]
forward_variables_from(invoker,
"*",
[
"assert_no_deps",
"data_deps",
"output_name",
"visibility",
])
output_dir = "$target_out_dir"
output_name = _output_name
}
bundle_data(_loadable_module_bundle_data) {
forward_variables_from(invoker, [ "testonly" ])
visibility = [ ":$_target_name" ]
sources = [
"$target_out_dir/${_output_name}.so",
]
outputs = [
"{{bundle_executable_dir}}/$_output_name",
]
public_deps = [
":$_loadable_module_target",
]
}
create_bundle(_target_name) {
forward_variables_from(invoker,
[
"data_deps",
"deps",
"public_deps",
"testonly",
"visibility",
])
if (!defined(deps)) {
deps = []
}
deps += [ ":$_loadable_module_bundle_data" ]
bundle_root_dir = "$root_out_dir/$_output_name.plugin/Contents"
bundle_executable_dir = "$bundle_root_dir/MacOS"
}
}