Chromium Code Reviews| 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 import("//build/config/ios/ios_sdk.gni") | 5 import("//build/config/ios/ios_sdk.gni") |
| 6 import("//build/config/mac/base_rules.gni") | 6 import("//build/config/mac/base_rules.gni") |
| 7 | 7 |
| 8 # Generates Info.plist files for Mac apps and frameworks. | 8 # Generates Info.plist files for Mac apps and frameworks. |
| 9 # | 9 # |
| 10 # Arguments | 10 # Arguments |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 } | 63 } |
| 64 forward_variables_from(invoker, | 64 forward_variables_from(invoker, |
| 65 [ | 65 [ |
| 66 "executable_name", | 66 "executable_name", |
| 67 "output_name", | 67 "output_name", |
| 68 "visibility", | 68 "visibility", |
| 69 ]) | 69 ]) |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 # TODO(crbug.com/297668): refactor this template to extract common behaviour | |
| 74 # between OS X and iOS bundle generation, then create a generic "app" template | |
| 75 # that forward to "executable" on all platform except iOS/OS X. | |
| 76 | |
| 77 # Template to build an application bundle for iOS. | 73 # Template to build an application bundle for iOS. |
| 78 # | 74 # |
| 79 # This should be used instead of "executable" built-in target type on iOS. | 75 # This should be used instead of "executable" built-in target type on iOS. |
| 80 # As the template forward the generation of the application executable to | 76 # As the template forward the generation of the application executable to |
| 81 # an "executable" target, all arguments supported by "executable" targets | 77 # an "executable" target, all arguments supported by "executable" targets |
| 82 # are also supported by this template. | 78 # are also supported by this template. |
| 83 # | 79 # |
| 84 # Arguments | 80 # Arguments |
| 85 # | 81 # |
| 86 # output_name: | 82 # output_name: |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 115 # not be overridden. | 111 # not be overridden. |
| 116 # | 112 # |
| 117 # For more information, see "gn help executable". | 113 # For more information, see "gn help executable". |
| 118 template("ios_app_bundle") { | 114 template("ios_app_bundle") { |
| 119 _output_name = target_name | 115 _output_name = target_name |
| 120 _target_name = target_name | 116 _target_name = target_name |
| 121 if (defined(invoker.output_name)) { | 117 if (defined(invoker.output_name)) { |
| 122 _output_name = invoker.output_name | 118 _output_name = invoker.output_name |
| 123 } | 119 } |
| 124 | 120 |
| 125 _generate_info_plist = target_name + "_generate_info_plist" | 121 # This template expands to multiple targets with some differences between |
| 126 _bundle_data_info_plist = target_name + "_bundle_data_info_plist" | 122 # the the different build configuration. |
| 127 | 123 # |
| 128 ios_info_plist(_generate_info_plist) { | 124 # For a regular build (i.e. when multi_arch_target_cpus is an empty list), |
|
Robert Sesek
2016/07/08 18:17:54
Maybe use "thin" instead of "regular" as that's th
sdefresne
2016/07/11 13:44:38
Done.
| |
| 129 executable_name = _output_name | 125 # it compiles the final application binary with an "executable" target, |
| 130 forward_variables_from(invoker, | 126 # performs variable expansions on the Info.plist, defines some "bundle_data" |
| 131 [ | 127 # target to pack Info.plist and the executable into the .app bundle, and |
| 132 "extra_substitutions", | 128 # finally a "create_bundle" target that packs everything the bundle. If the |
| 133 "info_plist", | 129 # bundle needs to be signed, then the binary is copied into the bundle by |
| 134 "info_plist_target", | 130 # the "create_bundle" target and the intermediate "bundle_data" target is |
| 135 ]) | 131 # not generated. |
| 136 } | 132 # |
| 137 | 133 # For a multi-architecture build (aka fat-build), the template expands to |
| 138 bundle_data(_bundle_data_info_plist) { | 134 # a simple "executable" target for non-default toolchain. This is because |
| 139 forward_variables_from(invoker, [ "testonly" ]) | 135 # the real application bundle will contains a single binary that supports |
| 140 visibility = [ ":$_target_name" ] | 136 # all the architectures and creating a separate .app bundle for every |
| 141 sources = get_target_outputs(":$_generate_info_plist") | 137 # architecture would be a waste of time. |
| 142 outputs = [ | 138 # |
| 143 "{{bundle_root_dir}}/Info.plist", | 139 # The target for the default toolchain of a multi-architecture build will |
| 144 ] | 140 # build the executable for current_cpu in a temporary location. The real |
| 145 public_deps = [ | 141 # fat binary will be created by "lipo" command from all those "executable" |
| 146 ":$_generate_info_plist", | 142 # target (including those of the non-default toolchains). This additional |
| 147 ] | 143 # target has the same role as the "executable" target of a regular build. |
| 148 } | 144 # |
| 149 | 145 # The rest of the build, including the codesigning step, are the same for |
| 150 _generate_executable = target_name + "_generate_executable" | 146 # regular and fat builds. |
| 151 if (!ios_enable_code_signing) { | 147 |
| 152 _bundle_data_executable = target_name + "_bundle_data_executable" | 148 _is_fat_build = multi_arch_toolchains != [] |
| 153 } | 149 if (_is_fat_build) { |
| 154 | 150 _is_fat_build_main_target = current_toolchain == default_toolchain |
| 155 executable(_generate_executable) { | 151 } |
| 156 if (ios_enable_code_signing) { | 152 |
| 153 if (_is_fat_build && !_is_fat_build_main_target) { | |
| 154 # For the non-default toolchain of a fat-build, the template expands to a | |
| 155 # single "executable" target that creates "$root_out_dir/$_output_name". | |
| 156 executable(_target_name) { | |
| 157 forward_variables_from(invoker, | |
| 158 "*", | |
| 159 [ | |
| 160 "bundle_extension", | |
| 161 "entitlements_path", | |
| 162 "extra_substitutions", | |
| 163 "info_plist", | |
| 164 "info_plist_target", | |
| 165 "output_name", | |
| 166 "product_type", | |
| 167 ]) | |
| 168 | |
| 169 if (defined(visibility)) { | |
| 170 visibility += [ ":*($default_toolchain)" ] | |
| 171 } | |
| 172 | |
| 173 output_name = _output_name | |
| 174 if (!defined(libs)) { | |
| 175 libs = [] | |
| 176 } | |
| 177 libs += [ "UIKit.framework" ] | |
| 178 if (!defined(ldflags)) { | |
| 179 ldflags = [] | |
| 180 } | |
| 181 ldflags += [ "-ObjC" ] | |
| 182 } | |
| 183 } else { | |
| 184 # This is either a regular build or the default toolchain of a fat-build. | |
|
Robert Sesek
2016/07/08 18:17:54
regular -> thin
sdefresne
2016/07/11 13:44:37
Done.
| |
| 185 # The template will expand in many different target ($target_name is the | |
| 186 # create_bundle target) used as input to the create_bundle target. | |
| 187 _generate_info_plist = target_name + "_generate_info_plist" | |
| 188 _bundle_data_info_plist = target_name + "_bundle_data_info_plist" | |
| 189 | |
| 190 ios_info_plist(_generate_info_plist) { | |
| 191 visibility = [ ":$_bundle_data_info_plist" ] | |
| 192 executable_name = _output_name | |
| 193 forward_variables_from(invoker, | |
| 194 [ | |
| 195 "extra_substitutions", | |
| 196 "info_plist", | |
| 197 "info_plist_target", | |
| 198 ]) | |
| 199 } | |
| 200 | |
| 201 bundle_data(_bundle_data_info_plist) { | |
| 157 visibility = [ ":$_target_name" ] | 202 visibility = [ ":$_target_name" ] |
| 158 } else { | |
| 159 visibility = [ ":$_bundle_data_executable" ] | |
| 160 } | |
| 161 forward_variables_from(invoker, | |
| 162 "*", | |
| 163 [ | |
| 164 "bundle_extension", | |
| 165 "data_deps", | |
| 166 "entitlements_path", | |
| 167 "info_plist", | |
| 168 "info_plist_target", | |
| 169 "output_name", | |
| 170 "product_type", | |
| 171 "visibility", | |
| 172 ]) | |
| 173 | |
| 174 output_name = rebase_path("$target_gen_dir/$_output_name", root_out_dir) | |
| 175 output_prefix_override = true | |
| 176 | |
| 177 if (!defined(libs)) { | |
| 178 libs = [] | |
| 179 } | |
| 180 libs += [ "UIKit.framework" ] | |
| 181 if (!defined(ldflags)) { | |
| 182 ldflags = [] | |
| 183 } | |
| 184 ldflags += [ "-ObjC" ] | |
| 185 } | |
| 186 | |
| 187 if (!ios_enable_code_signing) { | |
| 188 bundle_data(_bundle_data_executable) { | |
| 189 forward_variables_from(invoker, [ "testonly" ]) | 203 forward_variables_from(invoker, [ "testonly" ]) |
| 190 visibility = [ ":$_target_name" ] | 204 sources = get_target_outputs(":$_generate_info_plist") |
| 191 sources = [ | |
| 192 "$target_gen_dir/$_output_name", | |
| 193 ] | |
| 194 outputs = [ | 205 outputs = [ |
| 195 "{{bundle_executable_dir}}/$_output_name", | 206 "{{bundle_root_dir}}/Info.plist", |
| 196 ] | 207 ] |
| 197 public_deps = [ | 208 public_deps = [ |
| 198 ":$_generate_executable", | 209 ":$_generate_info_plist", |
| 199 ] | 210 ] |
| 200 } | 211 } |
| 201 } | 212 |
| 202 | 213 _link_executable = _target_name + "_link_executable" |
| 203 create_bundle(target_name) { | 214 _executable_path = "$target_gen_dir/$_output_name" |
| 204 forward_variables_from(invoker, | 215 |
| 205 [ | |
| 206 "data_deps", | |
| 207 "deps", | |
| 208 "public_deps", | |
| 209 "testonly", | |
| 210 "visibility", | |
| 211 ]) | |
| 212 | |
| 213 if (!defined(deps)) { | |
| 214 deps = [] | |
| 215 } | |
| 216 deps += [ ":$_bundle_data_info_plist" ] | |
| 217 if (ios_enable_code_signing) { | 216 if (ios_enable_code_signing) { |
| 218 deps += [ ":$_generate_executable" ] | 217 _link_executable_visibility = [ ":$_target_name" ] |
| 219 } else { | 218 } else { |
| 220 deps += [ ":$_bundle_data_executable" ] | 219 _bundle_data_executable = target_name + "_bundle_data_executable" |
| 221 } | 220 _link_executable_visibility = [ ":$_bundle_data_executable" ] |
| 222 | 221 } |
| 223 if (use_ios_simulator) { | 222 |
| 224 if (!defined(data_deps)) { | 223 # For a fat-build, the different "executable" outputs will be used to |
| 225 data_deps = [] | 224 # create the final binary using "lipo". As the corresponding target has |
| 226 } | 225 # the same role as the "executable" target in a regular build, copy the |
| 227 data_deps += [ "//testing/iossim" ] | 226 # visibility and redefine some variables. |
| 228 } | 227 if (_is_fat_build) { |
| 229 | 228 _lipo_executable = _target_name + "_lipo_executable" |
| 230 if (defined(invoker.product_type)) { | 229 _lipo_executable_visibility = _link_executable_visibility |
| 231 product_type = invoker.product_type | 230 |
| 232 } else { | 231 _link_executable_visibility = [] |
| 233 product_type = "com.apple.product-type.application" | 232 _link_executable_visibility = [ ":$_lipo_executable" ] |
| 234 } | 233 |
| 235 | 234 _arch_executable_path = "$target_gen_dir/$current_cpu/$_output_name" |
| 236 if (defined(invoker.bundle_extension)) { | 235 } |
| 237 _bundle_extension = invoker.bundle_extension | 236 |
| 238 } else { | 237 executable(_link_executable) { |
| 239 _bundle_extension = ".app" | 238 forward_variables_from(invoker, |
| 240 } | 239 "*", |
| 241 | 240 [ |
| 242 bundle_root_dir = "$root_out_dir/$_output_name$_bundle_extension" | 241 "bundle_extension", |
| 243 bundle_resources_dir = bundle_root_dir | 242 "data_deps", |
| 244 bundle_executable_dir = bundle_root_dir | 243 "entitlements_path", |
| 245 bundle_plugins_dir = "$bundle_root_dir/PlugIns" | 244 "extra_substitutions", |
| 246 | 245 "info_plist", |
| 247 if (defined(invoker.entitlements_path)) { | 246 "info_plist_target", |
| 248 _entitlements_path = invoker.entitlements_path | 247 "output_name", |
| 249 } else { | 248 "product_type", |
| 250 _entitlements_path = "$ios_sdk_path/Entitlements.plist" | 249 "visibility", |
| 251 } | 250 ]) |
| 252 | 251 |
| 253 if (ios_enable_code_signing) { | 252 visibility = _link_executable_visibility |
| 254 code_signing_script = "//build/config/ios/codesign.py" | 253 |
| 255 code_signing_sources = [ | 254 output_prefix_override = true |
| 256 _entitlements_path, | 255 if (_is_fat_build) { |
| 257 "$target_gen_dir/$_output_name", | 256 output_name = rebase_path(_arch_executable_path, root_build_dir) |
| 258 ] | 257 } else { |
| 259 code_signing_outputs = [ | 258 output_name = rebase_path(_executable_path, root_build_dir) |
| 260 "$bundle_root_dir/$_output_name", | 259 } |
| 261 "$bundle_root_dir/_CodeSignature/CodeResources", | 260 |
| 262 "$bundle_root_dir/embedded.mobileprovision", | 261 if (!defined(libs)) { |
| 263 ] | 262 libs = [] |
| 264 code_signing_args = [ | 263 } |
| 265 "-i=" + ios_code_signing_identity, | 264 libs += [ "UIKit.framework" ] |
| 266 "-b=" + rebase_path("$target_gen_dir/$_output_name", root_build_dir), | 265 if (!defined(ldflags)) { |
| 267 "-e=" + rebase_path(_entitlements_path, root_build_dir), | 266 ldflags = [] |
| 268 rebase_path(bundle_root_dir, root_build_dir), | 267 } |
| 269 ] | 268 ldflags += [ "-ObjC" ] |
| 270 } else { | 269 } |
| 271 assert(_entitlements_path != "", | 270 |
| 272 "force usage of _entitlements_path to avoid unused variable error") | 271 if (_is_fat_build) { |
| 273 } | 272 # Create the multi-architecture binary from all the single architecture |
| 273 # binaries using "lipo". This target exists for the default toolchain | |
| 274 # of a fat-build only and depends on the expansion of "ios_app_bundle" | |
| 275 # for the other toolchains (i.e. a single "executable" target). | |
| 276 # | |
| 277 # This action only happens once per "ios_app_bundle" template (for the | |
| 278 # main toolchain). | |
| 279 action(_lipo_executable) { | |
| 280 forward_variables_from(invoker, [ "testonly" ]) | |
| 281 visibility = _lipo_executable_visibility | |
| 282 script = "//build/config/mac/xcrun.py" | |
| 283 outputs = [ | |
| 284 _executable_path, | |
| 285 ] | |
| 286 inputs = [ | |
| 287 _arch_executable_path, | |
| 288 ] | |
| 289 deps = [ | |
| 290 ":$_link_executable", | |
| 291 ] | |
| 292 foreach(_toolchain, multi_arch_toolchains) { | |
| 293 _toolchain_target = "$_target_name($_toolchain)" | |
| 294 deps += [ ":$_toolchain_target" ] | |
| 295 inputs += [ get_label_info(_toolchain_target, "root_out_dir") + | |
| 296 "/$_output_name" ] | |
| 297 } | |
| 298 args = [ | |
| 299 "lipo", | |
| 300 "-create", | |
| 301 "-output", | |
| 302 rebase_path(outputs[0], root_build_dir), | |
| 303 ] + rebase_path(inputs, root_build_dir) | |
| 304 } | |
| 305 } | |
| 306 | |
| 307 if (!ios_enable_code_signing) { | |
| 308 # If codesigning is enabled, the binary will be copied into the bundle | |
| 309 # by the codesigning script (as the binary is updated by the signature). | |
| 310 # Otherwise, this "bundle_data" declares the location of the binary in | |
| 311 # the .app bundle. | |
| 312 bundle_data(_bundle_data_executable) { | |
| 313 forward_variables_from(invoker, [ "testonly" ]) | |
| 314 visibility = [ ":$_target_name" ] | |
| 315 outputs = [ | |
| 316 "{{bundle_executable_dir}}/$_output_name", | |
| 317 ] | |
| 318 if (_is_fat_build) { | |
| 319 public_deps = [ | |
| 320 ":$_lipo_executable", | |
| 321 ] | |
| 322 } else { | |
| 323 public_deps = [ | |
| 324 ":$_link_executable", | |
| 325 ] | |
| 326 } | |
| 327 sources = [ | |
| 328 "$target_gen_dir/$_output_name", | |
| 329 ] | |
| 330 } | |
| 331 } | |
| 332 | |
| 333 create_bundle(target_name) { | |
| 334 forward_variables_from(invoker, | |
| 335 [ | |
| 336 "data_deps", | |
| 337 "deps", | |
| 338 "public_deps", | |
| 339 "testonly", | |
| 340 "visibility", | |
| 341 ]) | |
| 342 | |
| 343 if (!defined(deps)) { | |
| 344 deps = [] | |
| 345 } | |
| 346 deps += [ ":$_bundle_data_info_plist" ] | |
| 347 if (ios_enable_code_signing) { | |
| 348 if (_is_fat_build) { | |
| 349 deps += [ ":$_lipo_executable" ] | |
| 350 } else { | |
| 351 deps += [ ":$_link_executable" ] | |
| 352 } | |
| 353 } else { | |
| 354 deps += [ ":$_bundle_data_executable" ] | |
| 355 } | |
| 356 | |
| 357 if (use_ios_simulator) { | |
| 358 if (!defined(data_deps)) { | |
| 359 data_deps = [] | |
| 360 } | |
| 361 data_deps += [ "//testing/iossim" ] | |
| 362 } | |
| 363 | |
| 364 if (defined(invoker.product_type)) { | |
| 365 product_type = invoker.product_type | |
| 366 } else { | |
| 367 product_type = "com.apple.product-type.application" | |
| 368 } | |
| 369 | |
| 370 if (defined(invoker.bundle_extension)) { | |
| 371 _bundle_extension = invoker.bundle_extension | |
| 372 } else { | |
| 373 _bundle_extension = ".app" | |
| 374 } | |
| 375 | |
| 376 bundle_root_dir = "$root_out_dir/$_output_name$_bundle_extension" | |
| 377 bundle_resources_dir = bundle_root_dir | |
| 378 bundle_executable_dir = bundle_root_dir | |
| 379 bundle_plugins_dir = "$bundle_root_dir/PlugIns" | |
| 380 | |
| 381 if (ios_enable_code_signing) { | |
| 382 _entitlements_path = "$ios_sdk_path/Entitlements.plist" | |
| 383 if (defined(invoker.entitlements_path)) { | |
| 384 _entitlements_path = invoker.entitlements_path | |
| 385 } | |
| 386 | |
| 387 code_signing_script = "//build/config/ios/codesign.py" | |
| 388 code_signing_sources = [ | |
| 389 _entitlements_path, | |
| 390 "$target_gen_dir/$_output_name", | |
| 391 ] | |
| 392 code_signing_outputs = [ | |
| 393 "$bundle_root_dir/$_output_name", | |
| 394 "$bundle_root_dir/_CodeSignature/CodeResources", | |
| 395 "$bundle_root_dir/embedded.mobileprovision", | |
| 396 ] | |
| 397 code_signing_args = [ | |
| 398 "-i=" + ios_code_signing_identity, | |
| 399 "-b=" + rebase_path("$target_gen_dir/$_output_name", root_build_dir), | |
| 400 "-e=" + rebase_path(_entitlements_path, root_build_dir), | |
| 401 rebase_path(bundle_root_dir, root_build_dir), | |
| 402 ] | |
| 403 } | |
| 404 } | |
| 405 } | |
| 406 | |
| 407 # TODO(crbug.com/395883): ensure those variables are marked as used to | |
| 408 # avoid errors while running "gn gen". | |
| 409 if (defined(invoker.entitlements_path)) { | |
| 410 assert(invoker.entitlements_path != "", | |
| 411 "mark invoker.entitlements_path as used") | |
| 412 } | |
| 413 if (defined(invoker.bundle_extension)) { | |
| 414 assert(invoker.bundle_extension != "", | |
| 415 "mark invoker.bundle_extension as used") | |
| 416 } | |
| 417 if (defined(invoker.bundle_extension)) { | |
| 418 assert(invoker.bundle_extension != "", | |
| 419 "mark invoker.bundle_extension as used") | |
| 420 } | |
| 421 if (defined(invoker.entitlements_path)) { | |
| 422 assert(invoker.entitlements_path != "", | |
| 423 "mark invoker.entitlements_path as used") | |
| 424 } | |
| 425 if (defined(invoker.extra_substitutions)) { | |
| 426 assert(invoker.extra_substitutions != [], | |
| 427 "mark invoker.extra_substitutions as used") | |
| 428 } | |
| 429 if (defined(invoker.info_plist)) { | |
| 430 assert(invoker.info_plist != "", "mark invoker.info_plist as used") | |
| 431 } | |
| 432 if (defined(invoker.info_plist_target)) { | |
| 433 assert(invoker.info_plist_target != "", | |
| 434 "mark invoker.info_plist_target as used") | |
| 435 } | |
| 436 if (defined(invoker.product_type)) { | |
| 437 assert(invoker.product_type != "", "mark product_type as used") | |
| 274 } | 438 } |
| 275 } | 439 } |
| 276 | 440 |
| 277 # Template to build an application extension bundle for iOS. | 441 # Template to build an application extension bundle for iOS. |
| 278 # | 442 # |
| 279 # This should be used instead of "executable" built-in target type on iOS. | 443 # This should be used instead of "executable" built-in target type on iOS. |
| 280 # As the template forward the generation of the application executable to | 444 # As the template forward the generation of the application executable to |
| 281 # an "executable" target, all arguments supported by "executable" targets | 445 # an "executable" target, all arguments supported by "executable" targets |
| 282 # are also supported by this template. | 446 # are also supported by this template. |
| 283 # | 447 # |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 613 [ | 777 [ |
| 614 "testonly", | 778 "testonly", |
| 615 "visibility", | 779 "visibility", |
| 616 ]) | 780 ]) |
| 617 public_deps = [ | 781 public_deps = [ |
| 618 ":$_framework_target+link", | 782 ":$_framework_target+link", |
| 619 ] | 783 ] |
| 620 } | 784 } |
| 621 } | 785 } |
| 622 } | 786 } |
| OLD | NEW |