Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(573)

Side by Side Diff: build/secondary/tools/grit/grit_rule.gni

Issue 361633002: [Android][gn] Add android resources templates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-java
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 # Instantiate grit. This will produce a script target to run grit, and a 5 # Instantiate grit. This will produce a script target to run grit, and a
6 # static library that compiles the .cc files. 6 # static library that compiles the .cc files.
7 # 7 #
8 # Parameters 8 # Parameters
9 # 9 #
10 # source 10 # source
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 grit_resource_id_file = "//tools/gritsettings/resource_ids" 154 grit_resource_id_file = "//tools/gritsettings/resource_ids"
155 grit_info_script = "//tools/grit/grit_info.py" 155 grit_info_script = "//tools/grit/grit_info.py"
156 156
157 template("grit") { 157 template("grit") {
158 assert(defined(invoker.source), 158 assert(defined(invoker.source),
159 "\"source\" must be defined for the grit template $target_name") 159 "\"source\" must be defined for the grit template $target_name")
160 assert(!defined(invoker.sources) && !defined(invoker.outputs), 160 assert(!defined(invoker.sources) && !defined(invoker.outputs),
161 "Neither \"sources\" nor \"outputs\" can be defined for the grit " + 161 "Neither \"sources\" nor \"outputs\" can be defined for the grit " +
162 "template $target_name") 162 "template $target_name")
163 163
164 if (defined(invoker.resource_ids)) {
165 resource_ids = invoker.resource_ids
brettw 2014/07/11 20:00:44 Can you add these new variables to the documentati
166 } else {
167 resource_ids = grit_resource_id_file
168 }
169
170 if (defined(invoker.output_dir)) {
171 output_dir = invoker.output_dir
172 } else {
173 output_dir = target_gen_dir
174 }
175
164 # These are all passed as arguments to the script so have to be relative to 176 # These are all passed as arguments to the script so have to be relative to
165 # the build directory. 177 # the build directory.
166 resource_ids = 178 if (resource_ids != "") {
167 rebase_path(grit_resource_id_file, root_build_dir) 179 resource_ids = rebase_path(resource_ids, root_build_dir)
168 output_dir = rebase_path(target_gen_dir, root_build_dir) 180 }
181 rebased_output_dir = rebase_path(output_dir, root_build_dir)
169 source_path = rebase_path(invoker.source, root_build_dir) 182 source_path = rebase_path(invoker.source, root_build_dir)
170 183
171 if (defined(invoker.grit_flags)) { 184 if (defined(invoker.grit_flags)) {
172 grit_flags = invoker.grit_flags 185 grit_flags = invoker.grit_flags
173 } else { 186 } else {
174 grit_flags = [] # These are optional so default to empty list. 187 grit_flags = [] # These are optional so default to empty list.
175 } 188 }
176 189
177 grit_inputs_build_rel = exec_script(grit_info_script, 190 grit_inputs_build_rel = exec_script(grit_info_script,
178 [ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines") 191 [ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines")
179 # The inputs are relative to the current (build) directory, rebase to 192 # The inputs are relative to the current (build) directory, rebase to
180 # the current one. 193 # the current one.
181 grit_inputs = rebase_path(grit_inputs_build_rel, ".", root_build_dir) + [ 194 grit_inputs = rebase_path(grit_inputs_build_rel, ".", root_build_dir) + [
182 grit_resource_id_file, 195 grit_resource_id_file,
183 ] 196 ]
184 197
185 grit_outputs_build_rel = exec_script(grit_info_script, 198 grit_outputs_build_rel = exec_script(grit_info_script,
186 [ "--outputs", "$output_dir", source_path, "-f", resource_ids ] + 199 [ "--outputs", "$rebased_output_dir", source_path, "-f", resource_ids ] +
187 grit_flags, 200 grit_flags,
188 "list lines") 201 "list lines")
189 202
190 # The inputs are relative to the current (build) directory, rebase to 203 # The inputs are relative to the current (build) directory, rebase to
191 # the current one. 204 # the current one.
192 grit_outputs = rebase_path(grit_outputs_build_rel, ".", root_build_dir) 205 grit_outputs = rebase_path(grit_outputs_build_rel, ".", root_build_dir)
193 206
194 # The config and the action below get this visibility son only the generated 207 # The config and the action below get this visibility son only the generated
195 # source set can depend on them. The variable "target_name" will get 208 # source set can depend on them. The variable "target_name" will get
196 # overwritten inside the innter classes so we need to compute it here. 209 # overwritten inside the innter classes so we need to compute it here.
197 target_visibility = ":$target_name" 210 target_visibility = ":$target_name"
198 211
199 # The current grit setup makes an file in $target_gen_dir/grit/foo.h that 212 # The current grit setup makes an file in $output_dir/grit/foo.h that
200 # the source code expects to include via "grit/foo.h". It would be nice to 213 # the source code expects to include via "grit/foo.h". It would be nice to
201 # change this to including absolute paths relative to the root gen directory 214 # change this to including absolute paths relative to the root gen directory
202 # (like "mycomponent/foo.h"). This config sets up the include path. 215 # (like "mycomponent/foo.h"). This config sets up the include path.
203 grit_config = target_name + "_grit_config" 216 grit_config = target_name + "_grit_config"
204 config(grit_config) { 217 config(grit_config) {
205 include_dirs = [ target_gen_dir ] 218 include_dirs = [ output_dir ]
206 visibility = target_visibility 219 visibility = target_visibility
207 } 220 }
208 221
209 grit_custom_target = target_name + "_grit" 222 grit_custom_target = target_name + "_grit"
210 action(grit_custom_target) { 223 action(grit_custom_target) {
211 script = "//tools/grit/grit.py" 224 script = "//tools/grit/grit.py"
212 source_prereqs = grit_inputs 225 source_prereqs = grit_inputs
213 outputs = grit_outputs 226 outputs = grit_outputs
214 227
215 args = [ 228 args = [
216 "-i", source_path, "build", 229 "-i", source_path, "build",
217 "-f", resource_ids, 230 "-f", resource_ids,
218 "-o", output_dir, 231 "-o", rebased_output_dir,
219 ] + grit_defines + grit_flags 232 ] + grit_defines + grit_flags
220 233
221 visibility = target_visibility 234 visibility = target_visibility
222 235
223 if (defined(invoker.deps)) { 236 if (defined(invoker.deps)) {
224 deps = invoker.deps 237 deps = invoker.deps
225 } 238 }
226 } 239 }
227 240
228 # This is the thing that people actually link with, it must be named the 241 # This is the thing that people actually link with, it must be named the
229 # same as the argument the template was invoked with. 242 # same as the argument the template was invoked with.
230 source_set(target_name) { 243 source_set(target_name) {
231 # Since we generate a file, we need to be run before the targets that 244 # Since we generate a file, we need to be run before the targets that
232 # depend on us. 245 # depend on us.
233 sources = grit_outputs 246 sources = grit_outputs
234 247
235 # Deps set on the template invocation will go on the grit script running 248 # Deps set on the template invocation will go on the grit script running
236 # target rather than this library. 249 # target rather than this library.
237 deps = [ ":$grit_custom_target" ] 250 deps = [ ":$grit_custom_target" ]
238 direct_dependent_configs = [ ":$grit_config" ] 251 direct_dependent_configs = [ ":$grit_config" ]
239 252
240 if (defined(invoker.visibility)) { 253 if (defined(invoker.visibility)) {
241 visibility = invoker.visibility 254 visibility = invoker.visibility
242 } 255 }
243 if (defined(invoker.output_name)) { 256 if (defined(invoker.output_name)) {
244 output_name = invoker.output_name 257 output_name = invoker.output_name
245 } 258 }
246 } 259 }
247 } 260 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698