Index: build/config/mac/rules.gni |
diff --git a/build/config/mac/rules.gni b/build/config/mac/rules.gni |
index 11b86c9d6f88f33c8f727afd56a58952ff667e03..9d624a7bac72f4a7744ba5b275492fe10a3d21e3 100644 |
--- a/build/config/mac/rules.gni |
+++ b/build/config/mac/rules.gni |
@@ -7,6 +7,12 @@ import("//build/config/mac/mac_sdk.gni") |
# This is used as the base template for both iOS and Mac frameworks.. |
# |
+# 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 |
# |
# output_name: |
@@ -19,6 +25,70 @@ import("//build/config/mac/mac_sdk.gni") |
# structure will not be created, and build output will go directly |
# into the framework subdirectory. |
# |
+# 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: |
+# |
+# 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: |
+# |
+# 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("framework_bundle") { |
@@ -80,10 +150,7 @@ template("framework_bundle") { |
# 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" ] |
- common_flags = [ "-F" + rebase_path("$root_out_dir/.", root_out_dir) ] |
- cflags_objc = common_flags |
- cflags_objcc = common_flags |
- ldflags = common_flags |
+ ldflags = [ "-F" + rebase_path("$root_out_dir/.", root_out_dir) ] |
lib_dirs = [ root_out_dir ] |
libs = [ _framework_name ] |
} |
@@ -100,7 +167,10 @@ template("framework_bundle") { |
if (defined(_framework_version)) { |
visibility = [ ":$_target_name" ] |
} else { |
- forward_variables_from(invoker, [ "visibility" ]) |
+ if (defined(invoker.visibility)) { |
+ visibility = invoker.visibility |
+ visibility += [ ":$_target_name+link" ] |
+ } |
} |
if (!defined(public_deps)) { |
@@ -108,8 +178,6 @@ template("framework_bundle") { |
} |
public_deps += [ ":$_shared_library_bundle_data" ] |
- public_configs = [ ":$_framework_public_config" ] |
- |
bundle_root_dir = _framework_root_dir |
bundle_resources_dir = "$bundle_root_dir/Resources" |
bundle_executable_dir = "$bundle_root_dir" |
@@ -117,11 +185,13 @@ template("framework_bundle") { |
if (defined(_framework_version)) { |
action(_target_name) { |
- forward_variables_from(invoker, |
- [ |
- "visibility", |
- "testonly", |
- ]) |
+ forward_variables_from(invoker, [ "testonly" ]) |
+ |
+ if (defined(invoker.visibility)) { |
+ visibility = invoker.visibility |
+ visibility += [ ":$_target_name+link" ] |
+ } |
+ |
script = "$root_out_dir/gyp-mac-tool" |
outputs = [ |
"$root_out_dir/$_framework_name/Versions/Current", |
@@ -136,6 +206,18 @@ template("framework_bundle") { |
] |
} |
} |
+ |
+ group(_target_name + "+link") { |
+ forward_variables_from(invoker, |
+ [ |
+ "visibility", |
+ "testonly", |
+ ]) |
+ public_deps = [ |
+ ":$_target_name", |
+ ] |
+ public_configs = [ ":$_framework_public_config" ] |
+ } |
} |
# Template to combile .xib or .storyboard files. |
@@ -228,6 +310,13 @@ 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/rules.gni:framework_bundle for a discussion |
+# and examples. |
+# |
# Arguments |
# |
# info_plist: |