1# Copyright 2019 The Chromium Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/config/ios/bundle_identifier_prefix.gni") 6import("//build/config/ios/sdk_info.gni") 7import("//build/config/ios/templates/ios_binary_bundle.gni") 8import("//build/config/ios/templates/merge_plist.gni") 9 10# Template to generate an app bundle. 11# 12# All the other parameters are forwarded to a shared_library target that will 13# generate the bundle binary. In general, you want to pass at least "sources" 14# or "deps" to have some binary objects included in your shared library. 15# 16# Arguments 17# 18# - info_plist (optional) 19# 20# path to additional Info.plist to merge into the final bundle Info.plist 21# 22# - bundle_identifier_prefix (optional) 23# 24# prefix for the bundle identifier (the full identifier will be defined 25# to $bundle_identifier_prefix.$output_name); if unset will defaults to 26# default_bundle_identifier_prefix 27# 28# - output_name (optional) 29# 30# name of the bundle without the extension; defaults to $target_name 31# 32template("ios_app_bundle") { 33 _output_name = target_name 34 if (defined(invoker.output_name)) { 35 _output_name = invoker.output_name 36 } 37 38 _bundle_identifier_prefix = default_bundle_identifier_prefix 39 if (defined(invoker.bundle_identifier_prefix)) { 40 _bundle_identifier_prefix = invoker.bundle_identifier_prefix 41 } 42 43 _bundle_identifier = "$_bundle_identifier_prefix.$_output_name" 44 45 _app_prefix_target = target_name + "_app_prefix" 46 _app_prefix_output = "$target_out_dir/$_app_prefix_target/app_prefix.json" 47 48 action(_app_prefix_target) { 49 script = "//build/config/ios/scripts/find_app_identifier_prefix.py" 50 sources = [] 51 outputs = [ _app_prefix_output ] 52 args = [ 53 "-b=" + _bundle_identifier, 54 "-o=" + rebase_path(_app_prefix_output, root_build_dir), 55 ] 56 } 57 58 if (sdk_info.is_simulator) { 59 _simu_xcent_target = target_name + "_simu_xcent" 60 _simu_xcent_output = 61 "$target_out_dir/$_simu_xcent_target/" + "Entitlements-Simulated.plist" 62 63 merge_plist(_simu_xcent_target) { 64 format = "xml1" 65 output = _simu_xcent_output 66 plists = [ "//build/config/ios/resources/Entitlements-Simulated.plist" ] 67 substitutions_json = _app_prefix_output 68 deps = [ ":$_app_prefix_target" ] 69 } 70 } 71 72 _executable_target = target_name + "_executable" 73 _executable_bundle = target_name + "_executable_bundle" 74 75 executable(_executable_target) { 76 forward_variables_from(invoker, 77 "*", 78 [ 79 "bundle_extension", 80 "bundle_identifier_prefix", 81 "bundle_type", 82 "display_name", 83 "info_plist", 84 "output_name", 85 "public_headers", 86 ]) 87 88 output_extension = "" 89 output_name = _output_name 90 output_prefix_override = true 91 output_dir = "$target_out_dir/$_executable_target" 92 93 if (sdk_info.is_simulator) { 94 if (!defined(deps)) { 95 deps = [] 96 } 97 if (!defined(inputs)) { 98 inputs = [] 99 } 100 if (!defined(ldflags)) { 101 ldflags = [] 102 } 103 104 deps += [ ":$_simu_xcent_target" ] 105 inputs += [ _simu_xcent_output ] 106 ldflags += [ 107 "-Xlinker", 108 "-sectcreate", 109 "-Xlinker", 110 "__TEXT", 111 "-Xlinker", 112 "__entitlements", 113 "-Xlinker", 114 rebase_path(_simu_xcent_output, root_build_dir), 115 ] 116 } 117 } 118 119 bundle_data(_executable_bundle) { 120 public_deps = [ ":$_executable_target" ] 121 sources = [ "$target_out_dir/$_executable_target/$_output_name" ] 122 outputs = [ "{{bundle_executable_dir}}/{{source_file_part}}" ] 123 } 124 125 ios_binary_bundle(target_name) { 126 forward_variables_from(invoker, 127 "*", 128 [ 129 "bundle_extension", 130 "bundle_identifier_prefix", 131 "bundle_type", 132 "deps", 133 "output_name", 134 "public_deps", 135 "public_headers", 136 ]) 137 138 output_name = _output_name 139 product_type = "com.apple.product-type.application" 140 141 bundle_identifier = _bundle_identifier 142 bundle_extension = "app" 143 bundle_type = "AAPL" 144 145 public_deps = [ ":$_executable_bundle" ] 146 } 147} 148