OLD | NEW |
| (Empty) |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import("mojo.gni") | |
6 import("mojo_sdk.gni") | |
7 | |
8 # Generate a binary mojo application.The parameters of this template are those | |
9 # of a shared library. | |
10 template("mojo_native_application") { | |
11 if (defined(invoker.output_name)) { | |
12 output = invoker.output_name + ".mojo" | |
13 library_target_name = invoker.output_name + "_library" | |
14 } else { | |
15 output = target_name + ".mojo" | |
16 library_target_name = target_name + "_library" | |
17 } | |
18 | |
19 if (is_linux || is_android) { | |
20 library_name = "lib${library_target_name}.so" | |
21 } else if (is_win) { | |
22 library_name = "${library_target_name}.dll" | |
23 } else if (is_mac) { | |
24 library_name = "lib${library_target_name}.dylib" | |
25 } else { | |
26 assert(false, "Platform not supported.") | |
27 } | |
28 | |
29 if (is_android) { | |
30 # On android, use the stripped version of the library, because applications | |
31 # are always fetched over the network. | |
32 library_dir = "${root_out_dir}/lib.stripped" | |
33 } else { | |
34 library_dir = root_out_dir | |
35 } | |
36 | |
37 final_target_name = target_name | |
38 | |
39 shared_library(library_target_name) { | |
40 if (defined(invoker.cflags)) { | |
41 cflags = invoker.cflags | |
42 } | |
43 if (defined(invoker.cflags_c)) { | |
44 cflags_c = invoker.cflags_c | |
45 } | |
46 if (defined(invoker.cflags_cc)) { | |
47 cflags_cc = invoker.cflags_cc | |
48 } | |
49 if (defined(invoker.cflags_objc)) { | |
50 cflags_objc = invoker.cflags_objc | |
51 } | |
52 if (defined(invoker.cflags_objcc)) { | |
53 cflags_objcc = invoker.cflags_objcc | |
54 } | |
55 if (defined(invoker.defines)) { | |
56 defines = invoker.defines | |
57 } | |
58 if (defined(invoker.include_dirs)) { | |
59 include_dirs = invoker.include_dirs | |
60 } | |
61 if (defined(invoker.ldflags)) { | |
62 ldflags = invoker.ldflags | |
63 } | |
64 if (defined(invoker.lib_dirs)) { | |
65 lib_dirs = invoker.lib_dirs | |
66 } | |
67 if (defined(invoker.libs)) { | |
68 libs = invoker.libs | |
69 } | |
70 | |
71 if (use_prebuilt_mojo_shell) { | |
72 copy_mojo_shell = | |
73 rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) | |
74 } | |
75 | |
76 # Copy the prebuilt mojo_shell if using it. | |
77 if (defined(invoker.datadeps)) { | |
78 datadeps = invoker.datadeps | |
79 if (use_prebuilt_mojo_shell) { | |
80 datadeps += [ copy_mojo_shell ] | |
81 } | |
82 } else { | |
83 if (use_prebuilt_mojo_shell) { | |
84 datadeps = [ | |
85 copy_mojo_shell, | |
86 ] | |
87 } | |
88 } | |
89 deps = rebase_path([ | |
90 "mojo/public/c/system", | |
91 "mojo/public/platform/native:system", | |
92 ], | |
93 ".", | |
94 mojo_root) | |
95 if (defined(invoker.deps)) { | |
96 deps += invoker.deps | |
97 } | |
98 if (defined(invoker.forward_dependent_configs_from)) { | |
99 forward_dependent_configs_from = invoker.forward_dependent_configs_from | |
100 } | |
101 if (defined(invoker.public_deps)) { | |
102 public_deps = invoker.public_deps | |
103 } | |
104 if (defined(invoker.all_dependent_configs)) { | |
105 all_dependent_configs = invoker.all_dependent_configs | |
106 } | |
107 if (defined(invoker.public_configs)) { | |
108 public_configs = invoker.public_configs | |
109 } | |
110 if (defined(invoker.check_includes)) { | |
111 check_includes = invoker.check_includes | |
112 } | |
113 if (defined(invoker.configs)) { | |
114 configs += invoker.configs | |
115 } | |
116 if (defined(invoker.data)) { | |
117 data = invoker.data | |
118 } | |
119 if (defined(invoker.inputs)) { | |
120 inputs = invoker.inputs | |
121 } | |
122 if (defined(invoker.public)) { | |
123 public = invoker.public | |
124 } | |
125 if (defined(invoker.sources)) { | |
126 sources = invoker.sources | |
127 } | |
128 if (defined(invoker.testonly)) { | |
129 testonly = invoker.testonly | |
130 } | |
131 | |
132 visibility = [ ":${final_target_name}" ] | |
133 } | |
134 | |
135 copy(final_target_name) { | |
136 if (defined(invoker.testonly)) { | |
137 testonly = invoker.testonly | |
138 } | |
139 if (defined(invoker.visibility)) { | |
140 visibility = invoker.visibility | |
141 } | |
142 deps = [ | |
143 ":${library_target_name}", | |
144 ] | |
145 | |
146 sources = [ | |
147 "${library_dir}/${library_name}", | |
148 ] | |
149 outputs = [ | |
150 "${root_out_dir}/${output}", | |
151 ] | |
152 } | |
153 } | |
154 | |
155 if (is_android) { | |
156 # Declares an Android Mojo application consisting of an .so file and a | |
157 # corresponding .dex.jar file. | |
158 # | |
159 # Variables: | |
160 # input_so: the .so file to bundle | |
161 # input_dex_jar: the .dex.jar file to bundle | |
162 # output_name (optional): override for the output file name | |
163 template("mojo_android_application") { | |
164 assert(defined(invoker.input_so)) | |
165 assert(defined(invoker.input_dex_jar)) | |
166 | |
167 zip_action_name = "${target_name}_zip" | |
168 zip_action_output = "$target_gen_dir/${target_name}.zip" | |
169 action(zip_action_name) { | |
170 script = "//build/android/gn/zip.py" | |
171 | |
172 inputs = [ | |
173 invoker.input_so, | |
174 invoker.input_dex_jar, | |
175 ] | |
176 | |
177 output = zip_action_output | |
178 outputs = [ | |
179 output, | |
180 ] | |
181 | |
182 rebase_inputs = rebase_path(inputs, root_build_dir) | |
183 rebase_output = rebase_path(output, root_build_dir) | |
184 args = [ | |
185 "--inputs=$rebase_inputs", | |
186 "--output=$rebase_output", | |
187 ] | |
188 } | |
189 | |
190 if (defined(invoker.output_name)) { | |
191 mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo" | |
192 } else { | |
193 mojo_output = "$root_out_dir/" + target_name + ".mojo" | |
194 } | |
195 | |
196 action(target_name) { | |
197 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root) | |
198 | |
199 input = zip_action_output | |
200 inputs = [ | |
201 input, | |
202 ] | |
203 | |
204 output = mojo_output | |
205 outputs = [ | |
206 output, | |
207 ] | |
208 | |
209 rebase_input = rebase_path(input, root_build_dir) | |
210 rebase_output = rebase_path(output, root_build_dir) | |
211 args = [ | |
212 "--input=$rebase_input", | |
213 "--output=$rebase_output", | |
214 "--line=#!mojo mojo:android_handler", | |
215 ] | |
216 } | |
217 } | |
218 } | |
OLD | NEW |