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

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: 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 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 #
(...skipping 30 matching lines...) Expand all
210 215
211 action_foreach("${target_name}__apply_gcc") { 216 action_foreach("${target_name}__apply_gcc") {
212 script = "//build/android/gyp/gcc_preprocess.py" 217 script = "//build/android/gyp/gcc_preprocess.py"
213 if (defined(invoker.source_prereqs)) { 218 if (defined(invoker.source_prereqs)) {
214 source_prereqs = invoker.source_prereqs + [] 219 source_prereqs = invoker.source_prereqs + []
215 } 220 }
216 depfile = "${target_gen_dir}/${target_name}.d" 221 depfile = "${target_gen_dir}/${target_name}.d"
217 222
218 sources = invoker.sources 223 sources = invoker.sources
219 224
220 gen_dir = "${target_gen_dir}/${package_name}" 225 gen_dir = "${target_gen_dir}/${target_name}/java_cpp_template/${package_name }"
221 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java" 226 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java"
222 227
223 outputs = [ 228 outputs = [
224 depfile, 229 depfile,
225 gcc_template_output_pattern 230 gcc_template_output_pattern
226 ] 231 ]
227 232
228 args = [ 233 args = [
229 "--depfile", rebase_path(depfile, root_build_dir), 234 "--depfile", rebase_path(depfile, root_build_dir),
230 "--include-path", rebase_path(include_path, root_build_dir), 235 "--include-path", rebase_path(include_path, root_build_dir),
(...skipping 12 matching lines...) Expand all
243 base_dir = base_gen_dir 248 base_dir = base_gen_dir
244 } 249 }
245 250
246 group(target_name) { 251 group(target_name) {
247 deps = [ 252 deps = [
248 ":${target_name}__zip_srcjar" 253 ":${target_name}__zip_srcjar"
249 ] 254 ]
250 } 255 }
251 } 256 }
252 257
258
259 # Declare an Android resources target
260 #
261 # This creates a resources zip file that will be used when building an Android
262 # library or apk and included into a final apk.
263 #
264 # To include these resources in a library/apk, this target should be listed in
265 # the library's deps. A library/apk will also include any resources used by its
266 # own dependencies.
267 #
268 # Variables
269 # deps: Specifies the dependencies of this target. Any Android resources
270 # listed in deps will be included by libraries/apks that depend on this
271 # target.
272 # resource_dirs: List of directories containing resources for this target.
273 # android_manifest: AndroidManifest.xml for this target. Defaults to
274 # //build/android/AndroidManifest.xml.
275 # custom_package: java package for generated .java files.
276 # v14_verify_only: If true, don't generate v14/v17 resources and just verify
277 # that the resources are v14-compliant (see
278 # build/android/gyp/generate_v14_compatible_resources.py). Defaults to false .
brettw 2014/07/11 20:00:44 80 cols here & below.
279 #
280 # Example
281 # android_resources("foo_resources") {
282 # deps = [":foo_strings_grd"]
283 # resource_dirs = ["res"]
284 # custom_package = "org.chromium.foo"
285 # }
286 template("android_resources") {
287 assert(defined(invoker.resource_dirs))
288
289 base_path = "$target_gen_dir/$target_name"
290 zip_path = base_path + ".resources.zip"
291 srcjar_path = base_path + ".srcjar"
292 build_config = base_path + ".build_config"
293
294 write_build_config("${target_name}__build_config") {
295 type = "android_resources"
296 resources_zip = zip_path
297 srcjar = srcjar_path
298 if (defined(invoker.deps)) {
299 deps = invoker.deps
300 }
301 }
302
303 android_manifest = "//build/android/AndroidManifest.xml"
304 if (defined(invoker.android_manifest)) {
305 android_manifest = invoker.android_manifest
306 }
307
308 process_resources("${target_name}__process_resources") {
309 resource_dirs = invoker.resource_dirs
310 if (defined(invoker.custom_package)) {
311 custom_package = invoker.custom_package
312 }
313
314 if (defined(invoker.v14_verify_only)) {
315 v14_verify_only = invoker.v14_verify_only
316 }
317 }
318
319 group(target_name) {
320 deps = [
321 ":${target_name}__build_config",
322 ":${target_name}__process_resources",
323 ]
324 }
325 }
326
327
328 # Declare a target that generates localized strings.xml from a .grd file.
329 #
330 # If this target is included in the deps of an android resources/library/apk,
331 # the strings.xml will be included with that target.
332 #
333 # Variables
334 # deps: Specifies the dependencies of this target.
335 # grd_file: Path to the .grd file to generate strings.xml from.
336 #
337 # Example
338 # java_strings_grd("foo_strings_grd") {
339 # grd_file = "foo_strings.grd"
340 # }
341 template("java_strings_grd") {
342 base_path = "$target_gen_dir/$target_name"
343 resources_zip = base_path + ".resources.zip"
344
345 write_build_config("${target_name}__build_config") {
346 type = "android_resources"
347 if (defined(invoker.deps)) {
348 deps = invoker.deps
349 }
350 }
351
352 grit_target_name = "${target_name}__grit"
353 grit_output_dir = base_path + "_grit_output"
354 grit(grit_target_name) {
355 grit_flags = [
356 "-E", "ANDROID_JAVA_TAGGED_ONLY=false",
357 ]
358 output_dir = grit_output_dir
359 resource_ids = ""
360 source = invoker.grd_file
361 }
362
363 # This needs to get outputs from grit's internal target, not the final source_ set.
364 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit")
365
366 zip("${target_name}__zip") {
367 base_dir = grit_output_dir
368 inputs = generate_strings_outputs
369 output = resources_zip
370 }
371
372 group(target_name) {
373 deps = [
374 ":${target_name}__build_config",
375 ":${target_name}__zip",
376 ]
377 }
378 }
379
380
253 # Declare an Android library target 381 # Declare an Android library target
254 # 382 #
255 # This target creates an Android library containing java code and Android 383 # This target creates an Android library containing java code and Android
256 # resources. 384 # resources.
257 # 385 #
258 # Variables 386 # Variables
259 # deps: Specifies the dependencies of this target. Java targets in this list 387 # deps: Specifies the dependencies of this target. Java targets in this list
260 # will be added to the javac classpath. 388 # will be added to the javac classpath. Android resources in dependencies
389 # will be used when building this library.
261 # java_files: List of .java files included in this library. 390 # java_files: List of .java files included in this library.
262 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars 391 # 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. 392 # will be added to java_files and be included in this library.
264 # 393 #
265 # jar_excluded_patterns: List of patterns of .class files to exclude from the final jar. 394 # jar_excluded_patterns: List of patterns of .class files to exclude from the final jar.
266 # 395 #
267 # Example 396 # Example
268 # android_library("foo_java") { 397 # android_library("foo_java") {
269 # java_files = [ 398 # java_files = [
270 # "android/org/chromium/foo/Foo.java", 399 # "android/org/chromium/foo/Foo.java",
271 # "android/org/chromium/foo/FooInterface.java", 400 # "android/org/chromium/foo/FooInterface.java",
272 # "android/org/chromium/foo/FooService.java", 401 # "android/org/chromium/foo/FooService.java",
273 # ] 402 # ]
274 # deps = [ 403 # deps = [
275 # ":bar_java" 404 # ":bar_java"
276 # ] 405 # ]
277 # srcjar_deps = [ 406 # srcjar_deps = [
278 # ":foo_generated_enum" 407 # ":foo_generated_enum"
279 # ] 408 # ]
280 # jar_excluded_patterns = [ 409 # jar_excluded_patterns = [
281 # "*/FooService.class", "*/FooService##*.class" 410 # "*/FooService.class", "*/FooService##*.class"
282 # ] 411 # ]
283 # } 412 # }
284 template("android_library") { 413 template("android_library") {
285 #TODO(cjhopman): resources 414 assert(defined(invoker.java_files))
286 415
287 assert(defined(invoker.java_files)) 416 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" 417 build_config = base_path + ".build_config"
291 418
292 write_build_config("${target_name}__build_config") { 419 write_build_config("${target_name}__build_config") {
293 type = "android_library" 420 type = "android_library"
294 421
295 deps = [] 422 deps = []
296 if (defined(invoker.deps)) { 423 if (defined(invoker.deps)) {
297 deps += invoker.deps 424 deps += invoker.deps
298 } 425 }
299 426
300 # base_path 427 # base_path
301 } 428 }
302 429
303 jar_path = base_path + ".jar" 430 jar_path = base_path + ".jar"
304 android_java_library(target_name) { 431 android_java_library(target_name) {
305 java_files = invoker.java_files 432 java_files = invoker.java_files
306 build_config = build_config 433 build_config = build_config
307 434
308 if (defined(invoker.jar_excluded_patterns)) { 435 if (defined(invoker.jar_excluded_patterns)) {
309 jar_excluded_patterns = invoker.jar_excluded_patterns 436 jar_excluded_patterns = invoker.jar_excluded_patterns
310 } 437 }
311 438
312 if (defined(invoker.srcjar_deps)) { 439 if (defined(invoker.srcjar_deps)) {
313 srcjar_deps = invoker.srcjar_deps 440 srcjar_deps = invoker.srcjar_deps
314 } 441 }
315 } 442 }
316 } 443 }
317
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698