| 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/toolchain/toolchain.gni") | 5 import("//build/config/mac/base_rules.gni") |
| 6 import("//build/config/mac/mac_sdk.gni") | |
| 7 | |
| 8 # The base template used to generate Info.plist files for iOS and Mac apps and | |
| 9 # frameworks. | |
| 10 # | |
| 11 # Arguments | |
| 12 # | |
| 13 # plist_templates: | |
| 14 # string array, paths to plist files which will be used for the bundle. | |
| 15 # | |
| 16 # executable_name: | |
| 17 # string, name of the generated target used for the product | |
| 18 # and executable name as specified in the output Info.plist. | |
| 19 # | |
| 20 # extra_substitutions: | |
| 21 # (optional) string array, 'key=value' pairs for extra fields which are | |
| 22 # specified in a source Info.plist template. | |
| 23 template("info_plist") { | |
| 24 assert(defined(invoker.plist_templates), | |
| 25 "A list of template plist files must be specified for $target_name") | |
| 26 assert(defined(invoker.executable_name), | |
| 27 "The executable_name must be specified for $target_name") | |
| 28 executable_name = invoker.executable_name | |
| 29 | |
| 30 action(target_name) { | |
| 31 script = "//build/config/mac/gen_plist.py" | |
| 32 sources = invoker.plist_templates | |
| 33 outputs = [ | |
| 34 "$target_gen_dir/$target_name.plist", | |
| 35 ] | |
| 36 extra_args = [] | |
| 37 if (defined(invoker.extra_substitutions)) { | |
| 38 foreach(substitution, invoker.extra_substitutions) { | |
| 39 extra_args += [ "-s=$substitution" ] | |
| 40 } | |
| 41 } | |
| 42 response_file_contents = | |
| 43 extra_args + [ | |
| 44 "-s=BUILD_MACHINE_OS_BUILD=$machine_os_build", | |
| 45 "-s=EXECUTABLE_NAME=$executable_name", | |
| 46 "-s=GCC_VERSION=com.apple.compilers.llvm.clang.1_0", | |
| 47 "-s=PRODUCT_NAME=$executable_name", | |
| 48 "-s=XCODE_BUILD=$xcode_build", | |
| 49 "-s=XCODE_VERSION=$xcode_version", | |
| 50 "-o=" + rebase_path(outputs[0], root_build_dir), | |
| 51 ] + rebase_path(sources, root_build_dir) | |
| 52 args = [ "@{{response_file_name}}" ] | |
| 53 } | |
| 54 } | |
| 55 | 6 |
| 56 # Generates Info.plist files for Mac apps and frameworks. | 7 # Generates Info.plist files for Mac apps and frameworks. |
| 57 # | 8 # |
| 58 # Arguments | 9 # Arguments |
| 59 # | 10 # |
| 60 # info_plist: | 11 # info_plist: |
| 61 # string, the path to an plist file that will be included in the final | 12 # string, the path to an plist file that will be included in the final |
| 62 # Info.plist generated. | 13 # Info.plist generated. |
| 63 # | 14 # |
| 64 # executable_name: | 15 # executable_name: |
| (...skipping 14 matching lines...) Expand all Loading... |
| 79 "MAC_SDK_NAME=$mac_sdk_name$mac_sdk_version", | 30 "MAC_SDK_NAME=$mac_sdk_name$mac_sdk_version", |
| 80 ] | 31 ] |
| 81 plist_templates = [ | 32 plist_templates = [ |
| 82 "//build/config/mac/BuildInfo.plist", | 33 "//build/config/mac/BuildInfo.plist", |
| 83 invoker.info_plist, | 34 invoker.info_plist, |
| 84 ] | 35 ] |
| 85 forward_variables_from(invoker, [ "executable_name" ]) | 36 forward_variables_from(invoker, [ "executable_name" ]) |
| 86 } | 37 } |
| 87 } | 38 } |
| 88 | 39 |
| 89 # This is used as the base template for both iOS and Mac frameworks. | |
| 90 # | |
| 91 # By default, the bundle target this template generates does not link the | |
| 92 # resulting framework into anything that depends on it. If a dependency wants | |
| 93 # a link-time (as well as build-time) dependency on the framework bundle, | |
| 94 # depend against "$target_name+link". If only the build-time dependency is | |
| 95 # required (e.g., for copying into another bundle), then use "$target_name". | |
| 96 # | |
| 97 # Arguments | |
| 98 # | |
| 99 # output_name: | |
| 100 # (optional) string, name of the generated framework without the | |
| 101 # .framework suffix. If omitted, defaults to target_name. | |
| 102 # | |
| 103 # framework_version: | |
| 104 # (optional) string, version of the framework. Typically this is a | |
| 105 # single letter, like "A". If omitted, the Versions/ subdirectory | |
| 106 # structure will not be created, and build output will go directly | |
| 107 # into the framework subdirectory. | |
| 108 # | |
| 109 # This template provides two targets for the resulting framework bundle. The | |
| 110 # link-time behavior varies depending on which of the two targets below is | |
| 111 # added as a dependency: | |
| 112 # - $target_name only adds a build-time dependency. Targets that depend on | |
| 113 # it will not link against the framework. | |
| 114 # - $target_name+link adds a build-time and link-time dependency. Targets | |
| 115 # that depend on it will link against the framework. | |
| 116 # | |
| 117 # The build-time-only dependency is used for when a target needs to use the | |
| 118 # framework either only for resources, or because the target loads it at run- | |
| 119 # time, via dlopen() or NSBundle. The link-time dependency will cause the | |
| 120 # dependee to have the framework loaded by dyld at launch. | |
| 121 # | |
| 122 # Example of build-time only dependency: | |
| 123 # | |
| 124 # framework_bundle("CoreTeleportation") { | |
| 125 # sources = [ ... ] | |
| 126 # } | |
| 127 # | |
| 128 # bundle_data("core_teleportation_bundle_data") { | |
| 129 # deps = [ ":CoreTeleportation" ] | |
| 130 # sources = [ "$root_out_dir/CoreTeleportation.framework" ] | |
| 131 # outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] | |
| 132 # } | |
| 133 # | |
| 134 # app_bundle("GoatTeleporter") { | |
| 135 # sources = [ ... ] | |
| 136 # deps = [ | |
| 137 # ":core_teleportation_bundle_data", | |
| 138 # ] | |
| 139 # } | |
| 140 # | |
| 141 # The GoatTeleporter.app will not directly link against | |
| 142 # CoreTeleportation.framework, but it will be included in the bundle's | |
| 143 # Frameworks directory. | |
| 144 # | |
| 145 # Example of link-time dependency: | |
| 146 # | |
| 147 # framework_bundle("CoreTeleportation") { | |
| 148 # sources = [ ... ] | |
| 149 # ldflags = [ | |
| 150 # "-install_name", | |
| 151 # "@executable_path/../Frameworks/$target_name.framework" | |
| 152 # ] | |
| 153 # } | |
| 154 # | |
| 155 # bundle_data("core_teleportation_bundle_data") { | |
| 156 # deps = [ ":CoreTeleportation+link" ] | |
| 157 # sources = [ "$root_out_dir/CoreTeleportation.framework" ] | |
| 158 # outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] | |
| 159 # } | |
| 160 # | |
| 161 # app_bundle("GoatTeleporter") { | |
| 162 # sources = [ ... ] | |
| 163 # deps = [ | |
| 164 # ":core_teleportation_bundle_data", | |
| 165 # ] | |
| 166 # } | |
| 167 # | |
| 168 # Note that the framework is still copied to the app's bundle, but dyld will | |
| 169 # load this library when the app is launched because it uses the "+link" | |
| 170 # target as a dependency. This also requires that the framework set its | |
| 171 # install_name so that dyld can locate it. | |
| 172 # | |
| 173 # See "gn help shared_library" for more information on arguments supported | |
| 174 # by shared library target. | |
| 175 template("framework_bundle") { | |
| 176 _target_name = target_name | |
| 177 _output_name = target_name | |
| 178 if (defined(invoker.output_name)) { | |
| 179 _output_name = invoker.output_name | |
| 180 } | |
| 181 | |
| 182 # If the framework is unversioned, the final _target_name will be the | |
| 183 # create_bundle(_framework_target), otherwise an action with the name | |
| 184 # _target_name will depends on the the create_bundle() in order to prepare | |
| 185 # the versioned directory structure. | |
| 186 _framework_target = _target_name | |
| 187 _framework_name = _output_name + ".framework" | |
| 188 _framework_root_dir = "$root_out_dir/$_framework_name" | |
| 189 if (defined(invoker.framework_version) && invoker.framework_version != "") { | |
| 190 _framework_version = invoker.framework_version | |
| 191 _framework_root_dir += "/Versions/$_framework_version" | |
| 192 _framework_target = _target_name + "_create_bundle" | |
| 193 } | |
| 194 | |
| 195 _shared_library_target = target_name + "_shared_library" | |
| 196 _shared_library_bundle_data = _shared_library_target + "_bundle_data" | |
| 197 | |
| 198 shared_library(_shared_library_target) { | |
| 199 visibility = [ ":$_shared_library_bundle_data" ] | |
| 200 forward_variables_from(invoker, | |
| 201 "*", | |
| 202 [ | |
| 203 "assert_no_deps", | |
| 204 "data_deps", | |
| 205 "info_plist", | |
| 206 "output_name", | |
| 207 "visibility", | |
| 208 ]) | |
| 209 output_name = _output_name | |
| 210 output_prefix_override = true | |
| 211 output_extension = "" | |
| 212 output_dir = "$target_out_dir/$_shared_library_target" | |
| 213 } | |
| 214 | |
| 215 bundle_data(_shared_library_bundle_data) { | |
| 216 visibility = [ ":$_framework_target" ] | |
| 217 forward_variables_from(invoker, [ "testonly" ]) | |
| 218 sources = [ | |
| 219 "$target_out_dir/$_shared_library_target/$_output_name", | |
| 220 ] | |
| 221 outputs = [ | |
| 222 "{{bundle_executable_dir}}/$_output_name", | |
| 223 ] | |
| 224 public_deps = [ | |
| 225 ":$_shared_library_target", | |
| 226 ] | |
| 227 } | |
| 228 | |
| 229 _framework_public_config = _target_name + "_public_config" | |
| 230 config(_framework_public_config) { | |
| 231 # TODO(sdefresne): should we have a framework_dirs similar to lib_dirs | |
| 232 # and include_dirs to avoid duplicate values on the command-line. | |
| 233 visibility = [ ":$_framework_target" ] | |
| 234 ldflags = [ "-F" + rebase_path("$root_out_dir/.", root_out_dir) ] | |
| 235 lib_dirs = [ root_out_dir ] | |
| 236 libs = [ _framework_name ] | |
| 237 } | |
| 238 | |
| 239 create_bundle(_framework_target) { | |
| 240 forward_variables_from(invoker, | |
| 241 [ | |
| 242 "data_deps", | |
| 243 "deps", | |
| 244 "public_deps", | |
| 245 "testonly", | |
| 246 ]) | |
| 247 | |
| 248 if (defined(_framework_version)) { | |
| 249 visibility = [ ":$_target_name" ] | |
| 250 } else { | |
| 251 if (defined(invoker.visibility)) { | |
| 252 visibility = invoker.visibility | |
| 253 visibility += [ ":$_target_name+link" ] | |
| 254 } | |
| 255 } | |
| 256 | |
| 257 if (!defined(public_deps)) { | |
| 258 public_deps = [] | |
| 259 } | |
| 260 public_deps += [ ":$_shared_library_bundle_data" ] | |
| 261 | |
| 262 bundle_root_dir = _framework_root_dir | |
| 263 bundle_resources_dir = "$bundle_root_dir/Resources" | |
| 264 bundle_executable_dir = "$bundle_root_dir" | |
| 265 } | |
| 266 | |
| 267 if (defined(_framework_version)) { | |
| 268 action(_target_name) { | |
| 269 forward_variables_from(invoker, [ "testonly" ]) | |
| 270 | |
| 271 if (defined(invoker.visibility)) { | |
| 272 visibility = invoker.visibility | |
| 273 visibility += [ ":$_target_name+link" ] | |
| 274 } | |
| 275 | |
| 276 script = "$root_out_dir/gyp-mac-tool" | |
| 277 outputs = [ | |
| 278 "$root_out_dir/$_framework_name/Versions/Current", | |
| 279 ] | |
| 280 args = [ | |
| 281 "package-framework", | |
| 282 "$_framework_name", | |
| 283 "$_framework_version", | |
| 284 ] | |
| 285 public_deps = [ | |
| 286 ":$_framework_target", | |
| 287 ] | |
| 288 } | |
| 289 } | |
| 290 | |
| 291 group(_target_name + "+link") { | |
| 292 forward_variables_from(invoker, | |
| 293 [ | |
| 294 "visibility", | |
| 295 "testonly", | |
| 296 ]) | |
| 297 public_deps = [ | |
| 298 ":$_target_name", | |
| 299 ] | |
| 300 public_configs = [ ":$_framework_public_config" ] | |
| 301 } | |
| 302 } | |
| 303 | |
| 304 # Template to combile .xib or .storyboard files. | |
| 305 # | |
| 306 # | |
| 307 # Arguments | |
| 308 # | |
| 309 # sources: | |
| 310 # list of string, sources to compile | |
| 311 # | |
| 312 # ibtool_flags: | |
| 313 # (optional) list of string, additional flags to pass to the ibtool | |
| 314 template("compile_xibs") { | |
| 315 action_foreach(target_name) { | |
| 316 forward_variables_from(invoker, | |
| 317 [ | |
| 318 "testonly", | |
| 319 "visibility", | |
| 320 ]) | |
| 321 assert(defined(invoker.sources), | |
| 322 "Sources must be specified for $target_name") | |
| 323 | |
| 324 ibtool_flags = [] | |
| 325 if (defined(invoker.ibtool_flags)) { | |
| 326 ibtool_flags = invoker.ibtool_flags | |
| 327 } | |
| 328 | |
| 329 script = "//build/config/mac/compile_xib.py" | |
| 330 sources = invoker.sources | |
| 331 outputs = [ | |
| 332 "$target_gen_dir/{{source_name_part}}.nib", | |
| 333 ] | |
| 334 args = [ | |
| 335 "--input", | |
| 336 "{{source}}", | |
| 337 "--output", | |
| 338 rebase_path("$target_gen_dir/{{source_name_part}}.nib"), | |
| 339 ] + ibtool_flags | |
| 340 } | |
| 341 } | |
| 342 | |
| 343 # Template to compile and package Mac XIB files as bundle data. | 40 # Template to compile and package Mac XIB files as bundle data. |
| 344 # | 41 # |
| 345 # Arguments | 42 # Arguments |
| 346 # | 43 # |
| 347 # sources: | 44 # sources: |
| 348 # list of string, sources to comiple | 45 # list of string, sources to comiple |
| 349 # | 46 # |
| 350 # output_path: | 47 # output_path: |
| 351 # (optional) string, the path to use for the outputs list in the | 48 # (optional) string, the path to use for the outputs list in the |
| 352 # bundle_data step. If unspecified, defaults to bundle_resources_dir. | 49 # bundle_data step. If unspecified, defaults to bundle_resources_dir. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 ] | 85 ] |
| 389 } | 86 } |
| 390 } | 87 } |
| 391 | 88 |
| 392 # Template to package a shared library into a Mac framework bundle. | 89 # Template to package a shared library into a Mac framework bundle. |
| 393 # | 90 # |
| 394 # This template provides two targets to control whether the framework is | 91 # This template provides two targets to control whether the framework is |
| 395 # merely built when targets depend on it, or whether it is linked as well: | 92 # merely built when targets depend on it, or whether it is linked as well: |
| 396 # "$target_name" and "$target_name+link". | 93 # "$target_name" and "$target_name+link". |
| 397 # | 94 # |
| 398 # See the //build/config/mac/rules.gni:framework_bundle for a discussion | 95 # See the //build/config/mac/base_rules.gni:framework_bundle for a discussion |
| 399 # and examples. | 96 # and examples. |
| 400 # | 97 # |
| 401 # Arguments | 98 # Arguments |
| 402 # | 99 # |
| 403 # info_plist: | 100 # info_plist: |
| 404 # string, path to the Info.plist file that will be used for the bundle. | 101 # string, path to the Info.plist file that will be used for the bundle. |
| 405 # | 102 # |
| 406 # output_name: | 103 # output_name: |
| 407 # (optional) string, name of the generated framework without the | 104 # (optional) string, name of the generated framework without the |
| 408 # .framework suffix. If omitted, defaults to target_name. | 105 # .framework suffix. If omitted, defaults to target_name. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 604 ]) | 301 ]) |
| 605 if (!defined(deps)) { | 302 if (!defined(deps)) { |
| 606 deps = [] | 303 deps = [] |
| 607 } | 304 } |
| 608 deps += [ ":$_loadable_module_bundle_data" ] | 305 deps += [ ":$_loadable_module_bundle_data" ] |
| 609 | 306 |
| 610 bundle_root_dir = "$root_out_dir/$_output_name.plugin/Contents" | 307 bundle_root_dir = "$root_out_dir/$_output_name.plugin/Contents" |
| 611 bundle_executable_dir = "$bundle_root_dir/MacOS" | 308 bundle_executable_dir = "$bundle_root_dir/MacOS" |
| 612 } | 309 } |
| 613 } | 310 } |
| OLD | NEW |