[Telemetry] Remove adb_commands usage from android_device.
[chromium-blink-merge.git] / mojo / public / mojo_application.gni
blob1450227fe287c494edaee961ccfb6e9e76719b95
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.
5 import("mojo.gni")
7 # Generate a binary Mojo application in a self-named directory.
8 # Application resources are copied to a "resources" directory alongside the app.
9 # The parameters of this template are those of a shared library.
10 template("mojo_native_application") {
11   base_target_name = target_name
12   if (defined(invoker.output_name)) {
13     base_target_name = invoker.output_name
14   }
16   final_target_name = target_name
18   mojo_deps = []
19   if (defined(invoker.deps)) {
20     mojo_deps += invoker.deps
21   }
23   if (defined(invoker.resources)) {
24     copy_step_name = "${base_target_name}__copy_resources"
25     copy(copy_step_name) {
26       sources = invoker.resources
27       outputs = [
28         "${root_out_dir}/${base_target_name}/resources/{{source_file_part}}",
29       ]
30       if (defined(invoker.testonly)) {
31         testonly = invoker.testonly
32       }
33       deps = mojo_deps
34     }
35     mojo_deps += [ ":$copy_step_name" ]
36   }
38   if (!is_nacl) {
39     output = base_target_name + ".mojo"
40     library_target_name = base_target_name + "_library"
42     if (is_linux || is_android) {
43       library_name = "lib${library_target_name}.so"
44     } else if (is_win) {
45       library_name = "${library_target_name}.dll"
46     } else if (is_mac) {
47       library_name = "lib${library_target_name}.dylib"
48     } else {
49       assert(false, "Platform not supported.")
50     }
52     if (is_android) {
53       # On android, use the stripped version of the library, because
54       # applications are always fetched over the network.
55       library_dir = "${root_out_dir}/lib.stripped"
56     } else {
57       library_dir = root_out_dir
58     }
60     shared_library(library_target_name) {
61       if (defined(invoker.cflags)) {
62         cflags = invoker.cflags
63       }
64       if (defined(invoker.cflags_c)) {
65         cflags_c = invoker.cflags_c
66       }
67       if (defined(invoker.cflags_cc)) {
68         cflags_cc = invoker.cflags_cc
69       }
70       if (defined(invoker.cflags_objc)) {
71         cflags_objc = invoker.cflags_objc
72       }
73       if (defined(invoker.cflags_objcc)) {
74         cflags_objcc = invoker.cflags_objcc
75       }
76       if (defined(invoker.defines)) {
77         defines = invoker.defines
78       }
79       if (defined(invoker.include_dirs)) {
80         include_dirs = invoker.include_dirs
81       }
82       if (defined(invoker.ldflags)) {
83         ldflags = invoker.ldflags
84       }
85       if (defined(invoker.lib_dirs)) {
86         lib_dirs = invoker.lib_dirs
87       }
88       if (defined(invoker.libs)) {
89         libs = invoker.libs
90       }
92       data_deps = []
93       if (defined(invoker.data_deps)) {
94         data_deps = invoker.data_deps
95       }
97       # Copy any necessary prebuilt artifacts.
98       if (mojo_use_prebuilt_mojo_shell) {
99         data_deps +=
100             [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
101       }
102       if (mojo_use_prebuilt_network_service) {
103         data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
104                                    ".",
105                                    mojo_root) ]
106       }
108       deps = rebase_path([
109                            "mojo/public/c/system",
110                            "mojo/public/platform/native:system",
111                          ],
112                          ".",
113                          mojo_root)
114       deps += mojo_deps
115       if (defined(invoker.forward_dependent_configs_from)) {
116         forward_dependent_configs_from = invoker.forward_dependent_configs_from
117       }
118       if (defined(invoker.public_deps)) {
119         public_deps = invoker.public_deps
120       }
121       if (defined(invoker.all_dependent_configs)) {
122         all_dependent_configs = invoker.all_dependent_configs
123       }
124       if (defined(invoker.public_configs)) {
125         public_configs = invoker.public_configs
126       }
127       if (defined(invoker.check_includes)) {
128         check_includes = invoker.check_includes
129       }
130       if (defined(invoker.configs)) {
131         configs += invoker.configs
132       }
133       if (defined(invoker.data)) {
134         data = invoker.data
135       }
136       if (defined(invoker.inputs)) {
137         inputs = invoker.inputs
138       }
139       if (defined(invoker.public)) {
140         public = invoker.public
141       }
142       if (defined(invoker.sources)) {
143         sources = invoker.sources
144       }
145       if (defined(invoker.testonly)) {
146         testonly = invoker.testonly
147       }
149       visibility = [ ":${final_target_name}" ]
150     }
152     copy(final_target_name) {
153       if (defined(invoker.testonly)) {
154         testonly = invoker.testonly
155       }
156       if (defined(invoker.visibility)) {
157         visibility = invoker.visibility
158       }
159       deps = [
160         ":${library_target_name}",
161       ]
163       sources = [
164         "${library_dir}/${library_name}",
165       ]
166       outputs = [
167         "${root_out_dir}/${base_target_name}/${output}",
168       ]
169     }
170   } else {
171     nexe_target_name = base_target_name + "_nexe"
172     nexe_name = base_target_name + ".nexe"
174     output = "${base_target_name}_${target_cpu}.nexe.mojo"
176     executable(nexe_target_name) {
177       output_name = base_target_name
179       if (defined(invoker.cflags)) {
180         cflags = invoker.cflags
181       }
182       if (defined(invoker.cflags_c)) {
183         cflags_c = invoker.cflags_c
184       }
185       if (defined(invoker.cflags_cc)) {
186         cflags_cc = invoker.cflags_cc
187       }
188       if (defined(invoker.cflags_objc)) {
189         cflags_objc = invoker.cflags_objc
190       }
191       if (defined(invoker.cflags_objcc)) {
192         cflags_objcc = invoker.cflags_objcc
193       }
194       if (defined(invoker.defines)) {
195         defines = invoker.defines
196       }
197       if (defined(invoker.include_dirs)) {
198         include_dirs = invoker.include_dirs
199       }
200       if (defined(invoker.ldflags)) {
201         ldflags = invoker.ldflags
202       }
203       if (defined(invoker.lib_dirs)) {
204         lib_dirs = invoker.lib_dirs
205       }
206       if (defined(invoker.libs)) {
207         libs = invoker.libs
208       }
210       data_deps = []
211       if (defined(invoker.data_deps)) {
212         data_deps = invoker.data_deps
213       }
215       # Copy any necessary prebuilt artifacts.
216       if (mojo_use_prebuilt_mojo_shell) {
217         data_deps +=
218             [ rebase_path("mojo/public/tools:copy_mojo_shell", ".", mojo_root) ]
219       }
220       if (mojo_use_prebuilt_network_service) {
221         data_deps += [ rebase_path("mojo/public/tools:copy_network_service",
222                                    ".",
223                                    mojo_root) ]
224       }
226       deps = rebase_path([
227                            "mojo/public/c/system",
228                            "mojo/public/platform/nacl:system",
229                          ],
230                          ".",
231                          mojo_root)
232       deps += mojo_deps
233       if (defined(invoker.forward_dependent_configs_from)) {
234         forward_dependent_configs_from = invoker.forward_dependent_configs_from
235       }
236       if (defined(invoker.public_deps)) {
237         public_deps = invoker.public_deps
238       }
239       if (defined(invoker.all_dependent_configs)) {
240         all_dependent_configs = invoker.all_dependent_configs
241       }
242       if (defined(invoker.public_configs)) {
243         public_configs = invoker.public_configs
244       }
245       if (defined(invoker.check_includes)) {
246         check_includes = invoker.check_includes
247       }
248       if (defined(invoker.configs)) {
249         configs += invoker.configs
250       }
251       if (defined(invoker.data)) {
252         data = invoker.data
253       }
254       if (defined(invoker.inputs)) {
255         inputs = invoker.inputs
256       }
257       if (defined(invoker.public)) {
258         public = invoker.public
259       }
260       if (defined(invoker.sources)) {
261         sources = invoker.sources
262       }
263       if (defined(invoker.testonly)) {
264         testonly = invoker.testonly
265       }
267       visibility = [ ":${final_target_name}" ]
268     }
270     action(target_name) {
271       if (defined(invoker.testonly)) {
272         testonly = invoker.testonly
273       }
274       if (defined(invoker.visibility)) {
275         visibility = invoker.visibility
276       }
278       script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
280       input_path = "${root_out_dir}/${nexe_name}"
281       inputs = [
282         input_path,
283       ]
285       output_path = "${root_build_dir}/${base_target_name}/${output}"
286       outputs = [
287         output_path,
288       ]
290       deps = [
291         ":${nexe_target_name}",
292       ]
294       rebase_input = rebase_path(input_path, root_build_dir)
295       rebase_output = rebase_path(output_path, root_build_dir)
296       args = [
297         "--input=$rebase_input",
298         "--output=$rebase_output",
299         "--line=#!mojo mojo:nacl_content_handler",
300       ]
301     }
302   }
305 if (is_android) {
306   # Declares an Android Mojo application consisting of an .so file and a
307   # corresponding .dex.jar file.
308   #
309   # Variables:
310   #   input_so: the .so file to bundle
311   #   input_dex_jar: the .dex.jar file to bundle
312   #   deps / public_deps / data_deps (optional):
313   #       Dependencies. The targets that generate the .so/jar inputs should be
314   #       listed in either deps or public_deps.
315   #   output_name (optional): override for the output file name
316   template("mojo_android_application") {
317     assert(defined(invoker.input_so))
318     assert(defined(invoker.input_dex_jar))
320     zip_action_name = "${target_name}_zip"
321     zip_action_output = "$target_gen_dir/${target_name}.zip"
322     prepend_action_name = target_name
323     action(zip_action_name) {
324       visibility = [ ":$prepend_action_name" ]
325       script = "//build/android/gn/zip.py"
327       inputs = [
328         invoker.input_so,
329         invoker.input_dex_jar,
330       ]
332       output = zip_action_output
333       outputs = [
334         output,
335       ]
337       rebase_inputs = rebase_path(inputs, root_build_dir)
338       rebase_output = rebase_path(output, root_build_dir)
339       args = [
340         "--inputs=$rebase_inputs",
341         "--output=$rebase_output",
342       ]
344       if (defined(invoker.deps)) {
345         deps = invoker.deps
346       }
347       if (defined(invoker.public_deps)) {
348         public_deps = invoker.public_deps
349       }
350       if (defined(invoker.data_deps)) {
351         data_deps = invoker.data_deps
352       }
353     }
355     action(target_name) {
356       script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root)
358       base_target_name = target_name
359       if (defined(invoker.output_name)) {
360         base_target_name = invoker.output_name
361       }
363       input = zip_action_output
364       inputs = [
365         input,
366       ]
368       output = "${root_out_dir}/${base_target_name}/${base_target_name}.mojo"
369       outputs = [
370         output,
371       ]
373       rebase_input = rebase_path(input, root_build_dir)
374       rebase_output = rebase_path(output, root_build_dir)
375       args = [
376         "--input=$rebase_input",
377         "--output=$rebase_output",
378         "--line=#!mojo mojo:android_handler",
379       ]
381       public_deps = [
382         ":$zip_action_name",
383       ]
384     }
385   }