Index: build/config/android/internal_rules.gni |
diff --git a/build/config/android/internal_rules.gni b/build/config/android/internal_rules.gni |
index a85fe996e52129bd22aa6b16a7610a4ec986874e..211bb20fcb7daa236172ab11f992c0aac247271f 100644 |
--- a/build/config/android/internal_rules.gni |
+++ b/build/config/android/internal_rules.gni |
@@ -1,3 +1,46 @@ |
+import("config.gni") |
+ |
+template("write_build_config") { |
+ assert(defined(invoker.type)) |
+ assert(defined(invoker.base_path)) |
+ |
+ base_path = invoker.base_path |
+ type = invoker.type |
+ build_config = base_path + ".build_config" |
+ |
+ assert(type == "android_library" || type == "android_binary") |
+ |
+ action(target_name) { |
+ script = "//build/android/gyp/write_build_config.py" |
+ depfile = "$target_gen_dir/$target_name.d" |
+ |
+ deps = [] |
+ if (defined(invoker.deps)) { |
+ deps += invoker.deps |
+ } |
+ |
+ outputs = [depfile, build_config] |
+ |
+ possible_deps_configs = [] |
+ foreach(d, deps) { |
+ possible_deps_configs += [get_label_info(d, "target_gen_dir") + "/" + get_label_info(d, "name") + ".build_config"] |
+ } |
+ rebase_possible_deps_configs = rebase_path(possible_deps_configs) |
+ args = [ |
+ "--type", type, |
+ "--depfile", rebase_path(depfile, root_build_dir), |
+ "--possible-deps-configs=$rebase_possible_deps_configs", |
+ "--build-config", rebase_path(build_config, root_build_dir), |
+ ] |
+ |
+ if (type == "android_library") { |
+ jar_path = base_path + ".jar" |
+ args += [ |
+ "--jar-path", rebase_path(jar_path, root_build_dir), |
+ ] |
+ } |
+ } |
+} |
# Creates a zip archive of the inputs. |
# If base_dir is provided, the archive paths will be relative to it. |
@@ -5,8 +48,8 @@ template("zip") { |
assert(defined(invoker.inputs)) |
assert(defined(invoker.output)) |
- rebase_inputs = rebase_path(invoker.inputs) |
- rebase_output = rebase_path(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" |
@@ -19,9 +62,147 @@ template("zip") { |
] |
if (defined(invoker.base_dir)) { |
args += [ |
- "--base-dir", rebase_path(invoker.base_dir) |
+ "--base-dir", rebase_path(invoker.base_dir, root_build_dir) |
] |
} |
} |
} |
+# Compiles and jars a set of java_files. |
+# |
+# Outputs: |
+# $jar_path.jar |
+# $jar_path.jar.TOC |
+# |
+# Variables |
+# java_files: List of .java files to compile. |
+# java_deps: List of java dependencies. These should all have a .jar output |
+# at "${target_gen_dir}/${target_name}.jar. |
+# chromium_code: If 1, enable extra warnings. |
+# srcjar_deps: List of srcjar dependencies. The .java files contained in the |
+# dependencies srcjar outputs will be compiled and added to the output jar. |
+# jar_path: Use this to explicitly set the output jar path. Defaults to |
+# "${target_gen_dir}/${target_name}.jar. |
+template("java_library") { |
+ assert(defined(invoker.java_files)) |
+ assert(defined(invoker.build_config)) |
+ assert(defined(invoker.jar_path)) |
+ |
+ java_files = invoker.java_files |
+ jar_path = invoker.jar_path |
+ jar_toc_path = jar_path + ".TOC" |
+ |
+ build_config = invoker.build_config |
+ |
+ jar_excluded_patterns = [] |
+ if (defined(invoker.jar_excluded_patterns)) { |
+ jar_excluded_patterns += invoker.jar_excluded_patterns |
+ } |
+ |
+ chromium_code = false |
+ if (defined(invoker.chromium_code)) { |
+ chromium_code = chromium_code || invoker.chromium_code |
+ } |
+ |
+ srcjar_deps = [] |
+ if (defined(invoker.srcjar_deps)) { |
+ srcjar_deps += invoker.srcjar_deps |
+ } |
+ |
+ java_srcjars = [] |
+ foreach(dep, srcjar_deps) { |
+ java_srcjars += [get_label_info(dep, "target_gen_dir") + "/" + get_label_info(dep, "name") + ".srcjar"] |
+ } |
+ |
+ # Mark srcjar_deps as used. |
+ assert(srcjar_deps == [] || srcjar_deps != []) |
+ |
+ |
+ rebase_jar_path = rebase_path(jar_path, root_build_dir) |
+ |
+ system_jars = ["${android_sdk}/android.jar"] |
+ action("${target_name}__javac") { |
+ script = "//build/android/gyp/javac.py" |
+ depfile = "$target_gen_dir/$target_name.d" |
+ outputs = [ |
+ depfile, |
+ jar_path, |
+ jar_path + ".md5.stamp" |
+ ] |
+ sources = java_files + java_srcjars |
+ source_prereqs = system_jars + [build_config] |
+ |
+ rebase_system_jars = rebase_path(system_jars, root_build_dir) |
+ rebase_java_srcjars = rebase_path(java_srcjars, root_build_dir) |
+ rebase_build_config = rebase_path(build_config, root_build_dir) |
+ rebase_depfile = rebase_path(depfile, root_build_dir) |
+ args = [ |
+ "--depfile=$rebase_depfile", |
+ "--classpath=$rebase_system_jars", |
+ "--classpath=@($rebase_build_config:javac:classpath)", |
+ "--jar-path=$rebase_jar_path", |
+ "--java-srcjars=$rebase_java_srcjars", |
+ "--jar-excluded-classes=$jar_excluded_patterns", |
+ ] |
+ if (chromium_code) { |
+ args += ["--chromium-code"] |
+ } |
+ |
+ args += rebase_path(java_files, root_build_dir) |
+ } |
+ |
+ # TODO(cjhopman): proguard |
+ |
+ rebase_jar_toc_path = rebase_path(jar_toc_path, root_build_dir) |
+ 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"] |
+ source_prereqs = [jar_path] |
+ args = [ |
+ "--depfile", rebase_path(depfile, root_build_dir), |
+ "--jar-path=${rebase_jar_path}", |
+ "--toc-path=${rebase_jar_toc_path}", |
+ ] |
+ } |
+ |
+ group(target_name) { |
+ deps = [ |
+ ":${target_name}__javac", |
+ ":${target_name}__jar_toc", |
+ ] |
+ } |
+} |
+ |
+# 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") { |
+ assert(defined(invoker.java_files)) |
+ |
+ assert(defined(invoker.build_config)) |
+ assert(defined(invoker.jar_path)) |
+ |
+ java_library("${target_name}__java_library") { |
+ if (defined(invoker.jar_excluded_patterns)) { |
+ jar_excluded_patterns = invoker.jar_excluded_patterns |
+ } |
+ build_config = invoker.build_config |
+ java_files = invoker.java_files |
+ jar_path = invoker.jar_path |
+ |
+ if (defined(invoker.srcjar_deps)) { |
+ srcjar_deps = invoker.srcjar_deps |
+ } |
+ } |
+ |
+ # TODO(cjhopman): lint |
+ # TODO(cjhopman): dex |
+ |
+ group(target_name) { |
+ deps = [ |
+ ":${target_name}__java_library" |
+ ] |
+ } |
+} |