| OLD | NEW |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 ios_app_script = "//build/config/ios/ios_app.py" | 5 import("//build/config/ios/ios_sdk.gni") |
| 6 | 6 |
| 7 # Template to code sign an iOS application. |
| 8 # |
| 9 # TODO(sdefresne): document or inline into "ios_app" template if the template |
| 10 # is not used anywhere else. |
| 7 template("code_sign_ios") { | 11 template("code_sign_ios") { |
| 8 assert(defined(invoker.entitlements_path), | 12 assert(defined(invoker.entitlements_path), |
| 9 "The path to the entitlements .xcent file") | 13 "The path to the entitlements .xcent file") |
| 10 assert(defined(invoker.identity), "The code signing identity") | 14 assert(defined(invoker.identity), "The code signing identity") |
| 11 assert(defined(invoker.application_path), "The application to code sign") | 15 assert(defined(invoker.application_path), "The application to code sign") |
| 12 assert(defined(invoker.deps)) | 16 assert(defined(invoker.deps)) |
| 13 | 17 |
| 14 action(target_name) { | 18 action(target_name) { |
| 15 sources = [ | 19 sources = [ |
| 16 invoker.entitlements_path, | 20 invoker.entitlements_path, |
| 17 ] | 21 ] |
| 18 | 22 |
| 19 _application_path = invoker.application_path | 23 _application_path = invoker.application_path |
| 20 | 24 |
| 21 script = ios_app_script | 25 script = "//build/config/ios/ios_code_sign.py" |
| 22 | 26 |
| 23 outputs = [ | 27 outputs = [ |
| 24 "$_application_path/_CodeSignature/CodeResources", | 28 "$_application_path/_CodeSignature/CodeResources", |
| 25 ] | 29 ] |
| 26 | 30 |
| 27 args = [ | 31 args = [ |
| 28 "codesign", | 32 "codesign", |
| 29 "-p", | 33 "-p", |
| 30 rebase_path(invoker.application_path, root_build_dir), | 34 rebase_path(invoker.application_path, root_build_dir), |
| 31 "-i", | 35 "-i", |
| 32 invoker.identity, | 36 invoker.identity, |
| 33 "-e", | 37 "-e", |
| 34 rebase_path(invoker.entitlements_path, root_build_dir), | 38 rebase_path(invoker.entitlements_path, root_build_dir), |
| 35 ] | 39 ] |
| 36 | 40 |
| 37 forward_variables_from(invoker, | 41 forward_variables_from(invoker, |
| 38 [ | 42 [ |
| 39 "deps", | 43 "deps", |
| 40 "public_deps", | 44 "public_deps", |
| 41 "testonly", | 45 "testonly", |
| 42 ]) | 46 ]) |
| 43 } | 47 } |
| 44 } | 48 } |
| 45 | 49 |
| 46 # TODO(GYP), TODO(dpranke): Should this be part of ios_app? | 50 # Use this template to create application bundle for iOS. |
| 47 template("resource_copy_ios") { | 51 # |
| 48 assert(defined(invoker.resources), | 52 # Arguments: |
| 49 "The source list of resources to copy over") | 53 # |
| 50 assert(defined(invoker.bundle_directory), | 54 # info_plist |
| 51 "The directory within the bundle to place the sources in") | 55 # Path to the application Info.plist template (variable substitution |
| 52 assert(defined(invoker.app_name), "The name of the application") | 56 # will be performed). |
| 53 | 57 # |
| 54 _bundle_directory = invoker.bundle_directory | 58 # entitlements_path |
| 55 _app_name = invoker.app_name | 59 # Path to the application entitlements .xcent. |
| 56 _resources = invoker.resources | 60 # |
| 57 | 61 # code_signing_identity |
| 58 copy(target_name) { | 62 # Identity to use for signing the application, if signing is enabled. |
| 59 set_sources_assignment_filter([]) | 63 # |
| 60 sources = _resources | 64 # app_name (optional) |
| 61 outputs = [ | 65 # Name of the application, defaults to ${target_name}. |
| 62 "$root_build_dir/$_app_name.app/$_bundle_directory/{{source_file_part}}", | 66 # |
| 63 ] | 67 # extra_pattern_substitution (optional) |
| 64 } | 68 # List of string in "key=value" format. Each correspond to variable |
| 65 } | 69 # substitution to perform when compiling the Info.plist template. |
| 66 | 70 # |
| 71 # The template uses an "executable" target under the hood and forwards to it |
| 72 # all the arguments it supports. Look at "executable" documentation for more |
| 73 # information. |
| 67 template("ios_app") { | 74 template("ios_app") { |
| 68 assert(defined(invoker.deps), | |
| 69 "Dependencies must be specified for $target_name") | |
| 70 assert(defined(invoker.info_plist), | 75 assert(defined(invoker.info_plist), |
| 71 "The application plist file must be specified for $target_name") | 76 "The application plist file must be specified for $target_name") |
| 72 assert(defined(invoker.entitlements_path), | 77 assert(defined(invoker.entitlements_path), |
| 73 "The entitlements path must be specified for $target_name") | 78 "The entitlements path must be specified for $target_name") |
| 74 assert(defined(invoker.code_signing_identity), | 79 assert(defined(invoker.code_signing_identity), |
| 75 "The code_signing_identity must be specified for $target_name") | 80 "The code_signing_identity must be specified for $target_name") |
| 76 | 81 |
| 77 # We just create a variable so we can use the same in interpolation | 82 # We just create a variable so we can use the same in interpolation |
| 78 if (defined(invoker.app_name)) { | 83 if (defined(invoker.app_name)) { |
| 79 _app_name = invoker.app_name | 84 _app_name = invoker.app_name |
| 80 } else { | 85 } else { |
| 81 _app_name = target_name | 86 _app_name = target_name |
| 82 } | 87 } |
| 83 | 88 |
| 84 forward_variables_from(invoker, [ "testonly" ]) | 89 forward_variables_from(invoker, [ "testonly" ]) |
| 85 | 90 |
| 86 plist_gen_target_name = target_name + "_plist" | 91 plist_gen_target_name = target_name + "__plist" |
| 87 bin_gen_target_name = target_name + "_bin" | 92 bin_gen_target_name = target_name + "__bin" |
| 93 res_gen_target_name = target_name + "__res" |
| 88 group_target_name = target_name | 94 group_target_name = target_name |
| 89 | 95 |
| 90 # Generate the executable | 96 # Generate the executable |
| 91 executable(bin_gen_target_name) { | 97 executable(bin_gen_target_name) { |
| 92 visibility = [ ":$group_target_name" ] | 98 visibility = [ ":$group_target_name" ] |
| 93 | |
| 94 output_name = "${_app_name}.app/${_app_name}" | 99 output_name = "${_app_name}.app/${_app_name}" |
| 95 | 100 |
| 96 forward_variables_from(invoker, | 101 forward_variables_from(invoker, |
| 97 [ | 102 [ |
| 98 "all_dependent_configs", | 103 "all_dependent_configs", |
| 99 "allow_circular_includes_from", | 104 "allow_circular_includes_from", |
| 100 "cflags", | 105 "cflags", |
| 101 "cflags_c", | 106 "cflags_c", |
| 102 "cflags_cc", | 107 "cflags_cc", |
| 103 "cflags_objc", | 108 "cflags_objc", |
| 104 "cflags_objcc", | 109 "cflags_objcc", |
| 110 "check_includes", |
| 105 "configs", | 111 "configs", |
| 106 "check_includes", | |
| 107 "data", | 112 "data", |
| 108 "data_deps", | 113 "data_deps", |
| 109 "defines", | 114 "defines", |
| 115 "deps", |
| 110 "include_dirs", | 116 "include_dirs", |
| 111 "ldflags", | 117 "ldflags", |
| 118 "libs", |
| 112 "public", | 119 "public", |
| 113 "public_configs", | 120 "public_configs", |
| 114 "public_deps", | 121 "public_deps", |
| 115 "sources", | 122 "sources", |
| 116 ]) | 123 ]) |
| 117 | 124 |
| 118 if (defined(invoker.libs)) { | 125 if (!defined(invoker.libs)) { |
| 119 libs = invoker.libs | |
| 120 } else { | |
| 121 libs = [] | 126 libs = [] |
| 122 } | 127 } |
| 123 libs += [ | 128 libs += [ "UIKit.framework" ] |
| 124 "UIKit.framework", | |
| 125 "QuartzCore.framework", | |
| 126 "OpenGLES.framework", | |
| 127 ] | |
| 128 | 129 |
| 129 if (defined(invoker.deps)) { | 130 if (!defined(invoker.deps)) { |
| 130 deps = invoker.deps | |
| 131 } else { | |
| 132 deps = [] | 131 deps = [] |
| 133 } | 132 } |
| 134 deps += [ ":$plist_gen_target_name" ] | 133 deps += [ ":$plist_gen_target_name" ] |
| 135 } | 134 } |
| 136 | 135 |
| 137 # Process the Info.plist | 136 # Process the Info.plist |
| 138 action(plist_gen_target_name) { | 137 action(plist_gen_target_name) { |
| 139 visibility = [ | 138 visibility = [ |
| 140 ":$group_target_name", | 139 ":$group_target_name", |
| 141 ":$bin_gen_target_name", | 140 ":$bin_gen_target_name", |
| 142 ] | 141 ] |
| 143 | 142 |
| 144 script = ios_app_script | 143 generated_info_plist = "$root_build_dir/$_app_name.app/Info.plist" |
| 145 | 144 |
| 145 script = "//build/config/ios/ios_gen_plist.py" |
| 146 outputs = [ |
| 147 generated_info_plist, |
| 148 ] |
| 146 sources = [ | 149 sources = [ |
| 150 "//build/config/ios/BuildInfo.plist", |
| 147 invoker.info_plist, | 151 invoker.info_plist, |
| 148 ] | 152 ] |
| 153 |
| 154 extra_args = [] |
| 155 if (defined(invoker.extra_pattern_substitution)) { |
| 156 foreach(substitution, invoker.extra_pattern_substitution) { |
| 157 extra_args += [ "-s=$substitution" ] |
| 158 } |
| 159 } |
| 160 |
| 161 args = extra_args + [ |
| 162 "-s=BUILD_MACHINE_OS_BUILD=${machine_os_build}", |
| 163 "-s=IOS_SUPPORTED_PLATFORM=${ios_sdk_platform}", |
| 164 "-s=IOS_SDK_NAME=${ios_sdk_name}", |
| 165 "-s=IOS_SDK_BUILD=${ios_sdk_version}", |
| 166 "-s=XCODE_VERSION=${xcode_version}", |
| 167 "-s=XCODE_BUILD=${xcode_build}", |
| 168 "-s=PRODUCT_NAME=${_app_name}", |
| 169 "-s=EXECUTABLE_NAME=${_app_name}", |
| 170 "-o=" + rebase_path(generated_info_plist), |
| 171 ] + rebase_path(sources) |
| 172 } |
| 173 |
| 174 # Copy resources. |
| 175 copy_bundle_data(res_gen_target_name) { |
| 176 deps = invoker.deps |
| 149 outputs = [ | 177 outputs = [ |
| 150 "$root_build_dir/${_app_name}.app/Info.plist", | 178 "$root_build_dir/$_app_name.app/{{source_file_part}}", |
| 151 ] | |
| 152 | |
| 153 args = [ | |
| 154 "plist", | |
| 155 "-i", | |
| 156 rebase_path(invoker.info_plist, root_build_dir), | |
| 157 "-o", | |
| 158 rebase_path("$root_build_dir/${_app_name}.app"), | |
| 159 ] | 179 ] |
| 160 } | 180 } |
| 161 | 181 |
| 162 # Perform Code Signing | 182 # Perform Code Signing |
| 163 entitlements_path = invoker.entitlements_path | 183 entitlements_path = invoker.entitlements_path |
| 164 if (invoker.code_signing_identity != "") { | 184 if (invoker.code_signing_identity != "") { |
| 165 code_sign_gen_target_name = target_name + "_codesign" | 185 code_sign_gen_target_name = target_name + "_codesign" |
| 166 code_sign_ios(code_sign_gen_target_name) { | 186 code_sign_ios(code_sign_gen_target_name) { |
| 167 visibility = [ ":$target_name" ] | 187 visibility = [ ":$target_name" ] |
| 168 | 188 |
| 169 identity = invoker.code_signing_identity | 189 identity = invoker.code_signing_identity |
| 170 application_path = "$root_build_dir/$app_name.app" | 190 application_path = "$root_build_dir/$app_name.app" |
| 171 deps = [ | 191 deps = [ |
| 172 ":$bin_gen_target_name", | 192 ":$bin_gen_target_name", |
| 173 ":$plist_gen_target_name", | 193 ":$plist_gen_target_name", |
| 194 ":$res_gen_target_name", |
| 174 ] | 195 ] |
| 175 } | 196 } |
| 176 } else { | 197 } else { |
| 177 # This avoids a potential unused variable warning in the caller. | 198 # This avoids a potential unused variable warning in the caller. |
| 178 entitlements_path = entitlements_path | 199 entitlements_path = entitlements_path |
| 179 } | 200 } |
| 180 | 201 |
| 181 # Top level group | 202 # Top level group |
| 182 group(target_name) { | 203 group(target_name) { |
| 183 deps = [ | 204 deps = [ |
| 184 ":$bin_gen_target_name", | 205 ":$bin_gen_target_name", |
| 185 ":$plist_gen_target_name", | 206 ":$plist_gen_target_name", |
| 207 ":$res_gen_target_name", |
| 186 ] | 208 ] |
| 187 if (invoker.code_signing_identity != "") { | 209 if (invoker.code_signing_identity != "") { |
| 188 deps += [ ":$code_sign_gen_target_name" ] | 210 deps += [ ":$code_sign_gen_target_name" ] |
| 189 } | 211 } |
| 190 } | 212 } |
| 191 } | 213 } |
| 214 |
| 215 # Use this template to create test application bundle for iOS. |
| 216 # |
| 217 # Arguments: |
| 218 # |
| 219 # bundle_test_name (optional) |
| 220 # String to use as bundle identifier in the Info.plist. Default to |
| 221 # ${app_name}. |
| 222 # |
| 223 # test_data_files (optional) |
| 224 # List of file to copy in the application bundle. The path in the |
| 225 # bundle will be the same as the path from the source root, unless |
| 226 # test_data_prefix is defined. |
| 227 # |
| 228 # test_data_prefix (optional) |
| 229 # If defined, ${test_data_files} will be copied to this directory |
| 230 # relative to the application bundle instead of a path relative to |
| 231 # source root. |
| 232 # |
| 233 # info_plist (optional) |
| 234 # Path to the application Info.plist template (variable substitution |
| 235 # will be performed). |
| 236 # |
| 237 # entitlements_path (optional) |
| 238 # Path to the application entitlements .xcent. |
| 239 # |
| 240 # code_signing_identity (optional) |
| 241 # Identity to use for signing the application, if signing is enabled. |
| 242 # |
| 243 # app_name (optional) |
| 244 # Name of the application, defaults to ${target_name}. |
| 245 # |
| 246 # extra_pattern_substitution (optional) |
| 247 # List of string in "key=value" format. Each correspond to variable |
| 248 # substitution to perform when compiling the Info.plist template. |
| 249 # |
| 250 # The template uses an "ios_app" target under the hood and forwards to it |
| 251 # all the arguments it supports. Look at "executable" documentation for more |
| 252 # information. |
| 253 template("ios_test_app") { |
| 254 _app_name = target_name |
| 255 if (defined(invoker.app_name)) { |
| 256 _app_name = invoker.app_name |
| 257 } |
| 258 |
| 259 _has_test_data = defined(invoker.test_data_files) |
| 260 if (_has_test_data) { |
| 261 _copy_test_data_target_name = target_name + "__test_data" |
| 262 _copy_test_data_target_dir = "$root_build_dir/$_app_name.app" |
| 263 if (defined(invoker.test_data_prefix)) { |
| 264 _copy_test_data_target_dir += "/${invoker.test_data_prefix}" |
| 265 } else { |
| 266 _copy_test_data_target_dir += "/{{source_root_relative_dir}}" |
| 267 } |
| 268 |
| 269 copy(_copy_test_data_target_name) { |
| 270 sources = invoker.test_data_files |
| 271 outputs = [ |
| 272 "$_copy_test_data_target_dir/{{source_file_part}}", |
| 273 ] |
| 274 } |
| 275 } |
| 276 |
| 277 _default_bundle_config_name = target_name + "__config" |
| 278 _default_bundle_target_name = target_name + "__bundle" |
| 279 config(_default_bundle_config_name) { |
| 280 bundle_data = [ "//testing/gtest_ios/Default.png" ] |
| 281 } |
| 282 |
| 283 group(_default_bundle_target_name) { |
| 284 all_dependent_configs = [ ":$_default_bundle_config_name" ] |
| 285 } |
| 286 |
| 287 ios_app(target_name) { |
| 288 app_name = _app_name |
| 289 testonly = true |
| 290 |
| 291 _bundle_test_name = _app_name |
| 292 if (defined(invoker.bundle_test_name)) { |
| 293 _bundle_test_name = invoker.bundle_test_name |
| 294 } |
| 295 |
| 296 extra_pattern_substitution = [ "BUNDLE_ID_TEST_NAME=$_bundle_test_name" ] |
| 297 |
| 298 entitlements_path = "" |
| 299 if (defined(invoker.entitlements_path)) { |
| 300 entitlements_path = invoker.entitlements_path |
| 301 } |
| 302 |
| 303 info_plist = "//testing/gtest_ios/unittest-Info.plist" |
| 304 if (defined(invoker.info_plist)) { |
| 305 info_plist = invoker.info_plist |
| 306 } |
| 307 |
| 308 code_signing_identity = ios_code_signing_identity |
| 309 if (defined(invoker.code_signing_identity)) { |
| 310 code_signing_identity = invoker.code_signing_identity |
| 311 } |
| 312 |
| 313 forward_variables_from(invoker, |
| 314 [ |
| 315 "all_dependent_configs", |
| 316 "allow_circular_includes_from", |
| 317 "cflags", |
| 318 "cflags_c", |
| 319 "cflags_cc", |
| 320 "cflags_objc", |
| 321 "cflags_objcc", |
| 322 "check_includes", |
| 323 "configs", |
| 324 "data", |
| 325 "data_deps", |
| 326 "defines", |
| 327 "deps", |
| 328 "include_dirs", |
| 329 "ldflags", |
| 330 "libs", |
| 331 "output_extension", |
| 332 "public", |
| 333 "public_configs", |
| 334 "public_deps", |
| 335 "sources", |
| 336 "visibility", |
| 337 ]) |
| 338 |
| 339 if (!defined(invoker.deps)) { |
| 340 deps = [] |
| 341 } |
| 342 if (_has_test_data) { |
| 343 deps += [ ":$_copy_test_data_target_name" ] |
| 344 } |
| 345 deps += [ ":$_default_bundle_target_name" ] |
| 346 } |
| 347 } |
| OLD | NEW |