|  | # Copyright 2015 The Chromium Authors. All rights reserved. | 
|  | # Use of this source code is governed by a BSD-style license that can be | 
|  | # found in the LICENSE file. | 
|  |  | 
|  | import("//build/config/android/rules.gni") | 
|  | import("//mojo/public/mojo_application.gni") | 
|  |  | 
|  | mojo_android_path = get_path_info(".", "abspath") | 
|  |  | 
|  | template("mojo_android_java_application") { | 
|  | assert(defined(invoker.mojo_main)) | 
|  |  | 
|  | dex_output_path = "$target_out_dir/${target_name}.dex.jar" | 
|  | dex_with_manifest_output_path = | 
|  | "$target_out_dir/${target_name}_with_manifest.dex.jar" | 
|  |  | 
|  | android_lib_name = "__${target_name}_lib" | 
|  | android_standalone_name = "__${target_name}_standalone" | 
|  | android_with_manifest_name = "__${target_name}_with_manifest" | 
|  |  | 
|  | all_deps = [ | 
|  | "//mojo/public/java:bindings", | 
|  | "//mojo/public/java:system", | 
|  | ] | 
|  | if (defined(invoker.deps)) { | 
|  | all_deps += invoker.deps | 
|  | } | 
|  |  | 
|  | android_library(android_lib_name) { | 
|  | java_files = invoker.sources | 
|  |  | 
|  | deps = all_deps | 
|  | } | 
|  |  | 
|  | android_standalone_library(android_standalone_name) { | 
|  | deps = [ ":${android_lib_name}" ] + all_deps | 
|  |  | 
|  | dex_path = dex_output_path | 
|  |  | 
|  | system_gen_dir = get_path_info("//mojo/public/java/BUILD.gn", "gen_dir") | 
|  | excluded_jars = [ "${system_gen_dir}/system.dex.jar" ] | 
|  | } | 
|  |  | 
|  | action(android_with_manifest_name) { | 
|  | script = "${mojo_android_path}/add_manifest_entry.py" | 
|  |  | 
|  | deps = [ | 
|  | ":$android_standalone_name", | 
|  | ] | 
|  |  | 
|  | input = dex_output_path | 
|  | inputs = [ | 
|  | input, | 
|  | ] | 
|  |  | 
|  | output = dex_with_manifest_output_path | 
|  | outputs = [ | 
|  | output, | 
|  | ] | 
|  |  | 
|  | rebase_input = rebase_path(input) | 
|  | rebase_output = rebase_path(output) | 
|  | mojo_main = invoker.mojo_main | 
|  | args = [ | 
|  | "--input=$rebase_input", | 
|  | "--output=$rebase_output", | 
|  | "--key=Mojo-Class", | 
|  | "--value=$mojo_main", | 
|  | ] | 
|  | } | 
|  |  | 
|  | if (defined(invoker.output_name)) { | 
|  | mojo_output = "$root_out_dir/" + invoker.output_name + ".mojo" | 
|  | } else { | 
|  | mojo_output = "$root_out_dir/" + target_name + ".mojo" | 
|  | } | 
|  |  | 
|  | action(target_name) { | 
|  | script = rebase_path("mojo/public/tools/prepend.py", ".", mojo_root) | 
|  |  | 
|  | deps = [ | 
|  | ":$android_with_manifest_name", | 
|  | ] | 
|  |  | 
|  | input = dex_with_manifest_output_path | 
|  | inputs = [ | 
|  | input, | 
|  | ] | 
|  |  | 
|  | output = mojo_output | 
|  | outputs = [ | 
|  | output, | 
|  | ] | 
|  |  | 
|  | rebase_input = rebase_path(input, root_build_dir) | 
|  | rebase_output = rebase_path(output, root_build_dir) | 
|  | args = [ | 
|  | "--input=$rebase_input", | 
|  | "--output=$rebase_output", | 
|  | "--line=#!mojo mojo:java_handler", | 
|  | ] | 
|  | } | 
|  | } |