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 ios_app_script = "//build/config/ios/ios_app.py" | 5 import("//build/config/ios/ios_sdk.gni") |
6 | 6 |
7 template("code_sign_ios") { | 7 # TODO(crbug.com/297668): refactor this template to extract common behaviour |
8 assert(defined(invoker.entitlements_path), | 8 # between OS X and iOS bundle generation, then create a generic "app" template |
9 "The path to the entitlements .xcent file") | 9 # that forward to "executable" on all platform except iOS/OS X. |
10 assert(defined(invoker.identity), "The code signing identity") | 10 template("ios_app") { |
11 assert(defined(invoker.application_path), "The application to code sign") | 11 # The application name defaults to target_name. |
12 assert(defined(invoker.deps)) | 12 _app_name = target_name |
13 if (defined(invoker.app_name)) { | |
14 _app_name = invoker.app_name | |
15 } | |
13 | 16 |
14 action(target_name) { | 17 # Declare the name of the target creating the application bundle so that |
18 # other targets can use it when setting "visibility". The target is named | |
19 # $target_name.app as it allows use to use the application name as argument | |
20 # to ninja during the build. | |
21 _create_app_bundle = target_name + ".app" | |
Dirk Pranke
2016/03/01 23:56:30
This is a bit confusing to me. Is _create_app_bund
sdefresne
2016/03/11 17:57:12
Done, but now I get the following error:
$ ninja
| |
22 | |
23 # Declare the name of some target as they have circular dependency via | |
24 # "visibility" and "deps". | |
25 _generate_info_plist = target_name + "_generate_info_plist" | |
26 _bundle_data_info_plist = target_name + "_bundle_data_info_plist" | |
27 | |
28 # Perform variable substitutions in the Info.plist and convert it to | |
29 # binary1 format. | |
30 action(_generate_info_plist) { | |
31 visibility = [ ":$_bundle_data_info_plist" ] | |
32 script = "//build/config/ios/ios_gen_plist.py" | |
15 sources = [ | 33 sources = [ |
16 invoker.entitlements_path, | 34 "//build/config/ios/BuildInfo.plist", |
35 invoker.info_plist, | |
17 ] | 36 ] |
37 outputs = [ | |
38 "$target_gen_dir/$target_name/Info.plist", | |
39 ] | |
40 extra_args = [] | |
41 if (defined(invoker.extra_substitutions)) { | |
42 foreach(substitution, invoker.extra_substitutions) { | |
43 extra_args += [ "-s=$substitution" ] | |
44 } | |
45 } | |
46 args = extra_args + [ | |
47 "-s=BUILD_MACHINE_OS_BUILD=$machine_os_build", | |
48 "-s=EXECUTABLE_NAME=$_app_name", | |
49 "-s=GCC_VERSION=com.apple.compilers.llvm.clang.1_0", | |
50 "-s=IOS_DEPLOYMENT_TARGET=$ios_deployment_target", | |
51 "-s=IOS_PLATFORM_BUILD=$ios_platform_build", | |
52 "-s=IOS_PLATFORM_NAME=$ios_sdk_name", | |
53 "-s=IOS_PLATFORM_VERSION=$ios_sdk_version", | |
54 "-s=IOS_SDK_BUILD=$ios_sdk_build", | |
55 "-s=IOS_SDK_NAME=$ios_sdk_name$ios_sdk_version", | |
56 "-s=IOS_SUPPORTED_PLATFORM=$ios_sdk_platform", | |
57 "-s=PRODUCT_NAME=$_app_name", | |
58 "-s=XCODE_BUILD=$xcode_build", | |
59 "-s=XCODE_VERSION=$xcode_version", | |
60 "-o=" + rebase_path(outputs[0], root_build_dir), | |
61 ] + rebase_path(sources, root_build_dir) | |
62 } | |
18 | 63 |
19 _application_path = invoker.application_path | 64 # Informs that the generated Info.plist file needs to be copied into the |
65 # application bundle. | |
66 bundle_data(_bundle_data_info_plist) { | |
67 forward_variables_from(invoker, [ "testonly" ]) | |
68 visibility = [ ":$_create_app_bundle" ] | |
69 sources = get_target_outputs(":$_generate_info_plist") | |
70 outputs = [ | |
71 "{{bundle_root_dir}}/Info.plist", | |
72 ] | |
73 public_deps = [ | |
74 ":$_generate_info_plist", | |
75 ] | |
76 } | |
20 | 77 |
21 script = ios_app_script | 78 # Declare the name of some target as they have circular dependency via |
79 # "visibility" and "deps". | |
Dirk Pranke
2016/03/01 23:56:30
I would probably drop this comment as calling thin
sdefresne
2016/03/11 17:57:12
Done.
| |
80 _generate_executable = target_name + "_generate_executable" | |
81 _bundle_data_executable = target_name + "_bundle_data_executable" | |
22 | 82 |
83 # Generates the application executable. | |
Dirk Pranke
2016/03/01 23:56:30
I would omit this comment.
sdefresne
2016/03/11 17:57:12
Done.
| |
84 executable(_generate_executable) { | |
85 visibility = [ ":$_bundle_data_executable" ] | |
86 forward_variables_from(invoker, | |
87 "*", | |
88 [ | |
89 "app_name", | |
90 "code_signing_identity", | |
91 "data_deps", | |
92 "entitlements_path", | |
93 "info_plist", | |
94 "visibility", | |
95 ]) | |
96 | |
97 output_name = rebase_path("$target_gen_dir/$_app_name", root_build_dir) | |
98 if (!defined(libs)) { | |
99 libs = [] | |
100 } | |
101 libs += [ "UIKit.framework" ] | |
102 } | |
103 | |
104 # Informs that the application executable needs to be copied into the | |
105 # application bundle. | |
Dirk Pranke
2016/03/01 23:56:30
I'm not actually sure what you're trying to convey
sdefresne
2016/03/11 17:57:12
Done.
| |
106 bundle_data(_bundle_data_executable) { | |
107 forward_variables_from(invoker, [ "testonly" ]) | |
108 visibility = [ ":$_create_app_bundle" ] | |
109 sources = [ | |
110 "$target_gen_dir/$_app_name", | |
111 ] | |
23 outputs = [ | 112 outputs = [ |
24 "$_application_path/_CodeSignature/CodeResources", | 113 "{{bundle_executable_dir}}/$_app_name", |
25 ] | 114 ] |
115 public_deps = [ | |
116 ":$_generate_executable", | |
117 ] | |
118 } | |
26 | 119 |
27 args = [ | 120 # Creates the application bundle. |
28 "codesign", | 121 create_bundle(_create_app_bundle) { |
Dirk Pranke
2016/03/01 23:56:30
Can you just make this be
create_bundle(target
sdefresne
2016/03/11 17:57:12
Done, but now I get the following error:
$ ninja
| |
29 "-p", | |
30 rebase_path(invoker.application_path, root_build_dir), | |
31 "-i", | |
32 invoker.identity, | |
33 "-e", | |
34 rebase_path(invoker.entitlements_path, root_build_dir), | |
35 ] | |
36 | |
37 forward_variables_from(invoker, | 122 forward_variables_from(invoker, |
38 [ | 123 [ |
124 "data_deps", | |
39 "deps", | 125 "deps", |
40 "public_deps", | 126 "public_deps", |
41 "testonly", | 127 "testonly", |
128 "visibility", | |
42 ]) | 129 ]) |
130 | |
131 if (!defined(deps)) { | |
132 deps = [] | |
133 } | |
134 deps += [ | |
135 ":$_bundle_data_executable", | |
136 ":$_bundle_data_info_plist", | |
137 ] | |
138 | |
139 bundle_root_dir = "$root_out_dir/$_app_name.app" | |
140 bundle_resources_dir = bundle_root_dir | |
141 bundle_executable_dir = bundle_root_dir | |
142 bundle_plugins_dir = "$bundle_root_dir/Plugins" | |
43 } | 143 } |
44 } | |
45 | 144 |
46 # TODO(GYP), TODO(dpranke): Should this be part of ios_app? | 145 # TODO(crbug.com/297668): |
47 template("resource_copy_ios") { | 146 # - add support for codesigning, |
48 assert(defined(invoker.resources), | 147 # - implements //testing/iossim(//build/toolchain/mac:clang_x64) and then |
Dirk Pranke
2016/03/01 23:56:30
Nit: s/implements/implement
sdefresne
2016/03/11 17:57:12
Done.
| |
49 "The source list of resources to copy over") | 148 # add a depency to that target. |
50 assert(defined(invoker.bundle_directory), | |
51 "The directory within the bundle to place the sources in") | |
52 assert(defined(invoker.app_name), "The name of the application") | |
53 | 149 |
54 _bundle_directory = invoker.bundle_directory | 150 # This group target is there to alias the _create_app_bundle target using |
55 _app_name = invoker.app_name | 151 # the name passed to the template. |
56 _resources = invoker.resources | 152 group(target_name) { |
57 | 153 forward_variables_from(invoker, |
58 copy(target_name) { | 154 [ |
59 set_sources_assignment_filter([]) | 155 "testonly", |
60 sources = _resources | 156 "visibility", |
61 outputs = [ | 157 ]) |
62 "$root_build_dir/$_app_name.app/$_bundle_directory/{{source_file_part}}", | 158 deps = [ |
159 ":$_create_app_bundle", | |
63 ] | 160 ] |
64 } | 161 } |
65 } | 162 } |
66 | |
67 template("ios_app") { | |
68 assert(defined(invoker.deps), | |
69 "Dependencies must be specified for $target_name") | |
70 assert(defined(invoker.info_plist), | |
71 "The application plist file must be specified for $target_name") | |
72 assert(defined(invoker.entitlements_path), | |
73 "The entitlements path must be specified for $target_name") | |
74 assert(defined(invoker.code_signing_identity), | |
75 "The code_signing_identity must be specified for $target_name") | |
76 | |
77 # We just create a variable so we can use the same in interpolation | |
78 if (defined(invoker.app_name)) { | |
79 _app_name = invoker.app_name | |
80 } else { | |
81 _app_name = target_name | |
82 } | |
83 | |
84 forward_variables_from(invoker, [ "testonly" ]) | |
85 | |
86 plist_gen_target_name = target_name + "_plist" | |
87 bin_gen_target_name = target_name + "_bin" | |
88 group_target_name = target_name | |
89 | |
90 # Generate the executable | |
91 executable(bin_gen_target_name) { | |
92 visibility = [ ":$group_target_name" ] | |
93 | |
94 output_name = "${_app_name}.app/${_app_name}" | |
95 | |
96 forward_variables_from(invoker, | |
97 [ | |
98 "all_dependent_configs", | |
99 "allow_circular_includes_from", | |
100 "cflags", | |
101 "cflags_c", | |
102 "cflags_cc", | |
103 "cflags_objc", | |
104 "cflags_objcc", | |
105 "configs", | |
106 "check_includes", | |
107 "data", | |
108 "data_deps", | |
109 "defines", | |
110 "include_dirs", | |
111 "ldflags", | |
112 "public", | |
113 "public_configs", | |
114 "public_deps", | |
115 "sources", | |
116 ]) | |
117 | |
118 if (defined(invoker.libs)) { | |
119 libs = invoker.libs | |
120 } else { | |
121 libs = [] | |
122 } | |
123 libs += [ | |
124 "UIKit.framework", | |
125 "QuartzCore.framework", | |
126 "OpenGLES.framework", | |
127 ] | |
128 | |
129 if (defined(invoker.deps)) { | |
130 deps = invoker.deps | |
131 } else { | |
132 deps = [] | |
133 } | |
134 deps += [ ":$plist_gen_target_name" ] | |
135 } | |
136 | |
137 # Process the Info.plist | |
138 action(plist_gen_target_name) { | |
139 visibility = [ | |
140 ":$group_target_name", | |
141 ":$bin_gen_target_name", | |
142 ] | |
143 | |
144 script = ios_app_script | |
145 | |
146 sources = [ | |
147 invoker.info_plist, | |
148 ] | |
149 outputs = [ | |
150 "$root_build_dir/${_app_name}.app/Info.plist", | |
151 ] | |
152 | |
153 args = [ | |
154 "plist", | |
155 "-i", | |
156 rebase_path(invoker.info_plist, root_build_dir), | |
157 "-o", | |
158 rebase_path("$root_build_dir/${_app_name}.app"), | |
159 ] | |
160 } | |
161 | |
162 # Perform Code Signing | |
163 entitlements_path = invoker.entitlements_path | |
164 if (invoker.code_signing_identity != "") { | |
165 code_sign_gen_target_name = target_name + "_codesign" | |
166 code_sign_ios(code_sign_gen_target_name) { | |
167 visibility = [ ":$target_name" ] | |
168 | |
169 identity = invoker.code_signing_identity | |
170 application_path = "$root_build_dir/$app_name.app" | |
171 deps = [ | |
172 ":$bin_gen_target_name", | |
173 ":$plist_gen_target_name", | |
174 ] | |
175 } | |
176 } else { | |
177 # This avoids a potential unused variable warning in the caller. | |
178 entitlements_path = entitlements_path | |
179 } | |
180 | |
181 # Top level group | |
182 group(target_name) { | |
183 deps = [ | |
184 ":$bin_gen_target_name", | |
185 ":$plist_gen_target_name", | |
186 ] | |
187 if (invoker.code_signing_identity != "") { | |
188 deps += [ ":$code_sign_gen_target_name" ] | |
189 } | |
190 } | |
191 } | |
OLD | NEW |