OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 # This file introduces two related templates that act like action and | 5 # This file introduces two related templates that act like action and |
6 # action_foreach but instead of running a Python script, it will compile a | 6 # action_foreach but instead of running a Python script, it will compile a |
7 # given tool in the host toolchain and run that (either once or over the list | 7 # given tool in the host toolchain and run that (either once or over the list |
8 # of inputs, depending on the variant). | 8 # of inputs, depending on the variant). |
9 # | 9 # |
10 # Parameters | 10 # Parameters |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 | 74 |
75 template("compiled_action") { | 75 template("compiled_action") { |
76 assert(defined(invoker.tool), "tool must be defined for $target_name") | 76 assert(defined(invoker.tool), "tool must be defined for $target_name") |
77 assert(defined(invoker.outputs), "outputs must be defined for $target_name") | 77 assert(defined(invoker.outputs), "outputs must be defined for $target_name") |
78 assert(defined(invoker.args), "args must be defined for $target_name") | 78 assert(defined(invoker.args), "args must be defined for $target_name") |
79 | 79 |
80 assert(!defined(invoker.sources), | 80 assert(!defined(invoker.sources), |
81 "compiled_action doesn't take a sources arg. Use inputs instead.") | 81 "compiled_action doesn't take a sources arg. Use inputs instead.") |
82 | 82 |
83 action(target_name) { | 83 action(target_name) { |
84 if (defined(invoker.visibility)) { | 84 deps = [] |
85 visibility = invoker.visibility | 85 inputs = [] |
86 } | 86 forward_variables_from(invoker, |
| 87 [ |
| 88 "deps", |
| 89 "inputs", |
| 90 "outputs", |
| 91 "testonly", |
| 92 "visibility", |
| 93 ]) |
87 | 94 |
88 script = "//build/gn_run_binary.py" | 95 script = "//build/gn_run_binary.py" |
89 | 96 |
90 if (defined(invoker.inputs)) { | |
91 inputs = invoker.inputs | |
92 } else { | |
93 inputs = [] | |
94 } | |
95 outputs = invoker.outputs | |
96 | |
97 # Constuct the host toolchain version of the tool. | 97 # Constuct the host toolchain version of the tool. |
98 host_tool = invoker.tool + "($host_toolchain)" | 98 host_tool = invoker.tool + "($host_toolchain)" |
99 | 99 |
100 # Get the path to the executable. Currently, this assumes that the tool | 100 # Get the path to the executable. Currently, this assumes that the tool |
101 # does not specify output_name so that the target name is the name to use. | 101 # does not specify output_name so that the target name is the name to use. |
102 # If that's not the case, we'll need another argument to the script to | 102 # If that's not the case, we'll need another argument to the script to |
103 # specify this, since we can't know what the output name is (it might be in | 103 # specify this, since we can't know what the output name is (it might be in |
104 # another file not processed yet). | 104 # another file not processed yet). |
105 host_executable = | 105 host_executable = |
106 get_label_info(host_tool, "root_out_dir") + "/" + | 106 get_label_info(host_tool, "root_out_dir") + "/" + |
107 get_label_info(host_tool, "name") + _host_executable_suffix | 107 get_label_info(host_tool, "name") + _host_executable_suffix |
108 | 108 |
109 # Add the executable itself as an input. | 109 # Add the executable itself as an input. |
110 inputs += [ host_executable ] | 110 inputs += [ host_executable ] |
111 | 111 |
112 deps = [ | 112 deps += [ host_tool ] |
113 host_tool, | |
114 ] | |
115 if (defined(invoker.deps)) { | |
116 deps += invoker.deps | |
117 } | |
118 | 113 |
119 # The script takes as arguments the binary to run, and then the arguments | 114 # The script takes as arguments the binary to run, and then the arguments |
120 # to pass it. | 115 # to pass it. |
121 args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args | 116 args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args |
122 } | 117 } |
123 } | 118 } |
124 | 119 |
125 template("compiled_action_foreach") { | 120 template("compiled_action_foreach") { |
126 assert(defined(invoker.sources), "sources must be defined for $target_name") | 121 assert(defined(invoker.sources), "sources must be defined for $target_name") |
127 assert(defined(invoker.tool), "tool must be defined for $target_name") | 122 assert(defined(invoker.tool), "tool must be defined for $target_name") |
128 assert(defined(invoker.outputs), "outputs must be defined for $target_name") | 123 assert(defined(invoker.outputs), "outputs must be defined for $target_name") |
129 assert(defined(invoker.args), "args must be defined for $target_name") | 124 assert(defined(invoker.args), "args must be defined for $target_name") |
130 | 125 |
131 action_foreach(target_name) { | 126 action_foreach(target_name) { |
132 # Otherwise this is a standalone action, define visibility if requested. | 127 deps = [] |
133 if (defined(invoker.visibility)) { | 128 inputs = [] |
134 visibility = invoker.visibility | 129 forward_variables_from(invoker, |
135 } | 130 [ |
| 131 "deps", |
| 132 "inputs", |
| 133 "outputs", |
| 134 "sources", |
| 135 "testonly", |
| 136 "visibility", |
| 137 ]) |
136 | 138 |
137 script = "//build/gn_run_binary.py" | 139 script = "//build/gn_run_binary.py" |
138 sources = invoker.sources | |
139 | |
140 if (defined(invoker.inputs)) { | |
141 inputs = invoker.inputs | |
142 } else { | |
143 inputs = [] | |
144 } | |
145 outputs = invoker.outputs | |
146 | 140 |
147 # Constuct the host toolchain version of the tool. | 141 # Constuct the host toolchain version of the tool. |
148 host_tool = invoker.tool + "($host_toolchain)" | 142 host_tool = invoker.tool + "($host_toolchain)" |
149 | 143 |
150 # Get the path to the executable. Currently, this assumes that the tool | 144 # Get the path to the executable. Currently, this assumes that the tool |
151 # does not specify output_name so that the target name is the name to use. | 145 # does not specify output_name so that the target name is the name to use. |
152 # If that's not the case, we'll need another argument to the script to | 146 # If that's not the case, we'll need another argument to the script to |
153 # specify this, since we can't know what the output name is (it might be in | 147 # specify this, since we can't know what the output name is (it might be in |
154 # another file not processed yet). | 148 # another file not processed yet). |
155 host_executable = | 149 host_executable = |
156 get_label_info(host_tool, "root_out_dir") + "/" + | 150 get_label_info(host_tool, "root_out_dir") + "/" + |
157 get_label_info(host_tool, "name") + _host_executable_suffix | 151 get_label_info(host_tool, "name") + _host_executable_suffix |
158 | 152 |
159 # Add the executable itself as an input. | 153 # Add the executable itself as an input. |
160 inputs += [ host_executable ] | 154 inputs += [ host_executable ] |
161 | 155 |
162 deps = [ | 156 deps += [ host_tool ] |
163 host_tool, | |
164 ] | |
165 if (defined(invoker.deps)) { | |
166 deps += invoker.deps | |
167 } | |
168 | 157 |
169 # The script takes as arguments the binary to run, and then the arguments | 158 # The script takes as arguments the binary to run, and then the arguments |
170 # to pass it. | 159 # to pass it. |
171 args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args | 160 args = [ rebase_path(host_executable, root_build_dir) ] + invoker.args |
172 } | 161 } |
173 } | 162 } |
OLD | NEW |