summaryrefslogtreecommitdiffstats
path: root/build/config/ios/rules.gni
blob: 0cee9ecbc280fe3d8c7c121d7145f6b27a21ccee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# 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
#
#   app_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")

  _app_name = target_name
  _target_name = target_name
  if (defined(invoker.app_name)) {
    _app_name = invoker.app_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=$_app_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=$_app_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,
                           "*",
                           [
                             "app_name",
                             "code_signing_identity",
                             "data_deps",
                             "entitlements_path",
                             "info_plist",
                             "visibility",
                           ])

    output_name = rebase_path("$target_gen_dir/$_app_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/$_app_name",
    ]
    outputs = [
      "{{bundle_executable_dir}}/$_app_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/$_app_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),
}