Index: build/config/android/internal_rules.gni |
diff --git a/build/config/android/internal_rules.gni b/build/config/android/internal_rules.gni |
index d6711b827f0bf14ea6df01e66ce9ada30fc6c8d5..7120bacba0ce7725ce84a0ac57a464b2d39d547a 100644 |
--- a/build/config/android/internal_rules.gni |
+++ b/build/config/android/internal_rules.gni |
@@ -55,6 +55,79 @@ template("android_lint") { |
} |
+template("dex") { |
+ if (defined(invoker.testonly)) { testonly = invoker.testonly } |
+ |
+ assert(defined(invoker.sources)) |
+ assert(defined(invoker.output)) |
+ action(target_name) { |
+ script = "//build/android/gyp/dex.py" |
+ depfile = "$target_gen_dir/$target_name.d" |
+ sources = invoker.sources |
+ outputs = [depfile, invoker.output] |
+ if (defined(invoker.inputs)) { |
+ inputs = invoker.inputs |
+ } |
+ |
+ if (defined(invoker.deps)) { |
+ deps = invoker.deps |
+ } |
+ |
+ rebased_output = rebase_path(invoker.output, root_build_dir) |
+ |
+ args = [ |
+ "--depfile", rebase_path(depfile, root_build_dir), |
+ "--android-sdk-tools", rebased_android_sdk_build_tools, |
+ "--dex-path", rebased_output, |
+ ] |
+ |
+ if (defined(invoker.no_locals) && invoker.no_locals) { |
+ args += [ |
+ "--no-locals=1" |
+ ] |
+ } |
+ |
+ if (defined(invoker.args)) { |
+ args += invoker.args |
+ } |
+ |
+ args += rebase_path(invoker.sources, root_build_dir) |
+ } |
+} |
+ |
+ |
+# Creates a zip archive of the inputs. |
+# If base_dir is provided, the archive paths will be relative to it. |
+template("zip") { |
+ if (defined(invoker.testonly)) { testonly = invoker.testonly } |
+ |
+ assert(defined(invoker.inputs)) |
+ assert(defined(invoker.output)) |
+ |
+ rebase_inputs = rebase_path(invoker.inputs, root_build_dir) |
+ rebase_output = rebase_path(invoker.output, root_build_dir) |
+ action(target_name) { |
+ script = "//build/android/gn/zip.py" |
+ depfile = "$target_gen_dir/$target_name.d" |
+ inputs = invoker.inputs |
+ outputs = [ |
+ depfile, |
+ invoker.output |
+ ] |
+ args = [ |
+ "--depfile", rebase_path(depfile, root_build_dir), |
+ "--inputs=$rebase_inputs", |
+ "--output=$rebase_output", |
+ ] |
+ if (defined(invoker.base_dir)) { |
+ args += [ |
+ "--base-dir", rebase_path(invoker.base_dir, root_build_dir) |
+ ] |
+ } |
+ } |
+} |
+ |
+ |
# Write the target's .build_config file. This is a json file that contains a |
# dictionary of information about how to build this target (things that |
# require knowledge about this target's dependencies and cannot be calculated |
@@ -73,7 +146,7 @@ template("write_build_config") { |
type = invoker.type |
build_config = invoker.build_config |
- assert(type == "android_apk" || type == "android_library" || type == "android_resources") |
+ assert(type == "android_apk" || type == "java_library" || type == "android_resources") |
action(target_name) { |
script = "//build/android/gyp/write_build_config.py" |
@@ -105,14 +178,43 @@ template("write_build_config") { |
"--build-config", rebase_path(build_config, root_build_dir), |
] |
- if (type == "android_library" || type == "android_apk") { |
+ is_java_library = type == "java_library" |
+ is_apk = type == "android_apk" |
+ is_android_resources = type == "android_resources" |
+ |
+ supports_android = (is_apk || is_android_resources || |
+ (is_java_library && defined(invoker.supports_android) && |
+ invoker.supports_android)) |
+ requires_android = (is_apk || is_android_resources || |
+ (is_java_library && defined(invoker.requires_android) && |
+ invoker.requires_android)) |
+ |
+ assert(!requires_android || supports_android, "requires_android requires" + |
+ " supports_android") |
+ # Mark these variables as used. |
+ assert(is_java_library || true) |
+ assert(is_apk || true) |
+ assert(is_android_resources || true) |
+ |
+ if (is_java_library || is_apk) { |
args += [ |
"--jar-path", rebase_path(invoker.jar_path, root_build_dir), |
+ ] |
+ } |
+ |
+ if (is_apk || (is_java_library && supports_android)) { |
+ args += [ |
"--dex-path", rebase_path(invoker.dex_path, root_build_dir), |
] |
} |
+ if (supports_android) { |
+ args += [ "--supports-android" ] |
+ } |
+ if (requires_android) { |
+ args += [ "--requires-android" ] |
+ } |
- if (type == "android_resources" || type == "android_apk") { |
+ if (is_android_resources || is_apk) { |
assert(defined(invoker.resources_zip)) |
args += [ |
"--resources-zip", rebase_path(invoker.resources_zip, root_build_dir), |
@@ -132,7 +234,7 @@ template("write_build_config") { |
} |
} |
- if (type == "android_apk") { |
+ if (is_apk) { |
if (defined(invoker.native_libs)) { |
rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir) |
rebased_android_readelf = rebase_path(android_readelf, root_build_dir) |
@@ -152,77 +254,75 @@ template("write_build_config") { |
} |
-# Creates a zip archive of the inputs. |
-# If base_dir is provided, the archive paths will be relative to it. |
-template("zip") { |
+template("process_java_prebuilt") { |
if (defined(invoker.testonly)) { testonly = invoker.testonly } |
- assert(defined(invoker.inputs)) |
- assert(defined(invoker.output)) |
+ _input_jar_path = invoker.input_jar_path |
+ _output_jar_path = invoker.output_jar_path |
+ _jar_toc_path = _output_jar_path + ".TOC" |
- rebase_inputs = rebase_path(invoker.inputs, root_build_dir) |
- rebase_output = rebase_path(invoker.output, root_build_dir) |
- action(target_name) { |
- script = "//build/android/gn/zip.py" |
+ assert(invoker.build_config != "") |
+ |
+ if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) { |
+ _proguard_jar_path = "$android_sdk_root/tools/proguard/lib/proguard.jar" |
+ _proguard_config_path = invoker.proguard_config |
+ _build_config = invoker.build_config |
+ _rebased_build_config = rebase_path(_build_config, root_build_dir) |
+ action("${target_name}__proguard_process") { |
+ script = "//build/android/gyp/proguard.py" |
+ inputs = [ |
+ android_sdk_jar, |
+ _proguard_jar_path, |
+ _build_config, |
+ _input_jar_path, |
+ _proguard_config_path, |
+ ] |
+ depfile = "${target_gen_dir}/${target_name}.d" |
+ outputs = [ |
+ depfile, |
+ _output_jar_path, |
+ ] |
+ args = [ |
+ "--depfile", rebase_path(depfile, root_build_dir), |
+ "--proguard-path", rebase_path(_proguard_jar_path, root_build_dir), |
+ "--input-path", rebase_path(_input_jar_path, root_build_dir), |
+ "--output-path", rebase_path(_output_jar_path, root_build_dir), |
+ "--proguard-config", rebase_path(_proguard_config_path, root_build_dir), |
+ "--classpath", rebased_android_sdk_jar, |
+ "--classpath=@FileArg($_rebased_build_config:javac:classpath)", |
+ ] |
+ } |
+ } else { |
+ copy("${target_name}__copy_jar") { |
+ sources = [_input_jar_path] |
+ outputs = [_output_jar_path] |
+ } |
+ } |
+ |
+ action("${target_name}__jar_toc") { |
+ script = "//build/android/gyp/jar_toc.py" |
depfile = "$target_gen_dir/$target_name.d" |
- inputs = invoker.inputs |
outputs = [ |
depfile, |
- invoker.output |
+ _jar_toc_path, |
+ _jar_toc_path + ".md5.stamp" |
] |
+ inputs = [ _output_jar_path ] |
args = [ |
"--depfile", rebase_path(depfile, root_build_dir), |
- "--inputs=$rebase_inputs", |
- "--output=$rebase_output", |
+ "--jar-path", rebase_path(_output_jar_path, root_build_dir), |
+ "--toc-path", rebase_path(_jar_toc_path, root_build_dir), |
] |
- if (defined(invoker.base_dir)) { |
- args += [ |
- "--base-dir", rebase_path(invoker.base_dir, root_build_dir) |
- ] |
- } |
} |
-} |
- |
-template("dex") { |
- if (defined(invoker.testonly)) { testonly = invoker.testonly } |
- |
- assert(defined(invoker.sources)) |
- assert(defined(invoker.output)) |
- action(target_name) { |
- script = "//build/android/gyp/dex.py" |
- depfile = "$target_gen_dir/$target_name.d" |
- sources = invoker.sources |
- outputs = [depfile, invoker.output] |
- if (defined(invoker.inputs)) { |
- inputs = invoker.inputs |
- } |
- |
- if (defined(invoker.deps)) { |
- deps = invoker.deps |
- } |
- |
- rebased_output = rebase_path(invoker.output, root_build_dir) |
- args = [ |
- "--depfile", rebase_path(depfile, root_build_dir), |
- "--android-sdk-tools", rebased_android_sdk_build_tools, |
- "--dex-path", rebased_output, |
+ group(target_name) { |
+ deps = [ |
+ ":${target_name}__jar_toc" |
] |
- |
- if (defined(invoker.no_locals) && invoker.no_locals) { |
- args += [ |
- "--no-locals=1" |
- ] |
- } |
- |
- if (defined(invoker.args)) { |
- args += invoker.args |
- } |
- |
- args += rebase_path(invoker.sources, root_build_dir) |
} |
} |
+ |
# Packages resources, assets, dex, and native libraries into an apk. Signs and |
# zipaligns the apk. |
template("create_apk") { |
@@ -379,74 +479,68 @@ template("create_apk") { |
} |
} |
-template("java_prebuilt") { |
+template("java_prebuilt_impl") { |
if (defined(invoker.testonly)) { testonly = invoker.testonly } |
+ _supports_android = ( |
+ defined(invoker.supports_android) && invoker.supports_android) |
- _input_jar_path = invoker.input_jar_path |
- _output_jar_path = invoker.output_jar_path |
- _jar_toc_path = _output_jar_path + ".TOC" |
+ assert(defined(invoker.jar_path)) |
+ _base_path = "${target_gen_dir}/$target_name" |
+ _jar_path = _base_path + ".jar" |
+ _build_config = _base_path + ".build_config" |
- assert(invoker.build_config != "") |
+ if (_supports_android) { |
+ _dex_path = _base_path + ".dex.jar" |
+ } |
- if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) { |
- _proguard_jar_path = "$android_sdk_root/tools/proguard/lib/proguard.jar" |
- _proguard_config_path = invoker.proguard_config |
- _build_config = invoker.build_config |
- _rebased_build_config = rebase_path(_build_config, root_build_dir) |
- action("${target_name}__proguard_process") { |
- script = "//build/android/gyp/proguard.py" |
- inputs = [ |
- android_sdk_jar, |
- _proguard_jar_path, |
- _build_config, |
- _input_jar_path, |
- _proguard_config_path, |
- ] |
- depfile = "${target_gen_dir}/${target_name}.d" |
- outputs = [ |
- depfile, |
- _output_jar_path, |
- ] |
- args = [ |
- "--depfile", rebase_path(depfile, root_build_dir), |
- "--proguard-path", rebase_path(_proguard_jar_path, root_build_dir), |
- "--input-path", rebase_path(_input_jar_path, root_build_dir), |
- "--output-path", rebase_path(_output_jar_path, root_build_dir), |
- "--proguard-config", rebase_path(_proguard_config_path, root_build_dir), |
- "--classpath", rebased_android_sdk_jar, |
- "--classpath=@FileArg($_rebased_build_config:javac:classpath)", |
- ] |
+ _final_deps = [] |
+ _template_name = target_name |
+ |
+ |
+ _final_deps += [ ":${_template_name}__build_config" ] |
+ write_build_config("${_template_name}__build_config") { |
+ type = "java_library" |
+ supports_android = _supports_android |
+ requires_android = (defined(invoker.requires_android) && |
+ invoker.requires_android) |
+ |
+ deps = [] |
+ if (defined(invoker.deps)) { |
+ deps += invoker.deps |
} |
- } else { |
- copy("${target_name}__copy_jar") { |
- sources = [_input_jar_path] |
- outputs = [_output_jar_path] |
+ build_config = _build_config |
+ jar_path = _jar_path |
+ if (_supports_android) { |
+ dex_path = _dex_path |
} |
} |
- action("${target_name}__jar_toc") { |
- script = "//build/android/gyp/jar_toc.py" |
- depfile = "$target_gen_dir/$target_name.d" |
- outputs = [ |
- depfile, |
- _jar_toc_path, |
- _jar_toc_path + ".md5.stamp" |
- ] |
- inputs = [ _output_jar_path ] |
- args = [ |
- "--depfile", rebase_path(depfile, root_build_dir), |
- "--jar-path", rebase_path(_output_jar_path, root_build_dir), |
- "--toc-path", rebase_path(_jar_toc_path, root_build_dir), |
- ] |
+ _final_deps += [ ":${_template_name}__process_jar" ] |
+ process_java_prebuilt("${_template_name}__process_jar") { |
+ if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) { |
+ proguard_preprocess = true |
+ proguard_config = invoker.proguard_config |
+ } |
+ |
+ build_config = _build_config |
+ input_jar_path = invoker.jar_path |
+ output_jar_path = _jar_path |
+ } |
+ |
+ if (_supports_android) { |
+ _final_deps += [ ":${_template_name}__dex" ] |
+ dex("${_template_name}__dex") { |
+ sources = [_jar_path] |
+ output = _dex_path |
+ } |
} |
group(target_name) { |
- deps = [ |
- ":${target_name}__jar_toc" |
- ] |
+ deps = _final_deps |
} |
} |
+ |
# Compiles and jars a set of java files. |
# |
# Outputs: |
@@ -502,10 +596,20 @@ template("compile_java") { |
# Mark srcjar_deps as used. |
assert(_srcjar_deps == [] || true) |
- _system_jars = [ android_sdk_jar ] |
- action("${target_name}__javac") { |
+ _system_jars = [] |
+ if (defined(invoker.android) && invoker.android) { |
+ _system_jars += [ android_sdk_jar ] |
+ } |
+ |
+ _rebased_build_config = rebase_path(_build_config, root_build_dir) |
+ _rebased_jar_path = rebase_path(_intermediate_jar_path, root_build_dir) |
+ |
+ _template_name = target_name |
+ _final_deps = [ ":${_template_name}__javac" ] |
+ action("${_template_name}__javac") { |
script = "//build/android/gyp/javac.py" |
depfile = "$target_gen_dir/$target_name.d" |
+ deps = [] |
outputs = [ |
depfile, |
_intermediate_jar_path, |
@@ -516,9 +620,7 @@ template("compile_java") { |
_rebased_system_jars = rebase_path(_system_jars, root_build_dir) |
_rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir) |
- _rebased_build_config = rebase_path(_build_config, root_build_dir) |
_rebased_depfile = rebase_path(depfile, root_build_dir) |
- _rebased_jar_path = rebase_path(_intermediate_jar_path, root_build_dir) |
args = [ |
"--depfile=$_rebased_depfile", |
"--classpath=$_rebased_system_jars", |
@@ -529,13 +631,20 @@ template("compile_java") { |
"--jar-excluded-classes=$_jar_excluded_patterns", |
] |
if (_chromium_code) { |
- args += [ "--chromium-code" ] |
+ args += [ "--chromium-code=1" ] |
+ } |
+ |
+ if (defined(invoker.main_class)) { |
+ args += [ |
+ "--main-class", invoker.main_class |
+ ] |
} |
args += rebase_path(_java_files, root_build_dir) |
} |
- java_prebuilt("${target_name}__finish") { |
+ _final_deps += [ ":${_template_name}__finish" ] |
+ process_java_prebuilt("${_template_name}__finish") { |
build_config = _build_config |
input_jar_path = _intermediate_jar_path |
output_jar_path = _final_jar_path |
@@ -546,26 +655,68 @@ template("compile_java") { |
} |
group(target_name) { |
- deps = [ |
- ":${target_name}__javac", |
- ":${target_name}__finish", |
- ] |
+ deps = _final_deps |
} |
} |
-# This adds Android-specific parts to the java_library template. |
-# |
-# Runs Android lint against the compiled java files. |
-# Dexes the output jar for inclusion in an APK. |
-template("android_java_library") { |
+template("java_library_impl") { |
if (defined(invoker.testonly)) { testonly = invoker.testonly } |
assert(defined(invoker.java_files) || defined(invoker.DEPRECATED_java_in_dir) |
|| defined(invoker.srcjars) || defined(invoker.srcjar_deps)) |
- assert(defined(invoker.build_config)) |
- assert(defined(invoker.jar_path)) |
- assert(defined(invoker.dex_path)) |
+ _base_path = "$target_gen_dir/$target_name" |
+ _jar_path = _base_path + ".jar" |
+ if (defined(invoker.jar_path)) { |
+ _jar_path = invoker.jar_path |
+ } |
+ _template_name = target_name |
+ |
+ _final_deps = [] |
+ _final_datadeps = [] |
+ if (defined(invoker.datadeps)) { |
+ _final_datadeps = invoker.datadeps |
+ } |
+ |
+ _supports_android = (defined(invoker.supports_android) && |
+ invoker.supports_android) |
+ _requires_android = (defined(invoker.requires_android) && |
+ invoker.requires_android) |
+ |
+ if (_supports_android) { |
+ _dex_path = _base_path + ".dex.jar" |
+ if (defined(invoker.dex_path)) { |
+ _dex_path = invoker.dex_path |
+ } |
+ } |
+ |
+ if (defined(invoker.override_build_config)) { |
+ _build_config = invoker.override_build_config |
+ } else { |
+ _build_config = _base_path + ".build_config" |
+ _final_deps += [ ":${_template_name}__build_config" ] |
+ write_build_config("${_template_name}__build_config") { |
+ type = "java_library" |
+ supports_android = _supports_android |
+ requires_android = _requires_android |
+ |
+ deps = [] |
+ if (defined(invoker.deps)) { |
+ deps += invoker.deps |
+ } |
+ |
+ build_config = _build_config |
+ jar_path = _jar_path |
+ if (_supports_android) { |
+ dex_path = _dex_path |
+ } |
+ } |
+ } |
+ |
+ _chromium_code = true |
+ if (defined(invoker.chromium_code)) { |
+ _chromium_code = invoker.chromium_code |
+ } |
_srcjar_deps = [] |
if (defined(invoker.srcjar_deps)) { |
@@ -602,60 +753,74 @@ template("android_java_library") { |
} |
assert(_java_files != [] || _srcjar_deps != [] || _srcjars != []) |
- _jar_path = invoker.jar_path |
- _dex_path = invoker.dex_path |
- |
- _android_manifest = "//build/android/AndroidManifest.xml" |
- if (defined(invoker.android_manifest)) { |
- _android_manifest = invoker.android_manifest |
- } |
- assert(_android_manifest != "") |
- |
- _final_deps = [] |
- _final_datadeps = [] |
- |
- compile_java("${target_name}__compile_java") { |
+ _final_deps += [ ":${_template_name}__compile_java" ] |
+ compile_java("${_template_name}__compile_java") { |
jar_path = _jar_path |
- if (defined(invoker.jar_excluded_patterns)) { |
- jar_excluded_patterns = invoker.jar_excluded_patterns |
- } |
- build_config = invoker.build_config |
+ build_config = _build_config |
java_files = _java_files |
srcjar_deps = _srcjar_deps |
srcjars = _srcjars |
- |
- if (defined(invoker.proguard_preprocess) && invoker.proguard_preprocess) { |
- proguard_preprocess = invoker.proguard_preprocess |
- proguard_config = invoker.proguard_config |
- } |
- |
- if (defined(invoker.dist_jar_path)) { |
- dist_jar_path = invoker.dist_jar_path |
+ chromium_code = _chromium_code |
+ android = _requires_android |
+ |
+ if (defined(invoker.jar_excluded_patterns)) { jar_excluded_patterns = invoker.jar_excluded_patterns } |
+ if (defined(invoker.main_class)) { main_class = invoker.main_class } |
+ if (defined(invoker.proguard_preprocess)) { proguard_preprocess = invoker.proguard_preprocess } |
+ if (defined(invoker.proguard_config)) { proguard_config = invoker.proguard_config } |
+ if (defined(invoker.dist_jar_path)) { dist_jar_path = invoker.dist_jar_path } |
+ } |
+ |
+ if (defined(invoker.main_class)) { |
+ _final_deps += [ ":${_template_name}__binary_script" ] |
+ action("${_template_name}__binary_script") { |
+ script = "//build/android/gyp/create_java_binary_script.py" |
+ depfile = "$target_gen_dir/$target_name.d" |
+ java_script = "$root_build_dir/bin/$_template_name" |
+ inputs = [ _build_config ] |
+ outputs = [ |
+ depfile, |
+ java_script, |
+ ] |
+ _rebased_build_config = rebase_path(_build_config, root_build_dir) |
+ args = [ |
+ "--depfile", rebase_path(depfile, root_build_dir), |
+ "--output", rebase_path(java_script, root_build_dir), |
+ "--classpath=@FileArg($_rebased_build_config:java:full_classpath)", |
+ "--jar-path", rebase_path(_jar_path, root_build_dir), |
+ "--main-class", invoker.main_class, |
+ ] |
} |
} |
- if (defined(invoker.chromium_code) && invoker.chromium_code) { |
- _final_datadeps += [ ":${target_name}__lint" ] |
- android_lint("${target_name}__lint") { |
- android_manifest = _android_manifest |
- jar_path = _jar_path |
- java_files = _java_files |
+ if (_supports_android) { |
+ if (defined(invoker.chromium_code) && invoker.chromium_code) { |
+ _android_manifest = "//build/android/AndroidManifest.xml" |
+ if (defined(invoker.android_manifest)) { |
+ _android_manifest = invoker.android_manifest |
+ } |
+ |
+ _final_datadeps += [ ":${_template_name}__lint" ] |
+ android_lint("${_template_name}__lint") { |
+ android_manifest = _android_manifest |
+ jar_path = _jar_path |
+ java_files = _java_files |
+ } |
} |
- } |
- dex("${target_name}__dex") { |
- sources = [_jar_path] |
- output = _dex_path |
+ _final_deps += [ ":${_template_name}__dex" ] |
+ dex("${_template_name}__dex") { |
+ sources = [_jar_path] |
+ output = _dex_path |
+ } |
} |
group(target_name) { |
- deps = [ |
- ":${target_name}__compile_java", |
- ":${target_name}__dex", |
- ] + _final_deps + _final_datadeps |
+ deps = _final_deps |
+ datadeps = _final_datadeps |
} |
} |
+ |
# Runs process_resources.py |
template("process_resources") { |
if (defined(invoker.testonly)) { testonly = invoker.testonly } |