OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import("//base/android/linker/config.gni") |
| 6 import("//build/config/android/config.gni") |
| 7 import("//build/config/android/internal_rules.gni") |
| 8 import("//third_party/android_platform/config.gni") |
| 9 import("//tools/grit/grit_rule.gni") |
| 10 |
| 11 assert(is_android) |
| 12 |
| 13 # Declare a jni target |
| 14 # |
| 15 # This target generates the native jni bindings for a set of .java files. |
| 16 # |
| 17 # See base/android/jni_generator/jni_generator.py for more info about the |
| 18 # format of generating JNI bindings. |
| 19 # |
| 20 # Variables |
| 21 # sources: list of .java files to generate jni for |
| 22 # jni_package: subdirectory path for generated bindings |
| 23 # |
| 24 # Example |
| 25 # generate_jni("foo_jni") { |
| 26 # sources = [ |
| 27 # "android/java/src/org/chromium/foo/Foo.java", |
| 28 # "android/java/src/org/chromium/foo/FooUtil.java", |
| 29 # ] |
| 30 # jni_package = "foo" |
| 31 # } |
| 32 template("generate_jni") { |
| 33 set_sources_assignment_filter([]) |
| 34 if (defined(invoker.testonly)) { |
| 35 testonly = invoker.testonly |
| 36 } |
| 37 |
| 38 assert(defined(invoker.sources)) |
| 39 assert(defined(invoker.jni_package)) |
| 40 jni_package = invoker.jni_package |
| 41 base_output_dir = "${target_gen_dir}/${target_name}" |
| 42 package_output_dir = "${base_output_dir}/${jni_package}" |
| 43 jni_output_dir = "${package_output_dir}/jni" |
| 44 |
| 45 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h" |
| 46 |
| 47 foreach_target_name = "${target_name}__jni_gen" |
| 48 action_foreach(foreach_target_name) { |
| 49 script = "//base/android/jni_generator/jni_generator.py" |
| 50 depfile = "$target_gen_dir/$target_name.{{source_name_part}}.d" |
| 51 sources = invoker.sources |
| 52 outputs = [ |
| 53 depfile, |
| 54 "${jni_output_dir}/{{source_name_part}}_jni.h", |
| 55 ] |
| 56 |
| 57 args = [ |
| 58 "--depfile", |
| 59 rebase_path(depfile, root_build_dir), |
| 60 "--input_file={{source}}", |
| 61 "--optimize_generation=1", |
| 62 "--ptr_type=long", |
| 63 "--output_dir", |
| 64 rebase_path(jni_output_dir, root_build_dir), |
| 65 "--includes", |
| 66 rebase_path(jni_generator_include, jni_output_dir), |
| 67 "--native_exports_optional", |
| 68 ] |
| 69 if (defined(invoker.jni_generator_jarjar_file)) { |
| 70 args += [ |
| 71 "--jarjar", |
| 72 rebase_path(jni_generator_jarjar_file, root_build_dir), |
| 73 ] |
| 74 } |
| 75 } |
| 76 |
| 77 config("jni_includes_${target_name}") { |
| 78 # TODO(cjhopman): #includes should probably all be relative to |
| 79 # base_output_dir. Remove that from this config once the includes are |
| 80 # updated. |
| 81 include_dirs = [ |
| 82 base_output_dir, |
| 83 package_output_dir, |
| 84 ] |
| 85 } |
| 86 |
| 87 group(target_name) { |
| 88 deps = [ |
| 89 ":$foreach_target_name", |
| 90 ] |
| 91 public_configs = [ ":jni_includes_${target_name}" ] |
| 92 |
| 93 if (defined(invoker.deps)) { |
| 94 deps += invoker.deps |
| 95 } |
| 96 if (defined(invoker.public_deps)) { |
| 97 public_deps = invoker.public_deps |
| 98 } |
| 99 |
| 100 if (defined(invoker.visibility)) { |
| 101 visibility = invoker.visibility |
| 102 } |
| 103 } |
| 104 } |
| 105 |
| 106 # Declare a jni target for a prebuilt jar |
| 107 # |
| 108 # This target generates the native jni bindings for a set of classes in a .jar. |
| 109 # |
| 110 # See base/android/jni_generator/jni_generator.py for more info about the |
| 111 # format of generating JNI bindings. |
| 112 # |
| 113 # Variables |
| 114 # classes: list of .class files in the jar to generate jni for. These should |
| 115 # include the full path to the .class file. |
| 116 # jni_package: subdirectory path for generated bindings |
| 117 # jar_file: the path to the .jar. If not provided, will default to the sdk's |
| 118 # android.jar |
| 119 # |
| 120 # deps, public_deps: As normal |
| 121 # |
| 122 # Example |
| 123 # generate_jar_jni("foo_jni") { |
| 124 # classes = [ |
| 125 # "android/view/Foo.class", |
| 126 # ] |
| 127 # jni_package = "foo" |
| 128 # } |
| 129 template("generate_jar_jni") { |
| 130 set_sources_assignment_filter([]) |
| 131 if (defined(invoker.testonly)) { |
| 132 testonly = invoker.testonly |
| 133 } |
| 134 |
| 135 assert(defined(invoker.classes)) |
| 136 assert(defined(invoker.jni_package)) |
| 137 |
| 138 if (defined(invoker.jar_file)) { |
| 139 jar_file = invoker.jar_file |
| 140 } else { |
| 141 jar_file = android_sdk_jar |
| 142 } |
| 143 |
| 144 jni_package = invoker.jni_package |
| 145 base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}" |
| 146 jni_output_dir = "${base_output_dir}/jni" |
| 147 |
| 148 jni_generator_include = "//base/android/jni_generator/jni_generator_helper.h" |
| 149 |
| 150 # TODO(cjhopman): make jni_generator.py support generating jni for multiple |
| 151 # .class files from a .jar. |
| 152 jni_actions = [] |
| 153 foreach(class, invoker.classes) { |
| 154 _classname_list = [] |
| 155 _classname_list = process_file_template([ class ], "{{source_name_part}}") |
| 156 classname = _classname_list[0] |
| 157 jni_target_name = "${target_name}__jni_${classname}" |
| 158 jni_actions += [ ":$jni_target_name" ] |
| 159 action(jni_target_name) { |
| 160 # The sources aren't compiled so don't check their dependencies. |
| 161 check_includes = false |
| 162 depfile = "$target_gen_dir/$target_name.d" |
| 163 script = "//base/android/jni_generator/jni_generator.py" |
| 164 sources = [ |
| 165 jar_file, |
| 166 ] |
| 167 outputs = [ |
| 168 depfile, |
| 169 "${jni_output_dir}/${classname}_jni.h", |
| 170 ] |
| 171 |
| 172 args = [ |
| 173 "--depfile", |
| 174 rebase_path(depfile, root_build_dir), |
| 175 "--jar_file", |
| 176 rebase_path(jar_file, root_build_dir), |
| 177 "--input_file", |
| 178 class, |
| 179 "--optimize_generation=1", |
| 180 "--ptr_type=long", |
| 181 "--output_dir", |
| 182 rebase_path(jni_output_dir, root_build_dir), |
| 183 "--includes", |
| 184 rebase_path(jni_generator_include, jni_output_dir), |
| 185 "--native_exports_optional", |
| 186 ] |
| 187 } |
| 188 } |
| 189 |
| 190 config("jni_includes_${target_name}") { |
| 191 include_dirs = [ base_output_dir ] |
| 192 } |
| 193 |
| 194 group(target_name) { |
| 195 deps = jni_actions |
| 196 if (defined(invoker.deps)) { |
| 197 deps += invoker.deps |
| 198 } |
| 199 if (defined(invoker.public_deps)) { |
| 200 public_deps = invoker.public_deps |
| 201 } |
| 202 public_configs = [ ":jni_includes_${target_name}" ] |
| 203 } |
| 204 } |
| 205 |
| 206 # Declare a target for c-preprocessor-generated java files |
| 207 # |
| 208 # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum |
| 209 # rule instead. |
| 210 # |
| 211 # This target generates java files using the host C pre-processor. Each file in |
| 212 # sources will be compiled using the C pre-processor. If include_path is |
| 213 # specified, it will be passed (with --I) to the pre-processor. |
| 214 # |
| 215 # This target will create a single .srcjar. Adding this target to an |
| 216 # android_library target's srcjar_deps will make the generated java files be |
| 217 # included in that library's final outputs. |
| 218 # |
| 219 # Variables |
| 220 # sources: list of files to be processed by the C pre-processor. For each |
| 221 # file in sources, there will be one .java file in the final .srcjar. For a |
| 222 # file named FooBar.template, a java file will be created with name |
| 223 # FooBar.java. |
| 224 # inputs: additional compile-time dependencies. Any files |
| 225 # `#include`-ed in the templates should be listed here. |
| 226 # package_name: this will be the subdirectory for each .java file in the |
| 227 # .srcjar. |
| 228 # |
| 229 # Example |
| 230 # java_cpp_template("foo_generated_enum") { |
| 231 # sources = [ |
| 232 # "android/java/templates/Foo.template", |
| 233 # ] |
| 234 # inputs = [ |
| 235 # "android/java/templates/native_foo_header.h", |
| 236 # ] |
| 237 # |
| 238 # package_name = "org/chromium/base/library_loader" |
| 239 # include_path = "android/java/templates" |
| 240 # } |
| 241 template("java_cpp_template") { |
| 242 set_sources_assignment_filter([]) |
| 243 if (defined(invoker.testonly)) { |
| 244 testonly = invoker.testonly |
| 245 } |
| 246 |
| 247 assert(defined(invoker.sources)) |
| 248 package_name = invoker.package_name + "" |
| 249 |
| 250 if (defined(invoker.include_path)) { |
| 251 include_path = invoker.include_path + "" |
| 252 } else { |
| 253 include_path = "//" |
| 254 } |
| 255 |
| 256 apply_gcc_target_name = "${target_name}__apply_gcc" |
| 257 zip_srcjar_target_name = "${target_name}__zip_srcjar" |
| 258 final_target_name = target_name |
| 259 |
| 260 action_foreach(apply_gcc_target_name) { |
| 261 visibility = [ ":$zip_srcjar_target_name" ] |
| 262 script = "//build/android/gyp/gcc_preprocess.py" |
| 263 if (defined(invoker.inputs)) { |
| 264 inputs = invoker.inputs + [] |
| 265 } |
| 266 depfile = "${target_gen_dir}/${target_name}_{{source_name_part}}.d" |
| 267 |
| 268 sources = invoker.sources |
| 269 |
| 270 if (defined(invoker.deps)) { |
| 271 deps = invoker.deps |
| 272 } |
| 273 if (defined(invoker.public_deps)) { |
| 274 public_deps = invoker.public_deps |
| 275 } |
| 276 if (defined(invoker.data_deps)) { |
| 277 data_deps = invoker.data_deps |
| 278 } |
| 279 |
| 280 gen_dir = |
| 281 "${target_gen_dir}/${target_name}/java_cpp_template/${package_name}" |
| 282 gcc_template_output_pattern = "${gen_dir}/{{source_name_part}}.java" |
| 283 |
| 284 outputs = [ |
| 285 depfile, |
| 286 gcc_template_output_pattern, |
| 287 ] |
| 288 |
| 289 args = [ |
| 290 "--depfile", |
| 291 rebase_path(depfile, root_build_dir), |
| 292 "--include-path", |
| 293 rebase_path(include_path, root_build_dir), |
| 294 "--output", |
| 295 rebase_path(gen_dir, root_build_dir) + "/{{source_name_part}}.java", |
| 296 "--template={{source}}", |
| 297 ] |
| 298 |
| 299 if (defined(invoker.defines)) { |
| 300 foreach(def, invoker.defines) { |
| 301 args += [ |
| 302 "--defines", |
| 303 def, |
| 304 ] |
| 305 } |
| 306 } |
| 307 } |
| 308 |
| 309 apply_gcc_outputs = get_target_outputs(":$apply_gcc_target_name") |
| 310 base_gen_dir = get_label_info(":$apply_gcc_target_name", "target_gen_dir") |
| 311 |
| 312 srcjar_path = "${target_gen_dir}/${target_name}.srcjar" |
| 313 zip(zip_srcjar_target_name) { |
| 314 visibility = [ ":$final_target_name" ] |
| 315 inputs = apply_gcc_outputs |
| 316 output = srcjar_path |
| 317 base_dir = base_gen_dir |
| 318 deps = [ |
| 319 ":$apply_gcc_target_name", |
| 320 ] |
| 321 } |
| 322 |
| 323 group(final_target_name) { |
| 324 if (defined(invoker.visibility)) { |
| 325 visibility = invoker.visibility |
| 326 } |
| 327 deps = [ |
| 328 ":$zip_srcjar_target_name", |
| 329 ] |
| 330 } |
| 331 } |
| 332 |
| 333 # Declare a target for generating Java classes from C++ enums. |
| 334 # |
| 335 # This target generates Java files from C++ enums using a script. |
| 336 # |
| 337 # This target will create a single .srcjar. Adding this target to an |
| 338 # android_library target's srcjar_deps will make the generated java files be |
| 339 # included in that library's final outputs. |
| 340 # |
| 341 # Variables |
| 342 # sources: list of files to be processed by the script. For each annotated |
| 343 # enum contained in the sources files the script will generate a .java |
| 344 # file with the same name as the name of the enum. |
| 345 # |
| 346 # outputs: list of outputs, relative to the output_dir. These paths are |
| 347 # verified at build time by the script. To get the list programatically run: |
| 348 # python build/android/gyp/java_cpp_enum.py \ |
| 349 # --print_output_only . path/to/header/file.h |
| 350 # |
| 351 # Example |
| 352 # java_cpp_enum("foo_generated_enum") { |
| 353 # sources = [ |
| 354 # "src/native_foo_header.h", |
| 355 # ] |
| 356 # outputs = [ |
| 357 # "org/chromium/FooEnum.java", |
| 358 # ] |
| 359 # } |
| 360 template("java_cpp_enum") { |
| 361 set_sources_assignment_filter([]) |
| 362 if (defined(invoker.testonly)) { |
| 363 testonly = invoker.testonly |
| 364 } |
| 365 |
| 366 assert(defined(invoker.sources)) |
| 367 assert(defined(invoker.outputs)) |
| 368 |
| 369 generate_enum_target_name = "${target_name}__generate_enum" |
| 370 zip_srcjar_target_name = "${target_name}__zip_srcjar" |
| 371 final_target_name = target_name |
| 372 |
| 373 action(generate_enum_target_name) { |
| 374 visibility = [ ":$zip_srcjar_target_name" ] |
| 375 |
| 376 # The sources aren't compiled so don't check their dependencies. |
| 377 check_includes = false |
| 378 |
| 379 sources = invoker.sources |
| 380 script = "//build/android/gyp/java_cpp_enum.py" |
| 381 gen_dir = "${target_gen_dir}/${target_name}/enums" |
| 382 outputs = |
| 383 get_path_info(rebase_path(invoker.outputs, ".", gen_dir), "abspath") |
| 384 |
| 385 args = [] |
| 386 foreach(output, rebase_path(outputs, root_build_dir)) { |
| 387 args += [ |
| 388 "--assert_file", |
| 389 output, |
| 390 ] |
| 391 } |
| 392 args += [ rebase_path(gen_dir, root_build_dir) ] |
| 393 args += rebase_path(invoker.sources, root_build_dir) |
| 394 } |
| 395 |
| 396 generate_enum_outputs = get_target_outputs(":$generate_enum_target_name") |
| 397 base_gen_dir = get_label_info(":$generate_enum_target_name", "target_gen_dir") |
| 398 |
| 399 srcjar_path = "${target_gen_dir}/${target_name}.srcjar" |
| 400 zip(zip_srcjar_target_name) { |
| 401 visibility = [ ":$final_target_name" ] |
| 402 inputs = generate_enum_outputs |
| 403 output = srcjar_path |
| 404 base_dir = base_gen_dir |
| 405 deps = [ |
| 406 ":$generate_enum_target_name", |
| 407 ] |
| 408 } |
| 409 |
| 410 group(final_target_name) { |
| 411 if (defined(invoker.visibility)) { |
| 412 visibility = invoker.visibility |
| 413 } |
| 414 deps = [ |
| 415 ":$zip_srcjar_target_name", |
| 416 ] |
| 417 } |
| 418 } |
| 419 |
| 420 # Declare a target for processing Android resources as Jinja templates. |
| 421 # |
| 422 # This takes an Android resource directory where each resource is a Jinja |
| 423 # template, processes each template, then packages the results in a zip file |
| 424 # which can be consumed by an android resources, library, or apk target. |
| 425 # |
| 426 # If this target is included in the deps of an android resources/library/apk, |
| 427 # the resources will be included with that target. |
| 428 # |
| 429 # Variables |
| 430 # resources: The list of resources files to process. |
| 431 # res_dir: The resource directory containing the resources. |
| 432 # variables: (Optional) A list of variables to make available to the template |
| 433 # processing environment, e.g. ["name=foo", "color=red"]. |
| 434 # |
| 435 # Example |
| 436 # jinja_template_resources("chrome_shell_template_resources") { |
| 437 # res_dir = "shell/res_template" |
| 438 # resources = ["shell/res_template/xml/syncable.xml"] |
| 439 # variables = ["color=red"] |
| 440 # } |
| 441 template("jinja_template_resources") { |
| 442 set_sources_assignment_filter([]) |
| 443 if (defined(invoker.testonly)) { |
| 444 testonly = invoker.testonly |
| 445 } |
| 446 |
| 447 assert(defined(invoker.resources)) |
| 448 assert(defined(invoker.res_dir)) |
| 449 |
| 450 _base_path = "$target_gen_dir/$target_name" |
| 451 _resources_zip = _base_path + ".resources.zip" |
| 452 _build_config = _base_path + ".build_config" |
| 453 |
| 454 write_build_config("${target_name}__build_config") { |
| 455 build_config = _build_config |
| 456 resources_zip = _resources_zip |
| 457 type = "android_resources" |
| 458 } |
| 459 |
| 460 action("${target_name}__template") { |
| 461 sources = invoker.resources |
| 462 script = "//build/android/gyp/jinja_template.py" |
| 463 depfile = "$target_gen_dir/$target_name.d" |
| 464 |
| 465 outputs = [ |
| 466 depfile, |
| 467 _resources_zip, |
| 468 ] |
| 469 |
| 470 rebased_resources = rebase_path(invoker.resources, root_build_dir) |
| 471 args = [ |
| 472 "--inputs=${rebased_resources}", |
| 473 "--inputs-base-dir", |
| 474 rebase_path(invoker.res_dir, root_build_dir), |
| 475 "--outputs-zip", |
| 476 rebase_path(_resources_zip, root_build_dir), |
| 477 "--depfile", |
| 478 rebase_path(depfile, root_build_dir), |
| 479 ] |
| 480 if (defined(invoker.variables)) { |
| 481 variables = invoker.variables |
| 482 args += [ "--variables=${variables}" ] |
| 483 } |
| 484 } |
| 485 |
| 486 group(target_name) { |
| 487 deps = [ |
| 488 ":${target_name}__build_config", |
| 489 ":${target_name}__template", |
| 490 ] |
| 491 } |
| 492 } |
| 493 |
| 494 # Creates a resources.zip with locale.pak files placed into appropriate |
| 495 # resource configs (e.g. en-GB.pak -> res/raw-en/en_gb.pak). Also generates |
| 496 # a locale_paks TypedArray so that resource files can be enumerated at runtime. |
| 497 # |
| 498 # If this target is included in the deps of an android resources/library/apk, |
| 499 # the resources will be included with that target. |
| 500 # |
| 501 # Variables: |
| 502 # sources: List of .pak files. Names must be of the form "en.pak" or |
| 503 # "en-US.pak". |
| 504 # deps: (optional) List of dependencies that might be needed to generate |
| 505 # the .pak files. |
| 506 # |
| 507 # Example |
| 508 # locale_pak_resources("locale_paks") { |
| 509 # sources = [ "path/en-US.pak", "path/fr.pak", ... ] |
| 510 # } |
| 511 template("locale_pak_resources") { |
| 512 set_sources_assignment_filter([]) |
| 513 assert(defined(invoker.sources)) |
| 514 |
| 515 _base_path = "$target_gen_dir/$target_name" |
| 516 _resources_zip = _base_path + ".resources.zip" |
| 517 _build_config = _base_path + ".build_config" |
| 518 |
| 519 write_build_config("${target_name}__build_config") { |
| 520 build_config = _build_config |
| 521 resources_zip = _resources_zip |
| 522 type = "android_resources" |
| 523 } |
| 524 |
| 525 action("${target_name}__create_resources_zip") { |
| 526 sources = invoker.sources |
| 527 script = "//build/android/gyp/locale_pak_resources.py" |
| 528 depfile = "$target_gen_dir/$target_name.d" |
| 529 |
| 530 outputs = [ |
| 531 depfile, |
| 532 _resources_zip, |
| 533 ] |
| 534 |
| 535 _rebased_sources = rebase_path(invoker.sources, root_build_dir) |
| 536 args = [ |
| 537 "--locale-paks=${_rebased_sources}", |
| 538 "--resources-zip", |
| 539 rebase_path(_resources_zip, root_build_dir), |
| 540 "--depfile", |
| 541 rebase_path(depfile, root_build_dir), |
| 542 ] |
| 543 |
| 544 if (defined(invoker.deps)) { |
| 545 deps = invoker.deps |
| 546 } |
| 547 } |
| 548 |
| 549 group(target_name) { |
| 550 deps = [ |
| 551 ":${target_name}__build_config", |
| 552 ":${target_name}__create_resources_zip", |
| 553 ] |
| 554 } |
| 555 } |
| 556 |
| 557 # Declare an Android resources target |
| 558 # |
| 559 # This creates a resources zip file that will be used when building an Android |
| 560 # library or apk and included into a final apk. |
| 561 # |
| 562 # To include these resources in a library/apk, this target should be listed in |
| 563 # the library's deps. A library/apk will also include any resources used by its |
| 564 # own dependencies. |
| 565 # |
| 566 # Variables |
| 567 # deps: Specifies the dependencies of this target. Any Android resources |
| 568 # listed in deps will be included by libraries/apks that depend on this |
| 569 # target. |
| 570 # resource_dirs: List of directories containing resources for this target. |
| 571 # android_manifest: AndroidManifest.xml for this target. Defaults to |
| 572 # //build/android/AndroidManifest.xml. |
| 573 # custom_package: java package for generated .java files. |
| 574 # v14_skip: If true, don't run v14 resource generator on this. Defaults to |
| 575 # false. (see build/android/gyp/generate_v14_compatible_resources.py) |
| 576 # |
| 577 # shared_resources: If true make a resource package that can be loaded by a |
| 578 # different application at runtime to access the package's resources. |
| 579 # |
| 580 |
| 581 # Example |
| 582 # android_resources("foo_resources") { |
| 583 # deps = [":foo_strings_grd"] |
| 584 # resource_dirs = ["res"] |
| 585 # custom_package = "org.chromium.foo" |
| 586 # } |
| 587 template("android_resources") { |
| 588 set_sources_assignment_filter([]) |
| 589 if (defined(invoker.testonly)) { |
| 590 testonly = invoker.testonly |
| 591 } |
| 592 |
| 593 assert(defined(invoker.resource_dirs)) |
| 594 assert(defined(invoker.android_manifest) || defined(invoker.custom_package)) |
| 595 |
| 596 base_path = "$target_gen_dir/$target_name" |
| 597 zip_path = base_path + ".resources.zip" |
| 598 srcjar_path = base_path + ".srcjar" |
| 599 r_text_path = base_path + "_R.txt" |
| 600 build_config = base_path + ".build_config" |
| 601 |
| 602 build_config_target_name = "${target_name}__build_config" |
| 603 process_resources_target_name = "${target_name}__process_resources" |
| 604 final_target_name = target_name |
| 605 |
| 606 write_build_config(build_config_target_name) { |
| 607 visibility = [ ":$process_resources_target_name" ] |
| 608 |
| 609 type = "android_resources" |
| 610 resources_zip = zip_path |
| 611 srcjar = srcjar_path |
| 612 r_text = r_text_path |
| 613 if (defined(invoker.deps)) { |
| 614 deps = invoker.deps |
| 615 } |
| 616 if (defined(invoker.android_manifest)) { |
| 617 android_manifest = invoker.android_manifest |
| 618 } |
| 619 if (defined(invoker.custom_package)) { |
| 620 custom_package = invoker.custom_package |
| 621 } |
| 622 } |
| 623 |
| 624 android_manifest = "//build/android/AndroidManifest.xml" |
| 625 if (defined(invoker.android_manifest)) { |
| 626 android_manifest = invoker.android_manifest |
| 627 } |
| 628 |
| 629 process_resources(process_resources_target_name) { |
| 630 visibility = [ ":$final_target_name" ] |
| 631 |
| 632 resource_dirs = invoker.resource_dirs |
| 633 if (defined(invoker.custom_package)) { |
| 634 custom_package = invoker.custom_package |
| 635 } |
| 636 |
| 637 if (defined(invoker.v14_skip)) { |
| 638 v14_skip = invoker.v14_skip |
| 639 } |
| 640 |
| 641 if (defined(invoker.shared_resources)) { |
| 642 shared_resources = invoker.shared_resources |
| 643 } |
| 644 |
| 645 deps = [ |
| 646 ":$build_config_target_name", |
| 647 ] |
| 648 if (defined(invoker.deps)) { |
| 649 # Invoker may have added deps that generate the input resources. |
| 650 deps += invoker.deps |
| 651 } |
| 652 } |
| 653 |
| 654 group(final_target_name) { |
| 655 if (defined(invoker.visibility)) { |
| 656 visibility = invoker.visibility |
| 657 } |
| 658 deps = [ |
| 659 ":${target_name}__process_resources", |
| 660 ] |
| 661 } |
| 662 } |
| 663 |
| 664 # Declare a target that generates localized strings.xml from a .grd file. |
| 665 # |
| 666 # If this target is included in the deps of an android resources/library/apk, |
| 667 # the strings.xml will be included with that target. |
| 668 # |
| 669 # Variables |
| 670 # deps: Specifies the dependencies of this target. |
| 671 # grd_file: Path to the .grd file to generate strings.xml from. |
| 672 # outputs: Expected grit outputs (see grit rule). |
| 673 # |
| 674 # Example |
| 675 # java_strings_grd("foo_strings_grd") { |
| 676 # grd_file = "foo_strings.grd" |
| 677 # } |
| 678 template("java_strings_grd") { |
| 679 set_sources_assignment_filter([]) |
| 680 if (defined(invoker.testonly)) { |
| 681 testonly = invoker.testonly |
| 682 } |
| 683 |
| 684 base_path = "$target_gen_dir/$target_name" |
| 685 resources_zip = base_path + ".resources.zip" |
| 686 build_config = base_path + ".build_config" |
| 687 |
| 688 write_build_config("${target_name}__build_config") { |
| 689 type = "android_resources" |
| 690 if (defined(invoker.deps)) { |
| 691 deps = invoker.deps |
| 692 } |
| 693 } |
| 694 |
| 695 # Put grit files into this subdirectory of target_gen_dir. |
| 696 extra_output_path = target_name + "_grit_output" |
| 697 |
| 698 grit_target_name = "${target_name}__grit" |
| 699 grit_output_dir = "$target_gen_dir/$extra_output_path" |
| 700 grit(grit_target_name) { |
| 701 grit_flags = [ |
| 702 "-E", |
| 703 "ANDROID_JAVA_TAGGED_ONLY=false", |
| 704 ] |
| 705 output_dir = grit_output_dir |
| 706 resource_ids = "" |
| 707 source = invoker.grd_file |
| 708 outputs = invoker.outputs |
| 709 } |
| 710 |
| 711 # This needs to get outputs from grit's internal target, not the final |
| 712 # source_set. |
| 713 generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit") |
| 714 |
| 715 zip("${target_name}__zip") { |
| 716 base_dir = grit_output_dir |
| 717 inputs = generate_strings_outputs |
| 718 output = resources_zip |
| 719 deps = [ |
| 720 ":$grit_target_name", |
| 721 ] |
| 722 } |
| 723 |
| 724 group(target_name) { |
| 725 deps = [ |
| 726 ":${target_name}__build_config", |
| 727 ":${target_name}__zip", |
| 728 ] |
| 729 } |
| 730 } |
| 731 |
| 732 # Declare a target that packages strings.xml generated from a grd file. |
| 733 # |
| 734 # If this target is included in the deps of an android resources/library/apk, |
| 735 # the strings.xml will be included with that target. |
| 736 # |
| 737 # Variables |
| 738 # grit_output_dir: directory containing grit-generated files. |
| 739 # generated_files: list of android resource files to package. |
| 740 # |
| 741 # Example |
| 742 # java_strings_grd_prebuilt("foo_strings_grd") { |
| 743 # grit_output_dir = "$root_gen_dir/foo/grit" |
| 744 # generated_files = [ |
| 745 # "values/strings.xml" |
| 746 # ] |
| 747 # } |
| 748 template("java_strings_grd_prebuilt") { |
| 749 set_sources_assignment_filter([]) |
| 750 if (defined(invoker.testonly)) { |
| 751 testonly = invoker.testonly |
| 752 } |
| 753 |
| 754 base_path = "$target_gen_dir/$target_name" |
| 755 resources_zip = base_path + ".resources.zip" |
| 756 build_config = base_path + ".build_config" |
| 757 |
| 758 build_config_target_name = "${target_name}__build_config" |
| 759 zip_target_name = "${target_name}__zip" |
| 760 final_target_name = target_name |
| 761 |
| 762 write_build_config(build_config_target_name) { |
| 763 visibility = [ ":$zip_target_name" ] |
| 764 type = "android_resources" |
| 765 } |
| 766 |
| 767 zip(zip_target_name) { |
| 768 visibility = [ ":$final_target_name" ] |
| 769 |
| 770 base_dir = invoker.grit_output_dir |
| 771 inputs = rebase_path(invoker.generated_files, ".", base_dir) |
| 772 output = resources_zip |
| 773 deps = [ |
| 774 ":$build_config_target_name", |
| 775 ] |
| 776 if (defined(invoker.deps)) { |
| 777 deps += invoker.deps |
| 778 } |
| 779 } |
| 780 |
| 781 group(final_target_name) { |
| 782 if (defined(invoker.visibility)) { |
| 783 visibility = invoker.visibility |
| 784 } |
| 785 deps = [ |
| 786 ":$zip_target_name", |
| 787 ] |
| 788 } |
| 789 } |
| 790 |
| 791 # Declare a Java executable target |
| 792 # |
| 793 # This target creates an executable from java code and libraries. The executable |
| 794 # will be in the output folder's /bin/ directory. |
| 795 # |
| 796 # Variables |
| 797 # deps: Specifies the dependencies of this target. Java targets in this list |
| 798 # will be included in the executable (and the javac classpath). |
| 799 # |
| 800 # java_files: List of .java files included in this library. |
| 801 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars |
| 802 # will be added to java_files and be included in this library. |
| 803 # srcjars: List of srcjars to be included in this library, together with the |
| 804 # ones obtained from srcjar_deps. |
| 805 # |
| 806 # bypass_platform_checks: Disables checks about cross-platform (Java/Android) |
| 807 # dependencies for this target. This will allow depending on an |
| 808 # android_library target, for example. |
| 809 # |
| 810 # chromium_code: If true, extra analysis warning/errors will be enabled. |
| 811 # enable_errorprone: If true, enables the errorprone compiler. |
| 812 # |
| 813 # data_deps, testonly |
| 814 # |
| 815 # Example |
| 816 # java_binary("foo") { |
| 817 # java_files = [ "org/chromium/foo/FooMain.java" ] |
| 818 # deps = [ ":bar_java" ] |
| 819 # main_class = "org.chromium.foo.FooMain" |
| 820 # } |
| 821 template("java_binary") { |
| 822 set_sources_assignment_filter([]) |
| 823 |
| 824 # TODO(cjhopman): This should not act like a java_library for dependents (i.e. |
| 825 # dependents shouldn't get the jar in their classpath, etc.). |
| 826 java_library_impl(target_name) { |
| 827 if (defined(invoker.DEPRECATED_java_in_dir)) { |
| 828 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir |
| 829 } |
| 830 if (defined(invoker.chromium_code)) { |
| 831 chromium_code = invoker.chromium_code |
| 832 } |
| 833 if (defined(invoker.data_deps)) { |
| 834 deps = invoker.data_deps |
| 835 } |
| 836 if (defined(invoker.deps)) { |
| 837 deps = invoker.deps |
| 838 } |
| 839 if (defined(invoker.enable_errorprone)) { |
| 840 enable_errorprone = invoker.enable_errorprone |
| 841 } |
| 842 if (defined(invoker.java_files)) { |
| 843 java_files = invoker.java_files |
| 844 } |
| 845 if (defined(invoker.srcjar_deps)) { |
| 846 srcjar_deps = invoker.srcjar_deps |
| 847 } |
| 848 if (defined(invoker.srcjars)) { |
| 849 srcjars = invoker.srcjars |
| 850 } |
| 851 if (defined(invoker.bypass_platform_checks)) { |
| 852 bypass_platform_checks = invoker.bypass_platform_checks |
| 853 } |
| 854 if (defined(invoker.testonly)) { |
| 855 testonly = invoker.testonly |
| 856 } |
| 857 |
| 858 supports_android = false |
| 859 main_class = invoker.main_class |
| 860 } |
| 861 } |
| 862 |
| 863 # Declare a Junit executable target |
| 864 # |
| 865 # This target creates an executable from java code for running as a junit test |
| 866 # suite. The executable will be in the output folder's /bin/ directory. |
| 867 # |
| 868 # Variables |
| 869 # deps: Specifies the dependencies of this target. Java targets in this list |
| 870 # will be included in the executable (and the javac classpath). |
| 871 # |
| 872 # java_files: List of .java files included in this library. |
| 873 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars |
| 874 # will be added to java_files and be included in this library. |
| 875 # srcjars: List of srcjars to be included in this library, together with the |
| 876 # ones obtained from srcjar_deps. |
| 877 # |
| 878 # chromium_code: If true, extra analysis warning/errors will be enabled. |
| 879 # |
| 880 # Example |
| 881 # junit_binary("foo") { |
| 882 # java_files = [ "org/chromium/foo/FooTest.java" ] |
| 883 # deps = [ ":bar_java" ] |
| 884 # } |
| 885 template("junit_binary") { |
| 886 set_sources_assignment_filter([]) |
| 887 |
| 888 java_binary(target_name) { |
| 889 bypass_platform_checks = true |
| 890 main_class = "org.chromium.testing.local.JunitTestMain" |
| 891 testonly = true |
| 892 |
| 893 if (defined(invoker.DEPRECATED_java_in_dir)) { |
| 894 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir |
| 895 } |
| 896 if (defined(invoker.chromium_code)) { |
| 897 chromium_code = invoker.chromium_code |
| 898 } |
| 899 deps = [ |
| 900 "//testing/android/junit:junit_test_support", |
| 901 "//third_party/junit", |
| 902 "//third_party/mockito:mockito_java", |
| 903 "//third_party/robolectric:robolectric_java", |
| 904 "//third_party/robolectric:android-all-4.3_r2-robolectric-0", |
| 905 ] |
| 906 if (defined(invoker.deps)) { |
| 907 deps += invoker.deps |
| 908 } |
| 909 if (defined(invoker.java_files)) { |
| 910 java_files = invoker.java_files |
| 911 } |
| 912 if (defined(invoker.srcjar_deps)) { |
| 913 srcjar_deps = invoker.srcjar_deps |
| 914 } |
| 915 if (defined(invoker.srcjars)) { |
| 916 srcjars = invoker.srcjars |
| 917 } |
| 918 } |
| 919 } |
| 920 |
| 921 # Declare a java library target |
| 922 # |
| 923 # Variables |
| 924 # deps: Specifies the dependencies of this target. Java targets in this list |
| 925 # will be added to the javac classpath. |
| 926 # |
| 927 # java_files: List of .java files included in this library. |
| 928 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars |
| 929 # will be added to java_files and be included in this library. |
| 930 # srcjars: List of srcjars to be included in this library, together with the |
| 931 # ones obtained from srcjar_deps. |
| 932 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in |
| 933 # this directory will be included in the library. This is only supported to |
| 934 # ease the gyp->gn conversion and will be removed in the future. |
| 935 # |
| 936 # chromium_code: If true, extra analysis warning/errors will be enabled. |
| 937 # enable_errorprone: If true, enables the errorprone compiler. |
| 938 # |
| 939 # jar_excluded_patterns: List of patterns of .class files to exclude from the |
| 940 # final jar. |
| 941 # |
| 942 # proguard_preprocess: If true, proguard preprocessing will be run. This can |
| 943 # be used to remove unwanted parts of the library. |
| 944 # proguard_config: Path to the proguard config for preprocessing. |
| 945 # |
| 946 # supports_android: If true, Android targets (android_library, android_apk) |
| 947 # may depend on this target. Note: if true, this target must only use the |
| 948 # subset of Java available on Android. |
| 949 # bypass_platform_checks: Disables checks about cross-platform (Java/Android) |
| 950 # dependencies for this target. This will allow depending on an |
| 951 # android_library target, for example. |
| 952 # |
| 953 # data_deps, testonly |
| 954 # |
| 955 # Example |
| 956 # java_library("foo_java") { |
| 957 # java_files = [ |
| 958 # "org/chromium/foo/Foo.java", |
| 959 # "org/chromium/foo/FooInterface.java", |
| 960 # "org/chromium/foo/FooService.java", |
| 961 # ] |
| 962 # deps = [ |
| 963 # ":bar_java" |
| 964 # ] |
| 965 # srcjar_deps = [ |
| 966 # ":foo_generated_enum" |
| 967 # ] |
| 968 # jar_excluded_patterns = [ |
| 969 # "*/FooService.class", "*/FooService##*.class" |
| 970 # ] |
| 971 # } |
| 972 template("java_library") { |
| 973 set_sources_assignment_filter([]) |
| 974 java_library_impl(target_name) { |
| 975 if (defined(invoker.DEPRECATED_java_in_dir)) { |
| 976 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir |
| 977 } |
| 978 if (defined(invoker.chromium_code)) { |
| 979 chromium_code = invoker.chromium_code |
| 980 } |
| 981 if (defined(invoker.data_deps)) { |
| 982 deps = invoker.data_deps |
| 983 } |
| 984 if (defined(invoker.deps)) { |
| 985 deps = invoker.deps |
| 986 } |
| 987 if (defined(invoker.enable_errorprone)) { |
| 988 enable_errorprone = invoker.enable_errorprone |
| 989 } |
| 990 if (defined(invoker.jar_excluded_patterns)) { |
| 991 jar_excluded_patterns = invoker.jar_excluded_patterns |
| 992 } |
| 993 if (defined(invoker.java_files)) { |
| 994 java_files = invoker.java_files |
| 995 } |
| 996 if (defined(invoker.proguard_config)) { |
| 997 proguard_config = invoker.proguard_config |
| 998 } |
| 999 if (defined(invoker.proguard_preprocess)) { |
| 1000 proguard_preprocess = invoker.proguard_preprocess |
| 1001 } |
| 1002 if (defined(invoker.srcjar_deps)) { |
| 1003 srcjar_deps = invoker.srcjar_deps |
| 1004 } |
| 1005 if (defined(invoker.srcjars)) { |
| 1006 srcjars = invoker.srcjars |
| 1007 } |
| 1008 if (defined(invoker.bypass_platform_checks)) { |
| 1009 bypass_platform_checks = invoker.bypass_platform_checks |
| 1010 } |
| 1011 if (defined(invoker.testonly)) { |
| 1012 testonly = invoker.testonly |
| 1013 } |
| 1014 if (defined(invoker.jar_path)) { |
| 1015 jar_path = invoker.jar_path |
| 1016 } |
| 1017 |
| 1018 if (defined(invoker.supports_android) && invoker.supports_android) { |
| 1019 supports_android = true |
| 1020 } |
| 1021 } |
| 1022 } |
| 1023 |
| 1024 # Declare a java library target for a prebuilt jar |
| 1025 # |
| 1026 # Variables |
| 1027 # deps: Specifies the dependencies of this target. Java targets in this list |
| 1028 # will be added to the javac classpath. |
| 1029 # jar_path: Path to the prebuilt jar. |
| 1030 # jar_dep: Target that builds jar_path (optional). |
| 1031 # proguard_preprocess: If true, proguard preprocessing will be run. This can |
| 1032 # be used to remove unwanted parts of the library. |
| 1033 # proguard_config: Path to the proguard config for preprocessing. |
| 1034 # |
| 1035 # Example |
| 1036 # java_prebuilt("foo_java") { |
| 1037 # jar_path = "foo.jar" |
| 1038 # deps = [ |
| 1039 # ":foo_resources", |
| 1040 # ":bar_java" |
| 1041 # ] |
| 1042 # } |
| 1043 template("java_prebuilt") { |
| 1044 set_sources_assignment_filter([]) |
| 1045 java_prebuilt_impl(target_name) { |
| 1046 jar_path = invoker.jar_path |
| 1047 if (defined(invoker.jar_dep)) { |
| 1048 jar_dep = invoker.jar_dep |
| 1049 } |
| 1050 if (defined(invoker.testonly)) { |
| 1051 testonly = invoker.testonly |
| 1052 } |
| 1053 if (defined(invoker.deps)) { |
| 1054 deps = invoker.deps |
| 1055 } |
| 1056 if (defined(invoker.data_deps)) { |
| 1057 data_deps = invoker.data_deps |
| 1058 } |
| 1059 if (defined(invoker.proguard_config)) { |
| 1060 proguard_config = invoker.proguard_config |
| 1061 } |
| 1062 if (defined(invoker.proguard_preprocess)) { |
| 1063 proguard_preprocess = invoker.proguard_preprocess |
| 1064 } |
| 1065 } |
| 1066 } |
| 1067 |
| 1068 # Declare an Android library target |
| 1069 # |
| 1070 # This target creates an Android library containing java code and Android |
| 1071 # resources. |
| 1072 # |
| 1073 # Variables |
| 1074 # deps: Specifies the dependencies of this target. Java targets in this list |
| 1075 # will be added to the javac classpath. Android resources in dependencies |
| 1076 # will be used when building this library. |
| 1077 # |
| 1078 # java_files: List of .java files included in this library. |
| 1079 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars |
| 1080 # will be added to java_files and be included in this library. |
| 1081 # srcjars: List of srcjars to be included in this library, together with the |
| 1082 # ones obtained from srcjar_deps. |
| 1083 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in |
| 1084 # this directory will be included in the library. This is only supported to |
| 1085 # ease the gyp->gn conversion and will be removed in the future. |
| 1086 # |
| 1087 # chromium_code: If true, extra analysis warning/errors will be enabled. |
| 1088 # enable_errorprone: If true, enables the errorprone compiler. |
| 1089 # |
| 1090 # jar_excluded_patterns: List of patterns of .class files to exclude from the |
| 1091 # final jar. |
| 1092 # |
| 1093 # proguard_preprocess: If true, proguard preprocessing will be run. This can |
| 1094 # be used to remove unwanted parts of the library. |
| 1095 # proguard_config: Path to the proguard config for preprocessing. |
| 1096 # |
| 1097 # dex_path: If set, the resulting .dex.jar file will be placed under this |
| 1098 # path. |
| 1099 # |
| 1100 # |
| 1101 # Example |
| 1102 # android_library("foo_java") { |
| 1103 # java_files = [ |
| 1104 # "android/org/chromium/foo/Foo.java", |
| 1105 # "android/org/chromium/foo/FooInterface.java", |
| 1106 # "android/org/chromium/foo/FooService.java", |
| 1107 # ] |
| 1108 # deps = [ |
| 1109 # ":bar_java" |
| 1110 # ] |
| 1111 # srcjar_deps = [ |
| 1112 # ":foo_generated_enum" |
| 1113 # ] |
| 1114 # jar_excluded_patterns = [ |
| 1115 # "*/FooService.class", "*/FooService##*.class" |
| 1116 # ] |
| 1117 # } |
| 1118 template("android_library") { |
| 1119 set_sources_assignment_filter([]) |
| 1120 assert(!defined(invoker.jar_path), |
| 1121 "android_library does not support a custom jar path") |
| 1122 java_library_impl(target_name) { |
| 1123 if (defined(invoker.DEPRECATED_java_in_dir)) { |
| 1124 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir |
| 1125 } |
| 1126 if (defined(invoker.chromium_code)) { |
| 1127 chromium_code = invoker.chromium_code |
| 1128 } |
| 1129 if (defined(invoker.data_deps)) { |
| 1130 deps = invoker.data_deps |
| 1131 } |
| 1132 if (defined(invoker.deps)) { |
| 1133 deps = invoker.deps |
| 1134 } |
| 1135 if (defined(invoker.enable_errorprone)) { |
| 1136 enable_errorprone = invoker.enable_errorprone |
| 1137 } |
| 1138 if (defined(invoker.jar_excluded_patterns)) { |
| 1139 jar_excluded_patterns = invoker.jar_excluded_patterns |
| 1140 } |
| 1141 if (defined(invoker.java_files)) { |
| 1142 java_files = invoker.java_files |
| 1143 } |
| 1144 if (defined(invoker.proguard_config)) { |
| 1145 proguard_config = invoker.proguard_config |
| 1146 } |
| 1147 if (defined(invoker.proguard_preprocess)) { |
| 1148 proguard_preprocess = invoker.proguard_preprocess |
| 1149 } |
| 1150 if (defined(invoker.srcjar_deps)) { |
| 1151 srcjar_deps = invoker.srcjar_deps |
| 1152 } |
| 1153 if (defined(invoker.srcjars)) { |
| 1154 srcjars = invoker.srcjars |
| 1155 } |
| 1156 if (defined(invoker.testonly)) { |
| 1157 testonly = invoker.testonly |
| 1158 } |
| 1159 if (defined(invoker.visibility)) { |
| 1160 visibility = invoker.visibility |
| 1161 } |
| 1162 if (defined(invoker.dex_path)) { |
| 1163 dex_path = invoker.dex_path |
| 1164 } |
| 1165 if (defined(invoker.manifest_entries)) { |
| 1166 manifest_entries = invoker.manifest_entries |
| 1167 } |
| 1168 |
| 1169 supports_android = true |
| 1170 requires_android = true |
| 1171 |
| 1172 if (!defined(jar_excluded_patterns)) { |
| 1173 jar_excluded_patterns = [] |
| 1174 } |
| 1175 jar_excluded_patterns += [ |
| 1176 "*/R.class", |
| 1177 "*/R##*.class", |
| 1178 "*/Manifest.class", |
| 1179 "*/Manifest##*.class", |
| 1180 ] |
| 1181 } |
| 1182 } |
| 1183 |
| 1184 # Declare a target that packages a set of Java dependencies into a standalone |
| 1185 # .dex.jar. |
| 1186 # |
| 1187 # Variables |
| 1188 # deps: specifies the dependencies of this target. Android libraries in deps |
| 1189 # will be packaged into the resulting .dex.jar file. |
| 1190 # dex_path: location at which the output file will be put |
| 1191 template("android_standalone_library") { |
| 1192 set_sources_assignment_filter([]) |
| 1193 deps_dex(target_name) { |
| 1194 deps = invoker.deps |
| 1195 dex_path = invoker.dex_path |
| 1196 if (defined(invoker.excluded_jars)) { |
| 1197 excluded_jars = invoker.excluded_jars |
| 1198 } |
| 1199 } |
| 1200 } |
| 1201 |
| 1202 # Declare an Android library target for a prebuilt jar |
| 1203 # |
| 1204 # This target creates an Android library containing java code and Android |
| 1205 # resources. |
| 1206 # |
| 1207 # Variables |
| 1208 # deps: Specifies the dependencies of this target. Java targets in this list |
| 1209 # will be added to the javac classpath. Android resources in dependencies |
| 1210 # will be used when building this library. |
| 1211 # jar_path: Path to the prebuilt jar. |
| 1212 # proguard_preprocess: If true, proguard preprocessing will be run. This can |
| 1213 # be used to remove unwanted parts of the library. |
| 1214 # proguard_config: Path to the proguard config for preprocessing. |
| 1215 # |
| 1216 # Example |
| 1217 # android_java_prebuilt("foo_java") { |
| 1218 # jar_path = "foo.jar" |
| 1219 # deps = [ |
| 1220 # ":foo_resources", |
| 1221 # ":bar_java" |
| 1222 # ] |
| 1223 # } |
| 1224 template("android_java_prebuilt") { |
| 1225 set_sources_assignment_filter([]) |
| 1226 java_prebuilt_impl(target_name) { |
| 1227 jar_path = invoker.jar_path |
| 1228 supports_android = true |
| 1229 requires_android = true |
| 1230 if (defined(invoker.testonly)) { |
| 1231 testonly = invoker.testonly |
| 1232 } |
| 1233 if (defined(invoker.deps)) { |
| 1234 deps = invoker.deps |
| 1235 } |
| 1236 if (defined(invoker.data_deps)) { |
| 1237 data_deps = invoker.data_deps |
| 1238 } |
| 1239 if (defined(invoker.proguard_config)) { |
| 1240 proguard_config = invoker.proguard_config |
| 1241 } |
| 1242 if (defined(invoker.proguard_preprocess)) { |
| 1243 proguard_preprocess = invoker.proguard_preprocess |
| 1244 } |
| 1245 } |
| 1246 } |
| 1247 |
| 1248 # Declare an Android apk target |
| 1249 # |
| 1250 # This target creates an Android APK containing java code, resources, assets, |
| 1251 # and (possibly) native libraries. |
| 1252 # |
| 1253 # Variables |
| 1254 # android_manifest: Path to AndroidManifest.xml. |
| 1255 # android_manifest_dep: Target that generates AndroidManifest (if applicable) |
| 1256 # data_deps: List of dependencies needed at runtime. These will be built but |
| 1257 # won't change the generated .apk in any way (in fact they may be built |
| 1258 # after the .apk is). |
| 1259 # deps: List of dependencies. All Android java resources and libraries in the |
| 1260 # "transitive closure" of these dependencies will be included in the apk. |
| 1261 # Note: this "transitive closure" actually only includes such targets if |
| 1262 # they are depended on through android_library or android_resources targets |
| 1263 # (and so not through builtin targets like 'action', 'group', etc). |
| 1264 # java_files: List of .java files to include in the apk. |
| 1265 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars |
| 1266 # will be added to java_files and be included in this apk. |
| 1267 # apk_name: Name for final apk. |
| 1268 # final_apk_path: Path to final built apk. Default is |
| 1269 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name. |
| 1270 # native_libs: List paths of native libraries to include in this apk. If these |
| 1271 # libraries depend on other shared_library targets, those dependencies will |
| 1272 # also be included in the apk. |
| 1273 # apk_under_test: For an instrumentation test apk, this is the target of the |
| 1274 # tested apk. |
| 1275 # include_all_resources - If true include all resource IDs in all generated |
| 1276 # R.java files. |
| 1277 # testonly: Marks this target as "test-only". |
| 1278 # |
| 1279 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in |
| 1280 # this directory will be included in the library. This is only supported to |
| 1281 # ease the gyp->gn conversion and will be removed in the future. |
| 1282 # |
| 1283 # Example |
| 1284 # android_apk("foo_apk") { |
| 1285 # android_manifest = "AndroidManifest.xml" |
| 1286 # java_files = [ |
| 1287 # "android/org/chromium/foo/FooApplication.java", |
| 1288 # "android/org/chromium/foo/FooActivity.java", |
| 1289 # ] |
| 1290 # deps = [ |
| 1291 # ":foo_support_java" |
| 1292 # ":foo_resources" |
| 1293 # ] |
| 1294 # srcjar_deps = [ |
| 1295 # ":foo_generated_enum" |
| 1296 # ] |
| 1297 # native_libs = [ |
| 1298 # native_lib_path |
| 1299 # ] |
| 1300 # } |
| 1301 template("android_apk") { |
| 1302 set_sources_assignment_filter([]) |
| 1303 if (defined(invoker.testonly)) { |
| 1304 testonly = invoker.testonly |
| 1305 } |
| 1306 |
| 1307 assert(defined(invoker.final_apk_path) || defined(invoker.apk_name)) |
| 1308 assert(defined(invoker.android_manifest)) |
| 1309 gen_dir = "$target_gen_dir/$target_name" |
| 1310 base_path = "$gen_dir/$target_name" |
| 1311 _build_config = "$target_gen_dir/$target_name.build_config" |
| 1312 resources_zip_path = "$base_path.resources.zip" |
| 1313 _all_resources_zip_path = "$base_path.resources.all.zip" |
| 1314 jar_path = "$base_path.jar" |
| 1315 _template_name = target_name |
| 1316 |
| 1317 final_dex_path = "$gen_dir/classes.dex" |
| 1318 final_dex_target_name = "${_template_name}__final_dex" |
| 1319 |
| 1320 _final_apk_path = "" |
| 1321 if (defined(invoker.final_apk_path)) { |
| 1322 _final_apk_path = invoker.final_apk_path |
| 1323 } else if (defined(invoker.apk_name)) { |
| 1324 _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk" |
| 1325 } |
| 1326 _dist_jar_path_list = |
| 1327 process_file_template( |
| 1328 [ _final_apk_path ], |
| 1329 "$root_build_dir/test.lib.java/{{source_name_part}}.jar") |
| 1330 _dist_jar_path = _dist_jar_path_list[0] |
| 1331 |
| 1332 _native_libs = [] |
| 1333 |
| 1334 _version_code = "1" |
| 1335 if (defined(invoker.version_code)) { |
| 1336 _version_code = invoker.version_code |
| 1337 } |
| 1338 |
| 1339 _version_name = "Developer Build" |
| 1340 if (defined(invoker.version_name)) { |
| 1341 _version_name = invoker.version_name |
| 1342 } |
| 1343 _keystore_path = android_default_keystore_path |
| 1344 _keystore_name = android_default_keystore_name |
| 1345 _keystore_password = android_default_keystore_password |
| 1346 |
| 1347 if (defined(invoker.keystore_path)) { |
| 1348 _keystore_path = invoker.keystore_path |
| 1349 _keystore_name = invoker.keystore_name |
| 1350 _keystore_password = invoker.keystore_password |
| 1351 } |
| 1352 |
| 1353 _srcjar_deps = [] |
| 1354 if (defined(invoker.srcjar_deps)) { |
| 1355 _srcjar_deps += invoker.srcjar_deps |
| 1356 } |
| 1357 |
| 1358 _load_library_from_apk = false |
| 1359 |
| 1360 # The dependency that makes the chromium linker, if any is needed. |
| 1361 _chromium_linker_dep = [] |
| 1362 |
| 1363 if (defined(invoker.native_libs)) { |
| 1364 _use_chromium_linker = false |
| 1365 if (defined(invoker.use_chromium_linker)) { |
| 1366 _use_chromium_linker = |
| 1367 invoker.use_chromium_linker && chromium_linker_supported |
| 1368 _chromium_linker_dep = [ "//base/android/linker:chromium_android_linker" ] |
| 1369 } |
| 1370 |
| 1371 if (defined(invoker.load_library_from_apk) && |
| 1372 invoker.load_library_from_apk) { |
| 1373 _load_library_from_apk = true |
| 1374 assert(_use_chromium_linker, |
| 1375 "Loading library from the apk requires use" + |
| 1376 " of the Chromium linker.") |
| 1377 } |
| 1378 |
| 1379 _enable_relocation_packing = false |
| 1380 if (defined(invoker.enable_relocation_packing) && |
| 1381 invoker.enable_relocation_packing) { |
| 1382 _enable_relocation_packing = relocation_packing_supported |
| 1383 assert(_use_chromium_linker, |
| 1384 "Relocation packing requires use of the" + " Chromium linker.") |
| 1385 } |
| 1386 |
| 1387 if (is_component_build) { |
| 1388 _native_libs += [ "$root_out_dir/lib.stripped/libc++_shared.so" ] |
| 1389 _chromium_linker_dep += [ "//build/android:cpplib_stripped" ] |
| 1390 } |
| 1391 |
| 1392 # Allow native_libs to be in the form "foo.so" or "foo.cr.so" |
| 1393 _first_ext_removed = |
| 1394 process_file_template(invoker.native_libs, "{{source_name_part}}") |
| 1395 _native_libs += process_file_template( |
| 1396 _first_ext_removed, |
| 1397 "$root_build_dir/lib.stripped/{{source_name_part}}$android_product_e
xtension") |
| 1398 |
| 1399 _native_libs_dir = base_path + "/libs" |
| 1400 |
| 1401 if (_use_chromium_linker) { |
| 1402 _native_libs += [ "$root_build_dir/lib.stripped/libchromium_android_linker
$android_product_extension" ] |
| 1403 } |
| 1404 |
| 1405 _enable_relocation_packing = false |
| 1406 if (_use_chromium_linker && defined(invoker.enable_relocation_packing) && |
| 1407 invoker.enable_relocation_packing) { |
| 1408 _enable_relocation_packing = true |
| 1409 } |
| 1410 |
| 1411 _native_lib_version_rule = "" |
| 1412 if (defined(invoker.native_lib_version_rule)) { |
| 1413 _native_lib_version_rule = invoker.native_lib_version_rule |
| 1414 } |
| 1415 _native_lib_version_arg = "\"\"" |
| 1416 if (defined(invoker.native_lib_version_arg)) { |
| 1417 _native_lib_version_arg = invoker.native_lib_version_arg |
| 1418 } |
| 1419 } |
| 1420 |
| 1421 _android_manifest_deps = [] |
| 1422 if (defined(invoker.android_manifest_dep)) { |
| 1423 _android_manifest_deps = [ invoker.android_manifest_dep ] |
| 1424 } |
| 1425 _android_manifest = invoker.android_manifest |
| 1426 |
| 1427 _rebased_build_config = rebase_path(_build_config, root_build_dir) |
| 1428 _create_abi_split = |
| 1429 defined(invoker.create_abi_split) && invoker.create_abi_split |
| 1430 _create_density_splits = |
| 1431 defined(invoker.create_density_splits) && invoker.create_density_splits |
| 1432 |
| 1433 # Help GN understand that _create_abi_split is not unused (bug in GN). |
| 1434 assert(_create_abi_split || true) |
| 1435 |
| 1436 build_config_target = "${_template_name}__build_config" |
| 1437 write_build_config(build_config_target) { |
| 1438 type = "android_apk" |
| 1439 dex_path = final_dex_path |
| 1440 resources_zip = resources_zip_path |
| 1441 build_config = _build_config |
| 1442 android_manifest = _android_manifest |
| 1443 |
| 1444 deps = _chromium_linker_dep + _android_manifest_deps |
| 1445 if (defined(invoker.deps)) { |
| 1446 deps += invoker.deps |
| 1447 } |
| 1448 |
| 1449 if (defined(invoker.apk_under_test)) { |
| 1450 apk_under_test = invoker.apk_under_test |
| 1451 } |
| 1452 |
| 1453 native_libs = _native_libs |
| 1454 } |
| 1455 |
| 1456 final_deps = [] |
| 1457 |
| 1458 process_resources_target = "${_template_name}__process_resources" |
| 1459 final_deps += [ ":$process_resources_target" ] |
| 1460 process_resources(process_resources_target) { |
| 1461 srcjar_path = "${target_gen_dir}/${target_name}.srcjar" |
| 1462 r_text_path = "${target_gen_dir}/${target_name}_R.txt" |
| 1463 android_manifest = _android_manifest |
| 1464 resource_dirs = [ "//build/android/ant/empty/res" ] |
| 1465 zip_path = resources_zip_path |
| 1466 all_resources_zip_path = _all_resources_zip_path |
| 1467 generate_constant_ids = true |
| 1468 |
| 1469 if (defined(invoker.include_all_resources)) { |
| 1470 include_all_resources = invoker.include_all_resources |
| 1471 } |
| 1472 |
| 1473 build_config = _build_config |
| 1474 deps = _android_manifest_deps + [ ":$build_config_target" ] |
| 1475 if (defined(invoker.deps)) { |
| 1476 deps += invoker.deps |
| 1477 } |
| 1478 } |
| 1479 _srcjar_deps += [ ":$process_resources_target" ] |
| 1480 |
| 1481 if (_native_libs != []) { |
| 1482 _enable_chromium_linker_tests = false |
| 1483 if (defined(invoker.enable_chromium_linker_tests)) { |
| 1484 _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests |
| 1485 } |
| 1486 |
| 1487 java_cpp_template("${_template_name}__native_libraries_java") { |
| 1488 package_name = "org/chromium/base/library_loader" |
| 1489 sources = [ |
| 1490 "//base/android/java/templates/NativeLibraries.template", |
| 1491 ] |
| 1492 inputs = [ |
| 1493 _build_config, |
| 1494 ] |
| 1495 deps = [ |
| 1496 ":$build_config_target", |
| 1497 ] |
| 1498 if (_native_lib_version_rule != "") { |
| 1499 deps += [ _native_lib_version_rule ] |
| 1500 } |
| 1501 |
| 1502 defines = [ |
| 1503 "NATIVE_LIBRARIES_LIST=" + |
| 1504 "@FileArg($_rebased_build_config:native:java_libraries_list)", |
| 1505 "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg", |
| 1506 ] |
| 1507 if (_use_chromium_linker) { |
| 1508 defines += [ "ENABLE_CHROMIUM_LINKER" ] |
| 1509 } |
| 1510 if (_load_library_from_apk) { |
| 1511 defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ] |
| 1512 } |
| 1513 if (_enable_chromium_linker_tests) { |
| 1514 defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ] |
| 1515 } |
| 1516 } |
| 1517 _srcjar_deps += [ ":${_template_name}__native_libraries_java" ] |
| 1518 } |
| 1519 |
| 1520 java_target = "${_template_name}__java" |
| 1521 final_deps += [ ":$java_target" ] |
| 1522 java_library_impl(java_target) { |
| 1523 supports_android = true |
| 1524 requires_android = true |
| 1525 override_build_config = _build_config |
| 1526 deps = _android_manifest_deps + [ ":$build_config_target" ] |
| 1527 |
| 1528 android_manifest = _android_manifest |
| 1529 chromium_code = true |
| 1530 if (defined(invoker.java_files)) { |
| 1531 java_files = invoker.java_files |
| 1532 } else if (defined(invoker.DEPRECATED_java_in_dir)) { |
| 1533 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir |
| 1534 } else { |
| 1535 java_files = [] |
| 1536 } |
| 1537 srcjar_deps = _srcjar_deps |
| 1538 dex_path = base_path + ".dex.jar" |
| 1539 |
| 1540 if (defined(invoker.deps)) { |
| 1541 deps += invoker.deps |
| 1542 } |
| 1543 } |
| 1544 |
| 1545 if (_dist_jar_path != "") { |
| 1546 create_dist_target = "${_template_name}__create_dist_jar" |
| 1547 final_deps += [ ":$create_dist_target" ] |
| 1548 |
| 1549 # TODO(cjhopman): This is only ever needed to calculate the list of tests to |
| 1550 # run. See build/android/pylib/instrumentation/test_jar.py. We should be |
| 1551 # able to just do that calculation at build time instead. |
| 1552 action(create_dist_target) { |
| 1553 script = "//build/android/gyp/create_dist_jar.py" |
| 1554 depfile = "$target_gen_dir/$target_name.d" |
| 1555 inputs = [ |
| 1556 _build_config, |
| 1557 ] |
| 1558 outputs = [ |
| 1559 depfile, |
| 1560 _dist_jar_path, |
| 1561 ] |
| 1562 args = [ |
| 1563 "--depfile", |
| 1564 rebase_path(depfile, root_build_dir), |
| 1565 "--output", |
| 1566 rebase_path(_dist_jar_path, root_build_dir), |
| 1567 "--inputs=@FileArg($_rebased_build_config:dist_jar:dependency_jars)", |
| 1568 ] |
| 1569 inputs += [ jar_path ] |
| 1570 _rebased_jar_path = rebase_path([ jar_path ], root_build_dir) |
| 1571 args += [ "--inputs=$_rebased_jar_path" ] |
| 1572 deps = [ |
| 1573 ":$build_config_target", # Generates the build config file. |
| 1574 ":$java_target", # Generates the jar file. |
| 1575 ] |
| 1576 } |
| 1577 } |
| 1578 |
| 1579 final_deps += [ ":$final_dex_target_name" ] |
| 1580 dex("${final_dex_target_name}_jar") { |
| 1581 deps = [ |
| 1582 ":$build_config_target", |
| 1583 ":$java_target", |
| 1584 ] |
| 1585 sources = [ |
| 1586 jar_path, |
| 1587 ] |
| 1588 inputs = [ |
| 1589 _build_config, |
| 1590 ] |
| 1591 output = "${final_dex_path}.jar" |
| 1592 dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files" |
| 1593 args = [ "--inputs=@FileArg($dex_arg_key)" ] |
| 1594 } |
| 1595 |
| 1596 dex("$final_dex_target_name") { |
| 1597 deps = [ |
| 1598 ":${final_dex_target_name}_jar", |
| 1599 ] |
| 1600 sources = [ |
| 1601 "${final_dex_path}.jar", |
| 1602 ] |
| 1603 output = final_dex_path |
| 1604 } |
| 1605 |
| 1606 if (_native_libs != []) { |
| 1607 action("${_template_name}__prepare_native") { |
| 1608 script = "//build/android/gyp/pack_relocations.py" |
| 1609 packed_libraries_dir = "$_native_libs_dir/$android_app_abi" |
| 1610 depfile = "$target_gen_dir/$target_name.d" |
| 1611 outputs = [ |
| 1612 depfile, |
| 1613 ] |
| 1614 |
| 1615 inputs = _native_libs |
| 1616 deps = _chromium_linker_dep |
| 1617 |
| 1618 inputs += [ _build_config ] |
| 1619 deps += [ ":$build_config_target" ] |
| 1620 |
| 1621 skip_packing_list = [ |
| 1622 "gdbserver", |
| 1623 "libchromium_android_linker$android_product_extension", |
| 1624 ] |
| 1625 |
| 1626 enable_packing_arg = 0 |
| 1627 if (_enable_relocation_packing) { |
| 1628 enable_packing_arg = 1 |
| 1629 deps += [ relocation_packer_target ] |
| 1630 } |
| 1631 |
| 1632 args = [ |
| 1633 "--depfile", |
| 1634 rebase_path(depfile, root_build_dir), |
| 1635 "--enable-packing=$enable_packing_arg", |
| 1636 "--exclude-packing-list=$skip_packing_list", |
| 1637 "--android-pack-relocations", |
| 1638 rebase_path(relocation_packer_exe, root_build_dir), |
| 1639 "--stripped-libraries-dir", |
| 1640 rebase_path(root_build_dir, root_build_dir), |
| 1641 "--packed-libraries-dir", |
| 1642 rebase_path(packed_libraries_dir, root_build_dir), |
| 1643 "--libraries=@FileArg(${_rebased_build_config}:native:libraries)", |
| 1644 "--clear-dir", |
| 1645 ] |
| 1646 |
| 1647 if (defined(invoker.deps)) { |
| 1648 deps += invoker.deps |
| 1649 } |
| 1650 if (defined(invoker.public_deps)) { |
| 1651 public_deps = invoker.public_deps |
| 1652 } |
| 1653 if (defined(invoker.data_deps)) { |
| 1654 data_deps = invoker.data_deps |
| 1655 } |
| 1656 |
| 1657 if (is_debug) { |
| 1658 rebased_gdbserver = rebase_path([ android_gdbserver ], root_build_dir) |
| 1659 inputs += [ android_gdbserver ] |
| 1660 args += [ "--libraries=$rebased_gdbserver" ] |
| 1661 } |
| 1662 } |
| 1663 } |
| 1664 |
| 1665 final_deps += [ ":${_template_name}__create" ] |
| 1666 create_apk("${_template_name}__create") { |
| 1667 apk_path = _final_apk_path |
| 1668 android_manifest = _android_manifest |
| 1669 resources_zip = _all_resources_zip_path |
| 1670 dex_path = final_dex_path |
| 1671 load_library_from_apk = _load_library_from_apk |
| 1672 create_density_splits = _create_density_splits |
| 1673 if (defined(invoker.language_splits)) { |
| 1674 language_splits = invoker.language_splits |
| 1675 } |
| 1676 if (defined(invoker.extensions_to_not_compress)) { |
| 1677 extensions_to_not_compress = invoker.extensions_to_not_compress |
| 1678 } else { |
| 1679 # Allow icu data, v8 snapshots, and pak files to be loaded directly from |
| 1680 # the .apk. |
| 1681 # Note: These are actually suffix matches, not necessarily extensions. |
| 1682 extensions_to_not_compress = ".dat,.bin,.pak" |
| 1683 } |
| 1684 |
| 1685 version_code = _version_code |
| 1686 version_name = _version_name |
| 1687 |
| 1688 keystore_name = _keystore_name |
| 1689 keystore_path = _keystore_path |
| 1690 keystore_password = _keystore_password |
| 1691 |
| 1692 # This target generates the input file _all_resources_zip_path. |
| 1693 deps = _android_manifest_deps + [ |
| 1694 ":$process_resources_target", |
| 1695 ":$final_dex_target_name", |
| 1696 ] |
| 1697 if (defined(invoker.deps)) { |
| 1698 deps += invoker.deps |
| 1699 } |
| 1700 |
| 1701 if (defined(invoker.asset_location)) { |
| 1702 asset_location = invoker.asset_location |
| 1703 |
| 1704 # We don't know the exact dependencies that create the assets in |
| 1705 # |asset_location|; we depend on all caller deps until a better solution |
| 1706 # is figured out (http://crbug.com/433330). |
| 1707 if (defined(invoker.deps)) { |
| 1708 deps += invoker.deps |
| 1709 } |
| 1710 } |
| 1711 |
| 1712 if (_native_libs != [] && !_create_abi_split) { |
| 1713 native_libs_dir = _native_libs_dir |
| 1714 deps += [ ":${_template_name}__prepare_native" ] |
| 1715 } |
| 1716 } |
| 1717 |
| 1718 if (_native_libs != [] && _create_abi_split) { |
| 1719 _manifest_rule = "${_template_name}__split_manifest_abi_${android_app_abi}" |
| 1720 generate_split_manifest(_manifest_rule) { |
| 1721 main_manifest = _android_manifest |
| 1722 out_manifest = |
| 1723 "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml" |
| 1724 split_name = "abi_${android_app_abi}" |
| 1725 deps = _android_manifest_deps |
| 1726 } |
| 1727 |
| 1728 _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}" |
| 1729 final_deps += [ ":$_apk_rule" ] |
| 1730 create_apk(_apk_rule) { |
| 1731 _split_paths = process_file_template( |
| 1732 [ _final_apk_path ], |
| 1733 "{{source_dir}}/{{source_name_part}}-abi-${android_app_abi}.apk") |
| 1734 apk_path = _split_paths[0] |
| 1735 base_path = "$gen_dir/$_apk_rule" |
| 1736 |
| 1737 manifest_outputs = get_target_outputs(":${_manifest_rule}") |
| 1738 android_manifest = manifest_outputs[1] |
| 1739 load_library_from_apk = _load_library_from_apk |
| 1740 |
| 1741 version_code = _version_code |
| 1742 version_name = _version_name |
| 1743 |
| 1744 keystore_name = _keystore_name |
| 1745 keystore_path = _keystore_path |
| 1746 keystore_password = _keystore_password |
| 1747 |
| 1748 native_libs_dir = _native_libs_dir |
| 1749 deps = [ |
| 1750 ":${_template_name}__prepare_native", |
| 1751 ":${_manifest_rule}", |
| 1752 ] |
| 1753 } |
| 1754 } |
| 1755 |
| 1756 if (defined(invoker.flutter_dist_jar)) { |
| 1757 flutter_jar_target = "${_template_name}__create_flutter_jar" |
| 1758 final_deps += [ ":$flutter_jar_target" ] |
| 1759 |
| 1760 action(flutter_jar_target) { |
| 1761 script = "//build/android/gyp/create_flutter_jar.py" |
| 1762 depfile = "$target_gen_dir/$target_name.d" |
| 1763 inputs = [ |
| 1764 _dist_jar_path, |
| 1765 ] |
| 1766 outputs = [ |
| 1767 invoker.flutter_dist_jar, |
| 1768 ] |
| 1769 args = [ |
| 1770 "--depfile", |
| 1771 rebase_path(depfile, root_build_dir), |
| 1772 "--output", |
| 1773 rebase_path(invoker.flutter_dist_jar, root_build_dir), |
| 1774 "--dist_jar", |
| 1775 rebase_path(_dist_jar_path, root_build_dir), |
| 1776 "--android_abi", |
| 1777 "$android_app_abi", |
| 1778 "--asset_dir", |
| 1779 rebase_path(invoker.asset_location, root_build_dir), |
| 1780 ] |
| 1781 foreach(native_lib, rebase_path(_native_libs, root_build_dir)) { |
| 1782 args += [ |
| 1783 "--native_lib", |
| 1784 native_lib, |
| 1785 ] |
| 1786 } |
| 1787 deps = [ |
| 1788 ":$create_dist_target", |
| 1789 ":${_template_name}__prepare_native" |
| 1790 ] |
| 1791 if (defined(invoker.deps)) { |
| 1792 deps += invoker.deps |
| 1793 } |
| 1794 } |
| 1795 } |
| 1796 |
| 1797 group(target_name) { |
| 1798 deps = final_deps |
| 1799 if (defined(invoker.data_deps)) { |
| 1800 data_deps = invoker.data_deps |
| 1801 } |
| 1802 } |
| 1803 } |
| 1804 |
| 1805 # Declare an Android instrumentation test apk |
| 1806 # |
| 1807 # This target creates an Android instrumentation test apk. |
| 1808 # |
| 1809 # Variables |
| 1810 # android_manifest: Path to AndroidManifest.xml. |
| 1811 # data_deps: List of dependencies needed at runtime. These will be built but |
| 1812 # won't change the generated .apk in any way (in fact they may be built |
| 1813 # after the .apk is). |
| 1814 # deps: List of dependencies. All Android java resources and libraries in the |
| 1815 # "transitive closure" of these dependencies will be included in the apk. |
| 1816 # Note: this "transitive closure" actually only includes such targets if |
| 1817 # they are depended on through android_library or android_resources targets |
| 1818 # (and so not through builtin targets like 'action', 'group', etc). |
| 1819 # java_files: List of .java files to include in the apk. |
| 1820 # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars |
| 1821 # will be added to java_files and be included in this apk. |
| 1822 # apk_name: Name for final apk. |
| 1823 # support_apk_path: Path to a support apk. If present, the test runner script |
| 1824 # will install it on the device before running the instrumentation tests. |
| 1825 # Should be a path relative to the src root. |
| 1826 # final_apk_path: Path to final built apk. Default is |
| 1827 # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name. |
| 1828 # native_libs: List paths of native libraries to include in this apk. If these |
| 1829 # libraries depend on other shared_library targets, those dependencies will |
| 1830 # also be included in the apk. |
| 1831 # apk_under_test: The apk being tested. |
| 1832 # isolate_file: Isolate file containing the list of test data dependencies. |
| 1833 # |
| 1834 # DEPRECATED_java_in_dir: Directory containing java files. All .java files in |
| 1835 # this directory will be included in the library. This is only supported to |
| 1836 # ease the gyp->gn conversion and will be removed in the future. |
| 1837 # |
| 1838 # Example |
| 1839 # instrumentation_test_apk("foo_test_apk") { |
| 1840 # android_manifest = "AndroidManifest.xml" |
| 1841 # apk_name = "FooTest" |
| 1842 # apk_under_test = "Foo" |
| 1843 # java_files = [ |
| 1844 # "android/org/chromium/foo/FooTestCase.java", |
| 1845 # "android/org/chromium/foo/FooExampleTest.java", |
| 1846 # ] |
| 1847 # deps = [ |
| 1848 # ":foo_test_support_java" |
| 1849 # ] |
| 1850 # } |
| 1851 template("instrumentation_test_apk") { |
| 1852 set_sources_assignment_filter([]) |
| 1853 testonly = true |
| 1854 _template_name = target_name |
| 1855 |
| 1856 if (defined(invoker.apk_name)) { |
| 1857 test_runner_data_dep = [ ":${_template_name}__test_runner_script" ] |
| 1858 test_runner_script("${_template_name}__test_runner_script") { |
| 1859 test_name = invoker.target_name |
| 1860 test_type = "instrumentation" |
| 1861 test_apk = invoker.apk_name |
| 1862 if (defined(invoker.isolate_file)) { |
| 1863 isolate_file = invoker.isolate_file |
| 1864 } |
| 1865 if (defined(invoker.support_apk_path)) { |
| 1866 support_apk_path = invoker.support_apk_path |
| 1867 } |
| 1868 } |
| 1869 } |
| 1870 |
| 1871 android_apk(target_name) { |
| 1872 if (defined(invoker.android_manifest)) { |
| 1873 android_manifest = invoker.android_manifest |
| 1874 } |
| 1875 data_deps = [ |
| 1876 "//testing/android/driver:driver_apk", |
| 1877 "//tools/android/forwarder2", |
| 1878 "//tools/android/md5sum", |
| 1879 ] |
| 1880 if (defined(test_runner_data_dep)) { |
| 1881 data_deps += test_runner_data_dep |
| 1882 } |
| 1883 if (defined(invoker.data_deps)) { |
| 1884 data_deps += invoker.data_deps |
| 1885 } |
| 1886 deps = [ |
| 1887 "//testing/android/broker:broker_java", |
| 1888 ] |
| 1889 if (defined(invoker.deps)) { |
| 1890 deps += invoker.deps |
| 1891 } |
| 1892 if (defined(invoker.java_files)) { |
| 1893 java_files = invoker.java_files |
| 1894 } |
| 1895 if (defined(invoker.srcjar_deps)) { |
| 1896 srcjar_deps = invoker.srcjar_deps |
| 1897 } |
| 1898 if (defined(invoker.apk_name)) { |
| 1899 apk_name = invoker.apk_name |
| 1900 } |
| 1901 if (defined(invoker.final_apk_path)) { |
| 1902 final_apk_path = invoker.final_apk_path |
| 1903 } |
| 1904 if (defined(invoker.native_libs)) { |
| 1905 native_libs = invoker.native_libs |
| 1906 } |
| 1907 if (defined(invoker.apk_under_test)) { |
| 1908 apk_under_test = invoker.apk_under_test |
| 1909 } |
| 1910 if (defined(invoker.DEPRECATED_java_in_dir)) { |
| 1911 DEPRECATED_java_in_dir = invoker.DEPRECATED_java_in_dir |
| 1912 } |
| 1913 } |
| 1914 } |
| 1915 |
| 1916 # Declare an Android gtest apk |
| 1917 # |
| 1918 # This target creates an Android apk for running gtest-based unittests. |
| 1919 # |
| 1920 # Variables |
| 1921 # deps: Specifies the dependencies of this target. These will be passed to |
| 1922 # the underlying android_apk invocation and should include the java and |
| 1923 # resource dependencies of the apk. |
| 1924 # unittests_dep: This should be the label of the gtest native target. This |
| 1925 # target must be defined previously in the same file. |
| 1926 # unittests_binary: The basename of the library produced by the unittests_dep |
| 1927 # target. If unspecified, it assumes the name of the unittests_dep target |
| 1928 # (which will be correct unless that target specifies an "output_name". |
| 1929 # TODO(brettw) make this automatic by allowing get_target_outputs to |
| 1930 # support executables. |
| 1931 # apk_name: The name of the produced apk. If unspecified, it uses the name |
| 1932 # of the unittests_dep target postfixed with "_apk" |
| 1933 # |
| 1934 # Example |
| 1935 # unittest_apk("foo_unittests_apk") { |
| 1936 # deps = [ ":foo_java", ":foo_resources" ] |
| 1937 # unittests_dep = ":foo_unittests" |
| 1938 # } |
| 1939 template("unittest_apk") { |
| 1940 set_sources_assignment_filter([]) |
| 1941 testonly = true |
| 1942 |
| 1943 assert(defined(invoker.unittests_dep), "Need unittests_dep for $target_name") |
| 1944 |
| 1945 test_suite_name = get_label_info(invoker.unittests_dep, "name") |
| 1946 |
| 1947 # This trivial assert is needed in case both unittests_binary and apk_name |
| 1948 # are defined, as otherwise test_suite_name would not be used. |
| 1949 assert(test_suite_name != "") |
| 1950 |
| 1951 if (defined(invoker.unittests_binary)) { |
| 1952 unittests_binary = invoker.unittests_binary |
| 1953 } else { |
| 1954 unittests_binary = "lib${test_suite_name}${android_product_extension}" |
| 1955 } |
| 1956 |
| 1957 if (defined(invoker.apk_name)) { |
| 1958 apk_name = invoker.apk_name |
| 1959 } else { |
| 1960 apk_name = test_suite_name |
| 1961 } |
| 1962 |
| 1963 android_apk(target_name) { |
| 1964 final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk" |
| 1965 java_files = [ |
| 1966 "//testing/android/native_test/java/src/org/chromium/native_test/NativeBro
wserTestActivity.java", |
| 1967 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTes
tActivity.java", |
| 1968 "//testing/android/native_test/java/src/org/chromium/native_test/NativeUni
tTestActivity.java", |
| 1969 "//testing/android/native_test/java/src/org/chromium/native_test/NativeTes
tInstrumentationTestRunner.java", |
| 1970 ] |
| 1971 android_manifest = "//testing/android/native_test/java/AndroidManifest.xml" |
| 1972 native_libs = [ unittests_binary ] |
| 1973 if (defined(invoker.asset_location)) { |
| 1974 asset_location = invoker.asset_location |
| 1975 } |
| 1976 deps = [ |
| 1977 "//base:base_java", |
| 1978 "//build/android/pylib/remote/device/dummy:remote_device_dummy_apk", |
| 1979 "//testing/android/appurify_support:appurify_support_java", |
| 1980 "//testing/android/reporter:reporter_java", |
| 1981 ] |
| 1982 if (defined(invoker.deps)) { |
| 1983 deps += invoker.deps |
| 1984 } |
| 1985 data_deps = [ "//tools/android/md5sum" ] |
| 1986 if (host_os == "linux") { |
| 1987 data_deps += [ "//tools/android/forwarder2" ] |
| 1988 } |
| 1989 if (defined(invoker.data_deps)) { |
| 1990 data_deps += invoker.data_deps |
| 1991 } |
| 1992 } |
| 1993 } |
| 1994 |
| 1995 # Generate .java files from .aidl files. |
| 1996 # |
| 1997 # This target will store the .java files in a srcjar and should be included in |
| 1998 # an android_library or android_apk's srcjar_deps. |
| 1999 # |
| 2000 # Variables |
| 2001 # sources: Paths to .aidl files to compile. |
| 2002 # import_include: Path to directory containing .java files imported by the |
| 2003 # .aidl files. |
| 2004 # interface_file: Preprocessed aidl file to import. |
| 2005 # |
| 2006 # Example |
| 2007 # android_aidl("foo_aidl") { |
| 2008 # import_include = "java/src" |
| 2009 # sources = [ |
| 2010 # "java/src/com/foo/bar/FooBarService.aidl", |
| 2011 # "java/src/com/foo/bar/FooBarServiceCallback.aidl", |
| 2012 # ] |
| 2013 # } |
| 2014 template("android_aidl") { |
| 2015 set_sources_assignment_filter([]) |
| 2016 if (defined(invoker.testonly)) { |
| 2017 testonly = invoker.testonly |
| 2018 } |
| 2019 |
| 2020 srcjar_path = "${target_gen_dir}/${target_name}.srcjar" |
| 2021 aidl_path = "${android_sdk_build_tools}/aidl" |
| 2022 framework_aidl = "$android_sdk/framework.aidl" |
| 2023 |
| 2024 action(target_name) { |
| 2025 script = "//build/android/gyp/aidl.py" |
| 2026 sources = invoker.sources |
| 2027 |
| 2028 imports = [ framework_aidl ] |
| 2029 if (defined(invoker.interface_file)) { |
| 2030 assert(invoker.interface_file != "") |
| 2031 imports += [ invoker.interface_file ] |
| 2032 } |
| 2033 |
| 2034 inputs = [ aidl_path ] + imports |
| 2035 |
| 2036 depfile = "${target_gen_dir}/${target_name}.d" |
| 2037 outputs = [ |
| 2038 depfile, |
| 2039 srcjar_path, |
| 2040 ] |
| 2041 rebased_imports = rebase_path(imports, root_build_dir) |
| 2042 args = [ |
| 2043 "--depfile", |
| 2044 rebase_path(depfile, root_build_dir), |
| 2045 "--aidl-path", |
| 2046 rebase_path(aidl_path, root_build_dir), |
| 2047 "--imports=$rebased_imports", |
| 2048 "--srcjar", |
| 2049 rebase_path(srcjar_path, root_build_dir), |
| 2050 ] |
| 2051 if (defined(invoker.import_include) && invoker.import_include != "") { |
| 2052 # TODO(cjhopman): aidl supports creating a depfile. We should be able to |
| 2053 # switch to constructing a depfile for the overall action from that |
| 2054 # instead of having all the .java files in the include paths as inputs. |
| 2055 rebased_import_includes = |
| 2056 rebase_path([ invoker.import_include ], root_build_dir) |
| 2057 args += [ "--includes=$rebased_import_includes" ] |
| 2058 |
| 2059 _java_files_build_rel = |
| 2060 exec_script("//build/android/gyp/find.py", |
| 2061 rebase_path([ invoker.import_include ], root_build_dir), |
| 2062 "list lines") |
| 2063 _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir) |
| 2064 inputs += _java_files |
| 2065 } |
| 2066 args += rebase_path(sources, root_build_dir) |
| 2067 } |
| 2068 } |
| 2069 |
| 2070 # Creates a dist directory for a native executable. |
| 2071 # |
| 2072 # Running a native executable on a device requires all the shared library |
| 2073 # dependencies of that executable. To make it easier to install and run such an |
| 2074 # executable, this will create a directory containing the native exe and all |
| 2075 # it's library dependencies. |
| 2076 # |
| 2077 # Note: It's usually better to package things as an APK than as a native |
| 2078 # executable. |
| 2079 # |
| 2080 # Variables |
| 2081 # dist_dir: Directory for the exe and libraries. Everything in this directory |
| 2082 # will be deleted before copying in the exe and libraries. |
| 2083 # binary: Path to (stripped) executable. |
| 2084 # |
| 2085 # Example |
| 2086 # create_native_executable_dist("foo_dist") { |
| 2087 # dist_dir = "$root_build_dir/foo_dist" |
| 2088 # binary = "$root_build_dir/exe.stripped/foo" |
| 2089 # deps = [ ":the_thing_that_makes_foo" ] |
| 2090 # } |
| 2091 template("create_native_executable_dist") { |
| 2092 set_sources_assignment_filter([]) |
| 2093 if (defined(invoker.testonly)) { |
| 2094 testonly = invoker.testonly |
| 2095 } |
| 2096 |
| 2097 dist_dir = invoker.dist_dir |
| 2098 binary = invoker.binary |
| 2099 template_name = target_name |
| 2100 |
| 2101 libraries_list = |
| 2102 "${target_gen_dir}/${template_name}_library_dependencies.list" |
| 2103 |
| 2104 find_deps_target_name = "${template_name}__find_library_dependencies" |
| 2105 copy_target_name = "${template_name}__copy_libraries_and_exe" |
| 2106 |
| 2107 stripped_libraries_dir = "$root_build_dir/lib.stripped" |
| 2108 action(find_deps_target_name) { |
| 2109 visibility = [ ":$copy_target_name" ] |
| 2110 |
| 2111 script = "//build/android/gyp/write_ordered_libraries.py" |
| 2112 depfile = "$target_gen_dir/$target_name.d" |
| 2113 inputs = [ |
| 2114 binary, |
| 2115 android_readelf, |
| 2116 ] |
| 2117 outputs = [ |
| 2118 depfile, |
| 2119 libraries_list, |
| 2120 ] |
| 2121 rebased_binaries = rebase_path([ binary ], root_build_dir) |
| 2122 args = [ |
| 2123 "--depfile", |
| 2124 rebase_path(depfile, root_build_dir), |
| 2125 "--input-libraries=$rebased_binaries", |
| 2126 "--libraries-dir", |
| 2127 rebase_path(stripped_libraries_dir, root_build_dir), |
| 2128 "--output", |
| 2129 rebase_path(libraries_list, root_build_dir), |
| 2130 "--readelf", |
| 2131 rebase_path(android_readelf, root_build_dir), |
| 2132 ] |
| 2133 if (defined(invoker.deps)) { |
| 2134 deps = invoker.deps |
| 2135 } |
| 2136 } |
| 2137 |
| 2138 copy_ex(copy_target_name) { |
| 2139 visibility = [ ":$template_name" ] |
| 2140 |
| 2141 clear_dir = true |
| 2142 inputs = [ |
| 2143 binary, |
| 2144 libraries_list, |
| 2145 ] |
| 2146 dest = dist_dir |
| 2147 rebased_binaries_list = rebase_path([ binary ], root_build_dir) |
| 2148 rebased_libraries_list = rebase_path(libraries_list, root_build_dir) |
| 2149 args = [ |
| 2150 "--files=$rebased_binaries_list", |
| 2151 "--files=@FileArg($rebased_libraries_list:lib_paths)", |
| 2152 ] |
| 2153 |
| 2154 deps = [ |
| 2155 ":$find_deps_target_name", |
| 2156 ] |
| 2157 if (defined(invoker.deps)) { |
| 2158 deps += invoker.deps |
| 2159 } |
| 2160 } |
| 2161 |
| 2162 group(template_name) { |
| 2163 if (defined(invoker.visibility)) { |
| 2164 visibility = invoker.visibility |
| 2165 } |
| 2166 deps = [ |
| 2167 ":$copy_target_name", |
| 2168 ] |
| 2169 } |
| 2170 } |
| 2171 |
| 2172 # Compile a protocol buffer to java. |
| 2173 # |
| 2174 # This generates java files from protocol buffers and creates an Android library |
| 2175 # containing the classes. |
| 2176 # |
| 2177 # Variables |
| 2178 # sources: Paths to .proto files to compile. |
| 2179 # proto_path: Root directory of .proto files. |
| 2180 # |
| 2181 # Example: |
| 2182 # proto_java_library("foo_proto_java") { |
| 2183 # proto_path = [ "src/foo" ] |
| 2184 # sources = [ "$proto_path/foo.proto" ] |
| 2185 # } |
| 2186 template("proto_java_library") { |
| 2187 set_sources_assignment_filter([]) |
| 2188 _protoc_dep = "//third_party/android_protobuf:android_protoc($host_toolchain)" |
| 2189 _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir") |
| 2190 _protoc_bin = "$_protoc_out_dir/android_protoc" |
| 2191 _proto_path = invoker.proto_path |
| 2192 |
| 2193 _template_name = target_name |
| 2194 |
| 2195 action("${_template_name}__protoc_java") { |
| 2196 srcjar_path = "$target_gen_dir/$target_name.srcjar" |
| 2197 script = "//build/protoc_java.py" |
| 2198 deps = [ |
| 2199 _protoc_dep, |
| 2200 ] |
| 2201 sources = invoker.sources |
| 2202 depfile = "$target_gen_dir/$target_name.d" |
| 2203 outputs = [ |
| 2204 depfile, |
| 2205 srcjar_path, |
| 2206 ] |
| 2207 args = [ |
| 2208 "--depfile", |
| 2209 rebase_path(depfile, root_build_dir), |
| 2210 "--protoc", |
| 2211 rebase_path(_protoc_bin, root_build_dir), |
| 2212 "--proto-path", |
| 2213 rebase_path(_proto_path, root_build_dir), |
| 2214 "--srcjar", |
| 2215 rebase_path(srcjar_path, root_build_dir), |
| 2216 ] + rebase_path(sources, root_build_dir) |
| 2217 } |
| 2218 |
| 2219 android_library(target_name) { |
| 2220 java_files = [] |
| 2221 srcjar_deps = [ ":${_template_name}__protoc_java" ] |
| 2222 deps = [ |
| 2223 "//third_party/android_protobuf:protobuf_nano_javalib", |
| 2224 ] |
| 2225 } |
| 2226 } |
| 2227 |
| 2228 # TODO(GYP): implement this. |
| 2229 template("uiautomator_test") { |
| 2230 set_sources_assignment_filter([]) |
| 2231 if (defined(invoker.testonly)) { |
| 2232 testonly = invoker.testonly |
| 2233 } |
| 2234 assert(target_name != "") |
| 2235 assert(invoker.deps != [] || true) |
| 2236 group(target_name) { |
| 2237 } |
| 2238 } |
OLD | NEW |