Index: build/config/mac/rules.gni |
diff --git a/build/config/mac/rules.gni b/build/config/mac/rules.gni |
index a2213784c0285ebe48f16c7a29ead335adca714a..832f635955fed0269b23d9bb7ff53395e56c8fc6 100644 |
--- a/build/config/mac/rules.gni |
+++ b/build/config/mac/rules.gni |
@@ -116,12 +116,11 @@ template("mac_xib_bundle_data") { |
# Template to package a shared library into a Mac framework bundle. |
# |
-# This template provides two targets to control whether the framework is |
-# merely built when targets depend on it, or whether it is linked as well: |
-# "$target_name" and "$target_name+link". |
-# |
-# See the //build/config/mac/base_rules.gni:framework_bundle for a discussion |
-# and examples. |
+# By default, the bundle target this template generates does not link the |
+# resulting framework into anything that depends on it. If a dependency wants |
+# a link-time (as well as build-time) dependency on the framework bundle, |
+# depend against "$target_name+link". If only the build-time dependency is |
+# required (e.g., for copying into another bundle), then use "$target_name". |
# |
# Arguments |
# |
@@ -148,6 +147,70 @@ template("mac_xib_bundle_data") { |
# (optional) string array, 'key=value' pairs for extra fields which are |
# specified in a source Info.plist template. |
# |
+# This template provides two targets for the resulting framework bundle. The |
+# link-time behavior varies depending on which of the two targets below is |
+# added as a dependency: |
+# - $target_name only adds a build-time dependency. Targets that depend on |
+# it will not link against the framework. |
+# - $target_name+link adds a build-time and link-time dependency. Targets |
+# that depend on it will link against the framework. |
+# |
+# The build-time-only dependency is used for when a target needs to use the |
+# framework either only for resources, or because the target loads it at run- |
+# time, via dlopen() or NSBundle. The link-time dependency will cause the |
+# dependee to have the framework loaded by dyld at launch. |
+# |
+# Example of build-time only dependency: |
+# |
+# mac_framework_bundle("CoreTeleportation") { |
+# sources = [ ... ] |
+# } |
+# |
+# bundle_data("core_teleportation_bundle_data") { |
+# deps = [ ":CoreTeleportation" ] |
+# sources = [ "$root_out_dir/CoreTeleportation.framework" ] |
+# outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] |
+# } |
+# |
+# app_bundle("GoatTeleporter") { |
+# sources = [ ... ] |
+# deps = [ |
+# ":core_teleportation_bundle_data", |
+# ] |
+# } |
+# |
+# The GoatTeleporter.app will not directly link against |
+# CoreTeleportation.framework, but it will be included in the bundle's |
+# Frameworks directory. |
+# |
+# Example of link-time dependency: |
+# |
+# mac_framework_bundle("CoreTeleportation") { |
+# sources = [ ... ] |
+# ldflags = [ |
+# "-install_name", |
+# "@executable_path/../Frameworks/$target_name.framework" |
+# ] |
+# } |
+# |
+# bundle_data("core_teleportation_bundle_data") { |
+# deps = [ ":CoreTeleportation+link" ] |
+# sources = [ "$root_out_dir/CoreTeleportation.framework" ] |
+# outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] |
+# } |
+# |
+# app_bundle("GoatTeleporter") { |
+# sources = [ ... ] |
+# deps = [ |
+# ":core_teleportation_bundle_data", |
+# ] |
+# } |
+# |
+# Note that the framework is still copied to the app's bundle, but dyld will |
+# load this library when the app is launched because it uses the "+link" |
+# target as a dependency. This also requires that the framework set its |
+# install_name so that dyld can locate it. |
+# |
# See "gn help shared_library" for more information on arguments supported |
# by shared library target. |
template("mac_framework_bundle") { |
@@ -183,13 +246,149 @@ template("mac_framework_bundle") { |
] |
} |
- framework_bundle(target_name) { |
- forward_variables_from(invoker, "*", [ "info_plist" ]) |
+ _target_name = target_name |
+ _output_name = target_name |
+ if (defined(invoker.output_name)) { |
+ _output_name = invoker.output_name |
+ } |
+ |
+ # If the framework is unversioned, the final _target_name will be the |
+ # create_bundle(_framework_target), otherwise an action with the name |
+ # _target_name will depends on the the create_bundle() in order to prepare |
+ # the versioned directory structure. |
+ _framework_target = _target_name |
+ _framework_name = _output_name + ".framework" |
+ _framework_root_dir = "$root_out_dir/$_framework_name" |
+ if (defined(invoker.framework_version) && invoker.framework_version != "") { |
+ _framework_version = invoker.framework_version |
+ _framework_root_dir += "/Versions/$_framework_version" |
+ _framework_target = _target_name + "_create_bundle" |
+ } |
+ |
+ _link_shared_library_target = target_name + "_shared_library" |
+ _shared_library_bundle_data = target_name + "_shared_library_bundle_data" |
+ |
+ shared_library(_link_shared_library_target) { |
+ forward_variables_from(invoker, |
+ "*", |
+ [ |
+ "assert_no_deps", |
+ "bundle_deps", |
+ "code_signing_enabled", |
+ "data_deps", |
+ "info_plist", |
+ "info_plist_target", |
+ "output_name", |
+ "visibility", |
+ ]) |
+ visibility = [ ":$_shared_library_bundle_data" ] |
+ output_name = _output_name |
+ output_prefix_override = true |
+ output_extension = "" |
+ output_dir = "$target_out_dir/$_link_shared_library_target" |
+ } |
+ |
+ bundle_data(_shared_library_bundle_data) { |
+ visibility = [ ":$_framework_target" ] |
+ forward_variables_from(invoker, [ "testonly" ]) |
+ sources = [ |
+ "$target_out_dir/$_link_shared_library_target/$_output_name", |
+ ] |
+ outputs = [ |
+ "{{bundle_executable_dir}}/$_output_name", |
+ ] |
+ public_deps = [ |
+ ":$_link_shared_library_target", |
+ ] |
+ } |
+ |
+ _framework_public_config = _target_name + "_public_config" |
+ config(_framework_public_config) { |
+ # TODO(sdefresne): should we have a framework_dirs similar to lib_dirs |
+ # and include_dirs to avoid duplicate values on the command-line. |
+ visibility = [ ":$_framework_target" ] |
+ ldflags = [ |
+ "-F", |
+ rebase_path("$root_out_dir/.", root_build_dir), |
+ ] |
+ lib_dirs = [ root_out_dir ] |
+ libs = [ _framework_name ] |
+ } |
+ |
+ create_bundle(_framework_target) { |
+ forward_variables_from(invoker, |
+ [ |
+ "data_deps", |
+ "deps", |
+ "public_deps", |
+ "testonly", |
+ ]) |
+ |
+ if (defined(_framework_version)) { |
+ visibility = [ ":$_target_name" ] |
+ } else { |
+ if (defined(invoker.visibility)) { |
+ visibility = invoker.visibility |
+ visibility += [ ":$_target_name+link" ] |
+ } |
+ } |
if (!defined(deps)) { |
deps = [] |
} |
deps += [ ":$_info_plist_bundle_data" ] |
+ |
+ if (defined(invoker.bundle_deps)) { |
+ deps += invoker.bundle_deps |
+ } |
+ |
+ if (!defined(public_deps)) { |
+ public_deps = [] |
+ } |
+ public_deps += [ ":$_shared_library_bundle_data" ] |
+ |
+ bundle_root_dir = _framework_root_dir |
+ bundle_resources_dir = "$bundle_root_dir/Resources" |
+ bundle_executable_dir = "$bundle_root_dir" |
+ } |
+ |
+ if (defined(_framework_version)) { |
+ action(_target_name) { |
+ forward_variables_from(invoker, [ "testonly" ]) |
+ |
+ if (defined(invoker.visibility)) { |
+ visibility = invoker.visibility |
+ visibility += [ ":$_target_name+link" ] |
+ } |
+ |
+ script = "//build/config/mac/package_framework.py" |
+ outputs = [ |
+ "$root_out_dir/$_framework_name/Versions/Current", |
+ ] |
+ args = [ |
+ "$_framework_name", |
+ "$_framework_version", |
+ ] |
+ public_deps = [ |
+ ":$_framework_target", |
+ ] |
+ } |
+ } |
+ |
+ group(_target_name + "+link") { |
+ forward_variables_from(invoker, |
+ [ |
+ "public_configs", |
+ "testonly", |
+ "visibility", |
+ ]) |
+ public_deps = [ |
+ ":$_target_name", |
+ ] |
+ if (!defined(public_configs)) { |
+ public_configs = [] |
+ } |
+ public_configs += [ ":$_framework_public_config" ] |
} |
} |