OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 # Rules to generate python packaged applications for Mojo | |
6 | |
7 import("../mojo_sdk.gni") | |
8 | |
9 template("python_package") { | |
10 action(target_name) { | |
11 script = rebase_path("mojo/public/tools/gn/zip.py", ".", mojo_root) | |
12 | |
13 inputs = invoker.sources | |
14 | |
15 deps = [] | |
16 zip_inputs = [] | |
17 | |
18 if (defined(invoker.deps)) { | |
19 deps += invoker.deps | |
20 foreach(d, invoker.deps) { | |
21 dep_name = get_label_info(d, "name") | |
22 dep_target_out_dir = get_label_info(d, "target_out_dir") | |
23 zip_inputs += [ "$dep_target_out_dir/$dep_name.pyzip" ] | |
24 } | |
25 } | |
26 | |
27 if (defined(invoker.datadeps)) { | |
28 datadeps = invoker.datadeps | |
29 } | |
30 | |
31 output = "$target_out_dir/$target_name.pyzip" | |
32 outputs = [ | |
33 output, | |
34 ] | |
35 | |
36 rebase_base_dir = | |
37 rebase_path(get_label_info(":$target_name", "dir"), root_build_dir) | |
38 rebase_inputs = rebase_path(inputs, root_build_dir) | |
39 rebase_zip_inputs = rebase_path(zip_inputs, root_build_dir) | |
40 rebase_output = rebase_path(output, root_build_dir) | |
41 args = [ | |
42 "--base-dir=$rebase_base_dir", | |
43 "--inputs=$rebase_inputs", | |
44 "--zip-inputs=$rebase_zip_inputs", | |
45 "--output=$rebase_output", | |
46 ] | |
47 } | |
48 } | |
49 | |
50 # Use this template to generate a .mojo python application. One of the source | |
51 # files should be named __mojo__.py and contain a MojoMain function as the | |
52 # entry point. Dependencies of python_packaged_application targets should be | |
53 # either mojom targets (and specified using the mojom_deps variable) or | |
54 # python_package targets. | |
55 template("python_packaged_application") { | |
56 package_name = "${target_name}_package" | |
57 package_output = "$target_out_dir/$package_name.pyzip" | |
58 | |
59 if (defined(invoker.output_name)) { | |
60 mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo" | |
61 } else { | |
62 mojo_output = "$root_out_dir/" + target_name + ".mojo" | |
63 } | |
64 | |
65 if (defined(invoker.debug) && invoker.debug) { | |
66 content_handler_param = "?debug=true" | |
67 } else { | |
68 content_handler_param = "" | |
69 } | |
70 | |
71 python_package(package_name) { | |
72 sources = invoker.sources | |
73 if (defined(invoker.deps)) { | |
74 deps = invoker.deps | |
75 } | |
76 if (defined(invoker.mojom_deps)) { | |
77 mojom_deps = invoker.mojom_deps | |
78 } | |
79 if (defined(invoker.datadeps)) { | |
80 datadeps = invoker.datadeps | |
81 } | |
82 } | |
83 | |
84 action(target_name) { | |
85 script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root) | |
86 | |
87 input = package_output | |
88 inputs = [ | |
89 input, | |
90 ] | |
91 | |
92 output = mojo_output | |
93 outputs = [ | |
94 output, | |
95 ] | |
96 | |
97 deps = [ | |
98 ":$package_name", | |
99 ] | |
100 if (defined(invoker.deps)) { | |
101 deps += invoker.deps | |
102 } | |
103 if (defined(invoker.mojom_deps)) { | |
104 deps += invoker.mojom_deps | |
105 } | |
106 if (defined(invoker.datadeps)) { | |
107 datadeps = invoker.datadeps | |
108 } | |
109 | |
110 rebase_input = rebase_path(input, root_build_dir) | |
111 rebase_output = rebase_path(output, root_build_dir) | |
112 args = [ | |
113 "--input=$rebase_input", | |
114 "--output=$rebase_output", | |
115 "--line=#!mojo mojo:py_content_handler${content_handler_param}", | |
116 ] | |
117 } | |
118 } | |
OLD | NEW |