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

Side by Side Diff: build/config/android/rules.gni

Issue 361633002: [Android][gn] Add android resources templates (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-java
Patch Set: Fix bad rebase 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
« no previous file with comments | « build/config/android/internal_rules.gni ('k') | build/secondary/tools/grit/grit_rule.gni » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 import("//build/config/android/config.gni") 5 import("//build/config/android/config.gni")
6 import("//build/config/android/internal_rules.gni") 6 import("//build/config/android/internal_rules.gni")
7 import("//tools/grit/grit_rule.gni")
8
9 assert(is_android)
10
7 11
8 # Declare a jni target 12 # Declare a jni target
9 # 13 #
10 # This target generates the native jni bindings for a set of .java files. 14 # This target generates the native jni bindings for a set of .java files.
11 # 15 #
12 # See base/android/jni_generator/jni_generator.py for more info about the 16 # See base/android/jni_generator/jni_generator.py for more info about the
13 # format of generating JNI bindings. 17 # format of generating JNI bindings.
14 # 18 #
15 # Variables 19 # Variables
16 # sources: list of .java files to generate jni for 20 # sources: list of .java files to generate jni for
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 if (defined(invoker.deps)) { 164 if (defined(invoker.deps)) {
161 deps += invoker.deps 165 deps += invoker.deps
162 } 166 }
163 if (defined(invoker.forward_dependent_configs_from)) { 167 if (defined(invoker.forward_dependent_configs_from)) {
164 forward_dependent_configs_from = invoker.forward_dependent_configs_from 168 forward_dependent_configs_from = invoker.forward_dependent_configs_from
165 } 169 }
166 direct_dependent_configs = [ ":jni_includes_${target_name}" ] 170 direct_dependent_configs = [ ":jni_includes_${target_name}" ]
167 } 171 }
168 } 172 }
169 173
174
170 # Declare a target for c-preprocessor-generated java files 175 # Declare a target for c-preprocessor-generated java files
171 # 176 #
172 # This target generates java files using the host C pre-processor. Each file in 177 # This target generates java files using the host C pre-processor. Each file in
173 # sources will be compiled using the C pre-processor. If include_path is 178 # sources will be compiled using the C pre-processor. If include_path is
174 # specified, it will be passed (with --I) to the pre-processor. 179 # specified, it will be passed (with --I) to the pre-processor.
175 # 180 #
176 # This target will create a single .srcjar. Adding this target to an 181 # This target will create a single .srcjar. Adding this target to an
177 # android_library target's srcjar_deps will make the generated java files be 182 # android_library target's srcjar_deps will make the generated java files be
178 # included in that library's final outputs. 183 # included in that library's final outputs.
179 # 184 #
180 # Variables 185 # Variables
181 # sources: list of files to be processed by the C pre-processor. For each 186 # sources: list of files to be processed by the C pre-processor. For each
182 # file in sources, there will be one .java file in the final .srcjar. For a 187 # file in sources, there will be one .java file in the final .srcjar. For a
183 # file named FooBar.template, a java file will be created with name 188 # file named FooBar.template, a java file will be created with name
184 # FooBar.java. 189 # FooBar.java.
185 # inputs: additional compile-time dependencies. Any files 190 # inputs: additional compile-time dependencies. Any files
186 # `#include`-ed in the templates should be listed here. 191 # `#include`-ed in the templates should be listed here.
187 # package_name: this will be the subdirectory for each .java file in the .srcj ar. 192 # package_name: this will be the subdirectory for each .java file in the
193 # .srcjar.
188 # 194 #
189 # Example 195 # Example
190 # java_cpp_template("foo_generated_enum") { 196 # java_cpp_template("foo_generated_enum") {
191 # sources = [ 197 # sources = [
192 # "android/java/templates/Foo.template", 198 # "android/java/templates/Foo.template",
193 # ] 199 # ]
194 # inputs = [ 200 # inputs = [
195 # "android/java/templates/native_foo_header.h", 201 # "android/java/templates/native_foo_header.h",
196 # ] 202 # ]
197 # 203 #
(...skipping 12 matching lines...) Expand all
210 216
211 action_foreach("${target_name}__apply_gcc") { 217 action_foreach("${target_name}__apply_gcc") {
212 script = "//build/android/gyp/gcc_preprocess.py" 218 script = "//build/android/gyp/gcc_preprocess.py"
213 if (defined(invoker.inputs)) { 219 if (defined(invoker.inputs)) {
214 inputs = invoker.inputs + [] 220 inputs = invoker.inputs + []
215 } 221 }
216 depfile = "${target_gen_dir}/${target_name}.d" 222 depfile = "${target_gen_dir}/${target_name}.d"
217 223
218 sources = invoker.sources 224 sources = invoker.sources
219 225
220 gen_dir = "${target_gen_dir}/${package_name}" 226 gen_dir = "${target_gen_dir}/${target_name}/java_cpp_template/${package_name }"
221 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java" 227 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
222 228
223 outputs = [ 229 outputs = [
224 depfile, 230 depfile,
225 gcc_template_output_pattern 231 gcc_template_output_pattern
226 ] 232 ]
227 233
228 args = [ 234 args = [
229 "--depfile", rebase_path(depfile, root_build_dir), 235 "--depfile", rebase_path(depfile, root_build_dir),
230 "--include-path", rebase_path(include_path, root_build_dir), 236 "--include-path", rebase_path(include_path, root_build_dir),
(...skipping 12 matching lines...) Expand all
243 base_dir = base_gen_dir 249 base_dir = base_gen_dir
244 } 250 }
245 251
246 group(target_name) { 252 group(target_name) {
247 deps = [ 253 deps = [
248 ":${target_name}__zip_srcjar" 254 ":${target_name}__zip_srcjar"
249 ] 255 ]
250 } 256 }
251 } 257 }
252 258
259
260 # Declare an Android resources target
261 #
262 # This creates a resources zip file that will be used when building an Android
263 # library or apk and included into a final apk.
264 #
265 # To include these resources in a library/apk, this target should be listed in
266 # the library's deps. A library/apk will also include any resources used by its
267 # own dependencies.
268 #
269 # Variables
270 # deps: Specifies the dependencies of this target. Any Android resources
271 # listed in deps will be included by libraries/apks that depend on this
272 # target.
273 # resource_dirs: List of directories containing resources for this target.
274 # android_manifest: AndroidManifest.xml for this target. Defaults to
275 # //build/android/AndroidManifest.xml.
276 # custom_package: java package for generated .java files.
277 # v14_verify_only: If true, don't generate v14/v17 resources and just verify
278 # that the resources are v14-compliant (see
279 # build/android/gyp/generate_v14_compatible_resources.py). Defaults to
280 # false.
281 #
282 # Example
283 # android_resources("foo_resources") {
284 # deps = [":foo_strings_grd"]
285 # resource_dirs = ["res"]
286 # custom_package = "org.chromium.foo"
287 # }
288 template("android_resources") {
289 assert(defined(invoker.resource_dirs))
290
291 base_path = "$target_gen_dir/$target_name"
292 zip_path = base_path + ".resources.zip"
293 srcjar_path = base_path + ".srcjar"
294 build_config = base_path + ".build_config"
295
296 write_build_config("${target_name}__build_config") {
297 type = "android_resources"
298 resources_zip = zip_path
299 srcjar = srcjar_path
300 if (defined(invoker.deps)) {
301 deps = invoker.deps
302 }
303 }
304
305 android_manifest = "//build/android/AndroidManifest.xml"
306 if (defined(invoker.android_manifest)) {
307 android_manifest = invoker.android_manifest
308 }
309
310 process_resources("${target_name}__process_resources") {
311 resource_dirs = invoker.resource_dirs
312 if (defined(invoker.custom_package)) {
313 custom_package = invoker.custom_package
314 }
315
316 if (defined(invoker.v14_verify_only)) {
317 v14_verify_only = invoker.v14_verify_only
318 }
319 }
320
321 group(target_name) {
322 deps = [
323 ":${target_name}__build_config",
324 ":${target_name}__process_resources",
325 ]
326 }
327 }
328
329
330 # Declare a target that generates localized strings.xml from a .grd file.
331 #
332 # If this target is included in the deps of an android resources/library/apk,
333 # the strings.xml will be included with that target.
334 #
335 # Variables
336 # deps: Specifies the dependencies of this target.
337 # grd_file: Path to the .grd file to generate strings.xml from.
338 #
339 # Example
340 # java_strings_grd("foo_strings_grd") {
341 # grd_file = "foo_strings.grd"
342 # }
343 template("java_strings_grd") {
344 base_path = "$target_gen_dir/$target_name"
345 resources_zip = base_path + ".resources.zip"
346
347 write_build_config("${target_name}__build_config") {
348 type = "android_resources"
349 if (defined(invoker.deps)) {
350 deps = invoker.deps
351 }
352 }
353
354 grit_target_name = "${target_name}__grit"
355 grit_output_dir = base_path + "_grit_output"
356 grit(grit_target_name) {
357 grit_flags = [
358 "-E", "ANDROID_JAVA_TAGGED_ONLY=false",
359 ]
360 output_dir = grit_output_dir
361 resource_ids = ""
362 source = invoker.grd_file
363 }
364
365 # This needs to get outputs from grit's internal target, not the final
366 # source_set.
367 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
368
369 zip("${target_name}__zip") {
370 base_dir = grit_output_dir
371 inputs = generate_strings_outputs
372 output = resources_zip
373 }
374
375 group(target_name) {
376 deps = [
377 ":${target_name}__build_config",
378 ":${target_name}__zip",
379 ]
380 }
381 }
382
383
253 # Declare an Android library target 384 # Declare an Android library target
254 # 385 #
255 # This target creates an Android library containing java code and Android 386 # This target creates an Android library containing java code and Android
256 # resources. 387 # resources.
257 # 388 #
258 # Variables 389 # Variables
259 # deps: Specifies the dependencies of this target. Java targets in this list 390 # deps: Specifies the dependencies of this target. Java targets in this list
260 # will be added to the javac classpath. 391 # will be added to the javac classpath. Android resources in dependencies
392 # will be used when building this library.
261 # java_files: List of .java files included in this library. 393 # java_files: List of .java files included in this library.
262 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars 394 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars
263 # will be added to java_files and be included in this library. 395 # will be added to java_files and be included in this library.
264 # 396 #
265 # jar_excluded_patterns: List of patterns of .class files to exclude from the final jar. 397 # jar_excluded_patterns: List of patterns of .class files to exclude from the
398 # final jar.
266 # 399 #
267 # Example 400 # Example
268 # android_library("foo_java") { 401 # android_library("foo_java") {
269 # java_files = [ 402 # java_files = [
270 # "android/org/chromium/foo/Foo.java", 403 # "android/org/chromium/foo/Foo.java",
271 # "android/org/chromium/foo/FooInterface.java", 404 # "android/org/chromium/foo/FooInterface.java",
272 # "android/org/chromium/foo/FooService.java", 405 # "android/org/chromium/foo/FooService.java",
273 # ] 406 # ]
274 # deps = [ 407 # deps = [
275 # ":bar_java" 408 # ":bar_java"
276 # ] 409 # ]
277 # srcjar_deps = [ 410 # srcjar_deps = [
278 # ":foo_generated_enum" 411 # ":foo_generated_enum"
279 # ] 412 # ]
280 # jar_excluded_patterns = [ 413 # jar_excluded_patterns = [
281 # "*/FooService.class", "*/FooService##*.class" 414 # "*/FooService.class", "*/FooService##*.class"
282 # ] 415 # ]
283 # } 416 # }
284 template("android_library") { 417 template("android_library") {
285 #TODO(cjhopman): resources 418 assert(defined(invoker.java_files))
286 419
287 assert(defined(invoker.java_files)) 420 base_path = "$target_gen_dir/$target_name"
288 dep = ":${target_name}"
289 base_path = get_label_info(dep, "target_gen_dir") + "/" + target_name
290 build_config = base_path + ".build_config" 421 build_config = base_path + ".build_config"
291 422
292 write_build_config("${target_name}__build_config") { 423 write_build_config("${target_name}__build_config") {
293 type = "android_library" 424 type = "android_library"
294 425
295 deps = [] 426 deps = []
296 if (defined(invoker.deps)) { 427 if (defined(invoker.deps)) {
297 deps += invoker.deps 428 deps += invoker.deps
298 } 429 }
299 430
300 # base_path 431 # base_path
301 } 432 }
302 433
303 jar_path = base_path + ".jar" 434 jar_path = base_path + ".jar"
304 android_java_library(target_name) { 435 android_java_library(target_name) {
305 java_files = invoker.java_files 436 java_files = invoker.java_files
306 build_config = build_config 437 build_config = build_config
307 438
308 if (defined(invoker.jar_excluded_patterns)) { 439 if (defined(invoker.jar_excluded_patterns)) {
309 jar_excluded_patterns = invoker.jar_excluded_patterns 440 jar_excluded_patterns = invoker.jar_excluded_patterns
310 } 441 }
311 442
312 if (defined(invoker.srcjar_deps)) { 443 if (defined(invoker.srcjar_deps)) {
313 srcjar_deps = invoker.srcjar_deps 444 srcjar_deps = invoker.srcjar_deps
314 } 445 }
315 } 446 }
316 } 447 }
317
OLDNEW
« no previous file with comments | « build/config/android/internal_rules.gni ('k') | build/secondary/tools/grit/grit_rule.gni » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698