OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 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 # This file contains rules that are shared between Mac and iOS. | 5 # This file contains rules that are shared between Mac and iOS. |
6 | 6 |
7 import("//build/toolchain/toolchain.gni") | 7 import("//build/toolchain/toolchain.gni") |
8 import("//build/config/mac/symbols.gni") | 8 import("//build/config/mac/symbols.gni") |
9 | 9 |
10 if (is_mac) { | 10 if (is_mac) { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 args = [ "@{{response_file_name}}" ] | 119 args = [ "@{{response_file_name}}" ] |
120 forward_variables_from(invoker, | 120 forward_variables_from(invoker, |
121 [ | 121 [ |
122 "deps", | 122 "deps", |
123 "testonly", | 123 "testonly", |
124 "visibility", | 124 "visibility", |
125 ]) | 125 ]) |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 # This is used as the base template for both iOS and Mac frameworks. | |
130 # | |
131 # By default, the bundle target this template generates does not link the | |
132 # resulting framework into anything that depends on it. If a dependency wants | |
133 # a link-time (as well as build-time) dependency on the framework bundle, | |
134 # depend against "$target_name+link". If only the build-time dependency is | |
135 # required (e.g., for copying into another bundle), then use "$target_name". | |
136 # | |
137 # Arguments | |
138 # | |
139 # output_name: | |
140 # (optional) string, name of the generated framework without the | |
141 # .framework suffix. If omitted, defaults to target_name. | |
142 # | |
143 # framework_version: | |
144 # (optional) string, version of the framework. Typically this is a | |
145 # single letter, like "A". If omitted, the Versions/ subdirectory | |
146 # structure will not be created, and build output will go directly | |
147 # into the framework subdirectory. | |
148 # | |
149 # This template provides two targets for the resulting framework bundle. The | |
150 # link-time behavior varies depending on which of the two targets below is | |
151 # added as a dependency: | |
152 # - $target_name only adds a build-time dependency. Targets that depend on | |
153 # it will not link against the framework. | |
154 # - $target_name+link adds a build-time and link-time dependency. Targets | |
155 # that depend on it will link against the framework. | |
156 # | |
157 # The build-time-only dependency is used for when a target needs to use the | |
158 # framework either only for resources, or because the target loads it at run- | |
159 # time, via dlopen() or NSBundle. The link-time dependency will cause the | |
160 # dependee to have the framework loaded by dyld at launch. | |
161 # | |
162 # Example of build-time only dependency: | |
163 # | |
164 # framework_bundle("CoreTeleportation") { | |
165 # sources = [ ... ] | |
166 # } | |
167 # | |
168 # bundle_data("core_teleportation_bundle_data") { | |
169 # deps = [ ":CoreTeleportation" ] | |
170 # sources = [ "$root_out_dir/CoreTeleportation.framework" ] | |
171 # outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] | |
172 # } | |
173 # | |
174 # app_bundle("GoatTeleporter") { | |
175 # sources = [ ... ] | |
176 # deps = [ | |
177 # ":core_teleportation_bundle_data", | |
178 # ] | |
179 # } | |
180 # | |
181 # The GoatTeleporter.app will not directly link against | |
182 # CoreTeleportation.framework, but it will be included in the bundle's | |
183 # Frameworks directory. | |
184 # | |
185 # Example of link-time dependency: | |
186 # | |
187 # framework_bundle("CoreTeleportation") { | |
188 # sources = [ ... ] | |
189 # ldflags = [ | |
190 # "-install_name", | |
191 # "@executable_path/../Frameworks/$target_name.framework" | |
192 # ] | |
193 # } | |
194 # | |
195 # bundle_data("core_teleportation_bundle_data") { | |
196 # deps = [ ":CoreTeleportation+link" ] | |
197 # sources = [ "$root_out_dir/CoreTeleportation.framework" ] | |
198 # outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] | |
199 # } | |
200 # | |
201 # app_bundle("GoatTeleporter") { | |
202 # sources = [ ... ] | |
203 # deps = [ | |
204 # ":core_teleportation_bundle_data", | |
205 # ] | |
206 # } | |
207 # | |
208 # Note that the framework is still copied to the app's bundle, but dyld will | |
209 # load this library when the app is launched because it uses the "+link" | |
210 # target as a dependency. This also requires that the framework set its | |
211 # install_name so that dyld can locate it. | |
212 # | |
213 # See "gn help shared_library" for more information on arguments supported | |
214 # by shared library target. | |
215 template("framework_bundle") { | |
216 _target_name = target_name | |
217 _output_name = target_name | |
218 if (defined(invoker.output_name)) { | |
219 _output_name = invoker.output_name | |
220 } | |
221 | |
222 _is_fat_build = is_ios && additional_toolchains != [] | |
223 if (_is_fat_build) { | |
224 _is_fat_build_main_target = current_toolchain == default_toolchain | |
225 } | |
226 | |
227 # The expansion of the template is different for fat and thin builds. For | |
228 # thin build (and default toolchain of a fat build), the template expands | |
229 # to a "shared_library" target to create the bundle shared library and a | |
230 # "create_bundle" target (the main target) to create the bundle structure. | |
231 # | |
232 # For a fat build, the template just expands to the "shared_library" target | |
233 # for the non-default toolchain, while the final library is created using | |
234 # "lipo" in the expansion of the template for the default toolchain. | |
235 # | |
236 # The "$target_name+link" group for the non-default toolchain depends on the | |
237 # target of the same name from the default toolchain as this is the target | |
238 # that defines the real framework bundle (it will support the current cpu | |
239 # as it is a fat framework). | |
240 | |
241 if (_is_fat_build && !_is_fat_build_main_target) { | |
242 shared_library(_target_name) { | |
243 forward_variables_from(invoker, | |
244 "*", | |
245 [ | |
246 "assert_no_deps", | |
247 "bundle_deps", | |
248 "code_signing_enabled", | |
249 "data_deps", | |
250 "info_plist", | |
251 "info_plist_target", | |
252 "output_name", | |
253 ]) | |
254 if (defined(visibility)) { | |
255 visibility += [ ":${_target_name}_shared_library($default_toolchain)" ] | |
256 } | |
257 output_name = _output_name | |
258 output_prefix_override = true | |
259 output_extension = "" | |
260 output_dir = "$target_out_dir/$_target_name" | |
261 } | |
262 | |
263 group(_target_name + "+link") { | |
264 forward_variables_from(invoker, | |
265 [ | |
266 "visibility", | |
267 "testonly", | |
268 ]) | |
269 public_deps = [ | |
270 ":$_target_name($default_toolchain)", | |
271 ] | |
272 } | |
273 | |
274 if (defined(invoker.bundle_deps)) { | |
275 assert(invoker.bundle_deps != [], "mark bundle_deps as used") | |
276 } | |
277 } else { | |
278 _code_signing_enabled = is_ios && ios_enable_code_signing | |
279 if (defined(invoker.code_signing_enabled)) { | |
280 _code_signing_enabled = | |
281 invoker.code_signing_enabled && _code_signing_enabled | |
282 } | |
283 | |
284 # If the framework is unversioned, the final _target_name will be the | |
285 # create_bundle(_framework_target), otherwise an action with the name | |
286 # _target_name will depends on the the create_bundle() in order to prepare | |
287 # the versioned directory structure. | |
288 _framework_target = _target_name | |
289 _framework_name = _output_name + ".framework" | |
290 _framework_root_dir = "$root_out_dir/$_framework_name" | |
291 if (defined(invoker.framework_version) && invoker.framework_version != "") { | |
292 _framework_version = invoker.framework_version | |
293 _framework_root_dir += "/Versions/$_framework_version" | |
294 _framework_target = _target_name + "_create_bundle" | |
295 } | |
296 | |
297 _link_shared_library_target = target_name + "_shared_library" | |
298 _shared_library_dir = "$target_out_dir/$_link_shared_library_target" | |
299 | |
300 if (_code_signing_enabled) { | |
301 _link_shared_library_visibility = [ ":$_framework_target" ] | |
302 } else { | |
303 _shared_library_bundle_data = target_name + "_shared_library_bundle_data" | |
304 _link_shared_library_visibility = [ ":$_shared_library_bundle_data" ] | |
305 } | |
306 | |
307 if (_is_fat_build) { | |
308 _lipo_shared_library_target = _link_shared_library_target | |
309 _lipo_shared_library_visibility = _link_shared_library_visibility | |
310 | |
311 _link_shared_library_visibility = [] | |
312 _link_shared_library_visibility = [ ":$_lipo_shared_library_target" ] | |
313 _link_shared_library_target = target_name + "_arch_shared_library" | |
314 | |
315 _arch_shared_library_dir = "$target_out_dir/$_link_shared_library_target" | |
316 _shared_library_dir = "$target_out_dir/$_lipo_shared_library_target" | |
317 } | |
318 | |
319 shared_library(_link_shared_library_target) { | |
320 forward_variables_from(invoker, | |
321 "*", | |
322 [ | |
323 "assert_no_deps", | |
324 "bundle_deps", | |
325 "code_signing_enabled", | |
326 "data_deps", | |
327 "info_plist", | |
328 "output_name", | |
329 "visibility", | |
330 ]) | |
331 visibility = _link_shared_library_visibility | |
332 output_name = _output_name | |
333 output_prefix_override = true | |
334 output_extension = "" | |
335 | |
336 if (!_is_fat_build) { | |
337 output_dir = _shared_library_dir | |
338 } else { | |
339 output_dir = _arch_shared_library_dir | |
340 } | |
341 } | |
342 | |
343 if (_is_fat_build) { | |
344 action(_lipo_shared_library_target) { | |
345 forward_variables_from(invoker, [ "testonly" ]) | |
346 visibility = _lipo_shared_library_visibility | |
347 script = "//build/toolchain/mac/linker_driver.py" | |
348 outputs = [ | |
349 "$_shared_library_dir/$_output_name", | |
350 ] | |
351 inputs = [ | |
352 "$_arch_shared_library_dir/$_output_name", | |
353 ] | |
354 deps = [ | |
355 ":$_link_shared_library_target", | |
356 ] | |
357 foreach(_additional_toolchain, additional_toolchains) { | |
358 _additional_toolchain_target = "$_target_name($_additional_toolchain)" | |
359 deps += [ ":$_additional_toolchain_target" ] | |
360 inputs += [ get_label_info(_additional_toolchain_target, | |
361 "target_out_dir") + "/$_output_name" ] | |
362 } | |
363 args = [ | |
364 "xcrun", | |
365 "lipo", | |
366 "-create", | |
367 "-output", | |
368 rebase_path(outputs[0], root_build_dir), | |
369 ] + rebase_path(inputs, root_build_dir) | |
370 | |
371 if (enable_dsyms) { | |
372 outputs += [ "$root_out_dir/$_output_name.dSYM/" ] | |
373 args += | |
374 [ "-Wcrl,dsym," + rebase_path("$root_out_dir/.", root_build_dir) ] | |
375 } | |
376 | |
377 if (enable_stripping) { | |
378 # Check whether //build/config/mac:strip_all has been removed from | |
379 # the configs variable (as this is how stripping is disabled for a | |
380 # single target). | |
381 _strip_all_in_config = false | |
382 if (defined(invoker.configs)) { | |
383 foreach(_config, invoker.configs) { | |
384 if (_config == "//build/config/mac:strip_all") { | |
385 _strip_all_in_config = true | |
386 } | |
387 } | |
388 } | |
389 | |
390 if (_strip_all_in_config) { | |
391 args += [ "-Wcrl,strip,-x,-S" ] | |
392 | |
393 if (save_unstripped_output) { | |
394 outputs += [ outputs[0] + ".unstripped" ] | |
395 args += [ "-Wcrl,unstripped," + | |
396 rebase_path(get_path_info(outputs[0], "dir"), | |
397 root_build_dir) ] | |
398 } | |
399 } | |
400 } | |
401 } | |
402 } | |
403 | |
404 if (!_code_signing_enabled) { | |
405 bundle_data(_shared_library_bundle_data) { | |
406 visibility = [ ":$_framework_target" ] | |
407 forward_variables_from(invoker, [ "testonly" ]) | |
408 sources = [ | |
409 "$_shared_library_dir/$_output_name", | |
410 ] | |
411 outputs = [ | |
412 "{{bundle_executable_dir}}/$_output_name", | |
413 ] | |
414 if (_is_fat_build) { | |
415 public_deps = [ | |
416 ":$_lipo_shared_library_target", | |
417 ] | |
418 } else { | |
419 public_deps = [ | |
420 ":$_link_shared_library_target", | |
421 ] | |
422 } | |
423 } | |
424 } | |
425 | |
426 _framework_public_config = _target_name + "_public_config" | |
427 config(_framework_public_config) { | |
428 # TODO(sdefresne): should we have a framework_dirs similar to lib_dirs | |
429 # and include_dirs to avoid duplicate values on the command-line. | |
430 visibility = [ ":$_framework_target" ] | |
431 ldflags = [ | |
432 "-F", | |
433 rebase_path("$root_out_dir/.", root_build_dir), | |
434 ] | |
435 lib_dirs = [ root_out_dir ] | |
436 libs = [ _framework_name ] | |
437 } | |
438 | |
439 create_bundle(_framework_target) { | |
440 forward_variables_from(invoker, | |
441 [ | |
442 "data_deps", | |
443 "deps", | |
444 "public_deps", | |
445 "testonly", | |
446 ]) | |
447 | |
448 if (defined(_framework_version)) { | |
449 visibility = [ ":$_target_name" ] | |
450 } else { | |
451 if (defined(invoker.visibility)) { | |
452 visibility = invoker.visibility | |
453 visibility += [ ":$_target_name+link" ] | |
454 } | |
455 } | |
456 | |
457 if (defined(invoker.bundle_deps)) { | |
458 if (!defined(deps)) { | |
459 deps = [] | |
460 } | |
461 deps += invoker.bundle_deps | |
462 } | |
463 | |
464 if (!_code_signing_enabled) { | |
465 if (!defined(public_deps)) { | |
466 public_deps = [] | |
467 } | |
468 public_deps += [ ":$_shared_library_bundle_data" ] | |
469 } | |
470 | |
471 bundle_root_dir = _framework_root_dir | |
472 bundle_resources_dir = "$bundle_root_dir/Resources" | |
473 bundle_executable_dir = "$bundle_root_dir" | |
474 | |
475 if (_code_signing_enabled) { | |
476 if (!defined(deps)) { | |
477 deps = [] | |
478 } | |
479 | |
480 if (_is_fat_build) { | |
481 deps += [ ":$_lipo_shared_library_target" ] | |
482 } else { | |
483 deps += [ ":$_link_shared_library_target" ] | |
484 } | |
485 | |
486 _entitlements_path = "//build/config/ios/entitlements.plist" | |
487 if (defined(invoker.entitlements_path)) { | |
488 _entitlements_path = invoker.entitlements_path | |
489 } | |
490 | |
491 code_signing_script = "//build/config/ios/codesign.py" | |
492 code_signing_sources = [ | |
493 _entitlements_path, | |
494 "$_shared_library_dir/$_output_name", | |
495 ] | |
496 code_signing_outputs = [ | |
497 "$bundle_root_dir/$_output_name", | |
498 "$bundle_root_dir/_CodeSignature/CodeResources", | |
499 "$bundle_root_dir/embedded.mobileprovision", | |
500 ] | |
501 code_signing_args = [ | |
502 "-e=" + rebase_path(_entitlements_path, root_build_dir), | |
503 "code-sign-bundle", | |
504 "-i=" + ios_code_signing_identity, | |
505 "-b=" + | |
506 rebase_path("$_shared_library_dir/$_output_name", root_build_dir), | |
507 rebase_path(bundle_root_dir, root_build_dir), | |
508 ] | |
509 } | |
510 } | |
511 | |
512 if (defined(_framework_version)) { | |
513 action(_target_name) { | |
514 forward_variables_from(invoker, [ "testonly" ]) | |
515 | |
516 if (defined(invoker.visibility)) { | |
517 visibility = invoker.visibility | |
518 visibility += [ ":$_target_name+link" ] | |
519 } | |
520 | |
521 script = "//build/config/mac/package_framework.py" | |
522 outputs = [ | |
523 "$root_out_dir/$_framework_name/Versions/Current", | |
524 ] | |
525 args = [ | |
526 "$_framework_name", | |
527 "$_framework_version", | |
528 ] | |
529 public_deps = [ | |
530 ":$_framework_target", | |
531 ] | |
532 } | |
533 } | |
534 | |
535 group(_target_name + "+link") { | |
536 forward_variables_from(invoker, | |
537 [ | |
538 "public_configs", | |
539 "testonly", | |
540 "visibility", | |
541 ]) | |
542 public_deps = [ | |
543 ":$_target_name", | |
544 ] | |
545 if (!defined(public_configs)) { | |
546 public_configs = [] | |
547 } | |
548 public_configs += [ ":$_framework_public_config" ] | |
549 } | |
550 } | |
551 } | |
552 | |
553 # Template to combile .xib or .storyboard files. | 129 # Template to combile .xib or .storyboard files. |
554 # | 130 # |
555 # Arguments | 131 # Arguments |
556 # | 132 # |
557 # sources: | 133 # sources: |
558 # list of string, sources to compile | 134 # list of string, sources to compile |
559 # | 135 # |
560 # ibtool_flags: | 136 # ibtool_flags: |
561 # (optional) list of string, additional flags to pass to the ibtool | 137 # (optional) list of string, additional flags to pass to the ibtool |
562 template("compile_xibs") { | 138 template("compile_xibs") { |
(...skipping 18 matching lines...) Expand all Loading... |
581 ] | 157 ] |
582 args = | 158 args = |
583 [ | 159 [ |
584 "--input", | 160 "--input", |
585 "{{source}}", | 161 "{{source}}", |
586 "--output", | 162 "--output", |
587 rebase_path("$target_gen_dir/$target_name/{{source_name_part}}.nib"), | 163 rebase_path("$target_gen_dir/$target_name/{{source_name_part}}.nib"), |
588 ] + ibtool_flags | 164 ] + ibtool_flags |
589 } | 165 } |
590 } | 166 } |
OLD | NEW |