Commit 7a7cd719 authored by sdefresne's avatar sdefresne Committed by Commit bot

Add template to compile plist files.

Add new template compile_plist that merge multiple plist files and
perform variables subsitutions and change info_plist implementation
to use it.

The new template will be used to compile entitlements files that
need different substitutions and do not use the one for Info.plist.

BUG=613543

Review-Url: https://codereview.chromium.org/2475893002
Cr-Commit-Position: refs/heads/master@{#430269}
parent 568cf3e9
......@@ -56,48 +56,41 @@ template("convert_plist") {
}
}
# The base template used to generate Info.plist files for iOS and Mac apps and
# frameworks.
# Template to merge multiple plist files and perform variable substitutions.
#
# Arguments
#
# plist_templates:
# string array, paths to plist files which will be used for the bundle.
#
# executable_name:
# string, name of the generated target used for the product
# and executable name as specified in the output Info.plist.
#
# format:
# string, the format to `plutil -convert` the plist to when
# generating the output.
#
# extra_substitutions:
# (optional) string array, 'key=value' pairs for extra fields which are
# specified in a source Info.plist template.
# substitutions:
# string array, 'key=value' pairs used to replace ${key} by value
# when generating the output plist file.
#
# output_name:
# (optional) string, name of the generated plist file, default to
# "$target_gen_dir/$target_name.plist".
template("info_plist") {
# string, name of the generated plist file.
template("compile_plist") {
assert(defined(invoker.plist_templates),
"A list of template plist files must be specified for $target_name")
assert(defined(invoker.executable_name),
"The executable_name must be specified for $target_name")
assert(defined(invoker.format),
"The plist format must be specified for $target_name")
executable_name = invoker.executable_name
_output_name = "$target_gen_dir/$target_name.plist"
if (defined(invoker.output_name)) {
_output_name = invoker.output_name
}
assert(defined(invoker.substitutions),
"A list of key=value pairs must be specified for $target_name")
assert(defined(invoker.output_name),
"The name of the output file must be specified for $target_name")
_output_name = invoker.output_name
_merged_name = get_path_info(_output_name, "dir") + "/" +
get_path_info(_output_name, "name") + "_merged" +
get_path_info(_output_name, "name") + "_merged." +
get_path_info(_output_name, "extension")
action(target_name + "_merge_templates") {
_merge_target = target_name + "_merge"
action(_merge_target) {
forward_variables_from(invoker,
[
"deps",
......@@ -113,7 +106,7 @@ template("info_plist") {
"merge",
"-f=" + invoker.format,
"-o=" + rebase_path(_merged_name, root_build_dir),
] + rebase_path(sources, root_build_dir)
] + rebase_path(invoker.plist_templates, root_build_dir)
}
action(target_name) {
......@@ -129,29 +122,79 @@ template("info_plist") {
outputs = [
_output_name,
]
args = [ "substitute" ]
if (defined(invoker.extra_substitutions)) {
foreach(substitution, invoker.extra_substitutions) {
args += [ "-s=$substitution" ]
}
}
args += [
"-s=BUILD_MACHINE_OS_BUILD=$machine_os_build",
"-s=EXECUTABLE_NAME=$executable_name",
"-s=GCC_VERSION=com.apple.compilers.llvm.clang.1_0",
"-s=PRODUCT_NAME=$executable_name",
"-s=XCODE_BUILD=$xcode_build",
"-s=XCODE_VERSION=$xcode_version",
args = [
"substitute",
"-f=" + invoker.format,
"-o=" + rebase_path(_output_name, root_build_dir),
"-t=" + rebase_path(_merged_name, root_build_dir),
"-f=" + invoker.format,
]
foreach(_substitution, invoker.substitutions) {
args += [ "-s=$_substitution" ]
}
deps = [
":" + target_name + "_merge_templates",
":$_merge_target",
]
}
}
# The base template used to generate Info.plist files for iOS and Mac apps and
# frameworks.
#
# Arguments
#
# plist_templates:
# string array, paths to plist files which will be used for the bundle.
#
# executable_name:
# string, name of the generated target used for the product
# and executable name as specified in the output Info.plist.
#
# format:
# string, the format to `plutil -convert` the plist to when
# generating the output.
#
# extra_substitutions:
# (optional) string array, 'key=value' pairs for extra fields which are
# specified in a source Info.plist template.
#
# output_name:
# (optional) string, name of the generated plist file, default to
# "$target_gen_dir/$target_name.plist".
template("info_plist") {
assert(defined(invoker.executable_name),
"The executable_name must be specified for $target_name")
executable_name = invoker.executable_name
compile_plist(target_name) {
forward_variables_from(invoker,
[
"plist_templates",
"testonly",
"deps",
"visibility",
"format",
])
if (defined(invoker.output_name)) {
output_name = invoker.output_name
} else {
output_name = "$target_gen_dir/$target_name.plist"
}
substitutions = [
"BUILD_MACHINE_OS_BUILD=$machine_os_build",
"EXECUTABLE_NAME=$executable_name",
"GCC_VERSION=com.apple.compilers.llvm.clang.1_0",
"PRODUCT_NAME=$executable_name",
"XCODE_BUILD=$xcode_build",
"XCODE_VERSION=$xcode_version",
]
if (defined(invoker.extra_substitutions)) {
substitutions += invoker.extra_substitutions
}
}
}
# Template to combile .xib or .storyboard files.
#
# Arguments
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment