# Copyright 2015 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. import("//build/config/ios/ios_sdk.gni") # TODO(crbug.com/297668): refactor this template to extract common behaviour # between OS X and iOS bundle generation, then create a generic "app" template # that forward to "executable" on all platform except iOS/OS X. # Template to build an application bundle for iOS. # # This should be used instead of "executable" built-in target type on iOS. # As the template forward the generation of the application executable to # an "executable" target, all arguments supported by "executable" targets # are also supported by this template. # # Arguments # # output_name: # (optional) string, name of the generated application, if omitted, # defaults to the target_name. # # extra_substitutions: # (optional) list of string in "key=value" format, each value will # be used as an additional variable substitution rule when generating # the application Info.plist # # info_plist: # path to the template to use to generate the application Info.plist # by performing variable substitutions. # # For more information, see "gn help executable". template("app") { assert(defined(invoker.info_plist), "info_plist must be specified for target $target_name") _output_name = target_name _target_name = target_name if (defined(invoker.output_name)) { _output_name = invoker.output_name } _generate_info_plist = target_name + "_generate_info_plist" _bundle_data_info_plist = target_name + "_bundle_data_info_plist" action(_generate_info_plist) { visibility = [ ":$_bundle_data_info_plist" ] script = "//build/config/ios/ios_gen_plist.py" sources = [ "//build/config/ios/BuildInfo.plist", invoker.info_plist, ] outputs = [ "$target_gen_dir/$target_name/Info.plist", ] extra_args = [] if (defined(invoker.extra_substitutions)) { foreach(substitution, invoker.extra_substitutions) { extra_args += [ "-s=$substitution" ] } } response_file_contents = extra_args + [ "-s=BUILD_MACHINE_OS_BUILD=$machine_os_build", "-s=EXECUTABLE_NAME=$_output_name", "-s=GCC_VERSION=com.apple.compilers.llvm.clang.1_0", "-s=IOS_DEPLOYMENT_TARGET=$ios_deployment_target", "-s=IOS_PLATFORM_BUILD=$ios_platform_build", "-s=IOS_PLATFORM_NAME=$ios_sdk_name", "-s=IOS_PLATFORM_VERSION=$ios_sdk_version", "-s=IOS_SDK_BUILD=$ios_sdk_build", "-s=IOS_SDK_NAME=$ios_sdk_name$ios_sdk_version", "-s=IOS_SUPPORTED_PLATFORM=$ios_sdk_platform", "-s=PRODUCT_NAME=$_output_name", "-s=XCODE_BUILD=$xcode_build", "-s=XCODE_VERSION=$xcode_version", "-o=" + rebase_path(outputs[0], root_build_dir), ] + rebase_path(sources, root_build_dir) args = [ "@{{response_file_name}}" ] } bundle_data(_bundle_data_info_plist) { forward_variables_from(invoker, [ "testonly" ]) visibility = [ ":$_target_name" ] sources = get_target_outputs(":$_generate_info_plist") outputs = [ "{{bundle_root_dir}}/Info.plist", ] public_deps = [ ":$_generate_info_plist", ] } _generate_executable = target_name + "_generate_executable" _bundle_data_executable = target_name + "_bundle_data_executable" executable(_generate_executable) { visibility = [ ":$_bundle_data_executable" ] forward_variables_from(invoker, "*", [ "assert_no_deps", "code_signing_identity", "data_deps", "entitlements_path", "info_plist", "output_name", "visibility", ]) output_name = rebase_path("$target_gen_dir/$_output_name", root_build_dir) if (!defined(libs)) { libs = [] } libs += [ "UIKit.framework" ] } bundle_data(_bundle_data_executable) { forward_variables_from(invoker, [ "testonly" ]) visibility = [ ":$_target_name" ] sources = [ "$target_gen_dir/$_output_name", ] outputs = [ "{{bundle_executable_dir}}/$_output_name", ] public_deps = [ ":$_generate_executable", ] } create_bundle(target_name) { forward_variables_from(invoker, [ "data_deps", "deps", "public_deps", "testonly", "visibility", ]) if (!defined(deps)) { deps = [] } deps += [ ":$_bundle_data_executable", ":$_bundle_data_info_plist", ] if (use_ios_simulator) { if (!defined(data_deps)) { data_deps = [] } data_deps += [ "//testing/iossim(${host_toolchain})" ] } bundle_root_dir = "$root_out_dir/$_output_name.app" bundle_resources_dir = bundle_root_dir bundle_executable_dir = bundle_root_dir bundle_plugins_dir = "$bundle_root_dir/Plugins" } # TODO(crbug.com/297668): # - add support for codesigning, # - find a way to make "ninja -C out/Default base_unittests.app" work as # an alias to "ninja -C out/Default base_unittests" (for convenience # and compatibility with gyp), } # Compile a xib or storyboard file and add it to a bundle_data so that it is # available at runtime in the bundle. # # Arguments # # source: # string, path of the xib or storyboard to compile. # # Forwards all variables to the bundle_data target. template("bundle_data_xib") { assert(defined(invoker.source), "source needs to be defined for $target_name") _source_extension = get_path_info(invoker.source, "extension") assert(_source_extension == "xib" || _source_extension == "storyboard", "source must be a .xib or .storyboard for $target_name") _target_name = target_name _compile_xib = target_name + "_compile_xib" _nib_basename = get_path_info(invoker.source, "name") _nib_filename = "$_nib_basename.nib" action(_compile_xib) { visibility = [ ":$_target_name" ] script = "//build/config/ios/ios_compile_xib.py" sources = [ invoker.source, ] outputs = [ "$target_gen_dir/$_nib_filename/objects.nib", "$target_gen_dir/$_nib_filename/runtime.nib", ] args = [ "--minimum-deployment-target", ios_deployment_target, "--output", rebase_path("$target_gen_dir/$_nib_filename"), "--input", rebase_path(invoker.source, root_build_dir), ] } bundle_data(_target_name) { forward_variables_from(invoker, "*", [ "source" ]) if (!defined(public_deps)) { public_deps = [] } public_deps += [ ":$_compile_xib" ] sources = [ "$target_gen_dir/$_nib_filename/objects.nib", "$target_gen_dir/$_nib_filename/runtime.nib", ] outputs = [ "{{bundle_resources_dir}}/$_nib_filename/{{source_file_part}}", ] } }