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.
5 import("//build/config/android/config.gni")
10 rebased_android_sdk = rebase_path(android_sdk, root_build_dir)
11 rebased_android_sdk_root = rebase_path(android_sdk_root, root_build_dir)
12 rebased_android_sdk_build_tools = rebase_path(android_sdk_build_tools, root_build_dir)
15 # Write the target's .build_config file. This is a json file that contains a
16 # dictionary of information about how to build this target (things that
17 # require knowledge about this target's dependencies and cannot be calculated
18 # at gn-time). There is a special syntax to add a value in that dictionary to
19 # an action/action_foreachs args:
20 # --python-arg=@FileArg($rebased_build_config_path:key0:key1)
21 # At runtime, such an arg will be replaced by the value in the build_config.
22 # See build/android/gyp/write_build_config.py and
23 # build/android/gyp/util/build_utils.py:ExpandFileArgs
24 template("write_build_config") {
25 assert(defined(invoker.type))
26 assert(defined(invoker.build_config))
29 build_config = invoker.build_config
31 assert(type == "android_apk" || type == "android_library" || type == "android_resources")
34 script = "//build/android/gyp/write_build_config.py"
35 depfile = "$target_gen_dir/$target_name.d"
38 if (defined(invoker.deps)) {
47 possible_deps_configs = []
49 dep_gen_dir = get_label_info(d, "target_gen_dir")
50 dep_name = get_label_info(d, "name")
51 possible_deps_configs += [ "$dep_gen_dir/$dep_name.build_config" ]
53 rebase_possible_deps_configs = rebase_path(possible_deps_configs)
57 "--depfile", rebase_path(depfile, root_build_dir),
58 "--possible-deps-configs=$rebase_possible_deps_configs",
59 "--build-config", rebase_path(build_config, root_build_dir),
62 if (type == "android_library" || type == "android_apk") {
64 "--jar-path", rebase_path(invoker.jar_path, root_build_dir),
65 "--dex-path", rebase_path(invoker.dex_path, root_build_dir),
69 if (type == "android_resources" || type == "android_apk") {
70 assert(defined(invoker.resources_zip))
72 "--resources-zip", rebase_path(invoker.resources_zip, root_build_dir),
76 if (defined(invoker.srcjar)) {
78 "--srcjar", rebase_path(invoker.srcjar, root_build_dir)
85 # Creates a zip archive of the inputs.
86 # If base_dir is provided, the archive paths will be relative to it.
88 assert(defined(invoker.inputs))
89 assert(defined(invoker.output))
91 rebase_inputs = rebase_path(invoker.inputs, root_build_dir)
92 rebase_output = rebase_path(invoker.output, root_build_dir)
94 script = "//build/android/gn/zip.py"
95 depfile = "$target_gen_dir/$target_name.d"
96 inputs = invoker.inputs
102 "--depfile", rebase_path(depfile, root_build_dir),
103 "--inputs=$rebase_inputs",
104 "--output=$rebase_output",
106 if (defined(invoker.base_dir)) {
108 "--base-dir", rebase_path(invoker.base_dir, root_build_dir)
115 assert(defined(invoker.sources))
116 assert(defined(invoker.output))
117 action(target_name) {
118 script = "//build/android/gyp/dex.py"
119 depfile = "$target_gen_dir/$target_name.d"
120 sources = invoker.sources
121 outputs = [depfile, invoker.output]
122 if (defined(invoker.inputs)) {
123 inputs = invoker.inputs
126 rebased_output = rebase_path(invoker.output, root_build_dir)
129 "--depfile", rebase_path(depfile, root_build_dir),
130 "--android-sdk-tools", rebased_android_sdk_build_tools,
131 "--dex-path", rebased_output,
134 if (defined(invoker.no_locals) && invoker.no_locals) {
140 if (defined(invoker.args)) {
144 args += rebase_path(invoker.sources, root_build_dir)
148 # Compiles and jars a set of java files.
155 # java_files: List of .java files to compile.
156 # java_deps: List of java dependencies. These should all have a .jar output
157 # at "${target_gen_dir}/${target_name}.jar.
158 # chromium_code: If 1, enable extra warnings.
159 # srcjar_deps: List of srcjar dependencies. The .java files contained in the
160 # dependencies srcjar outputs will be compiled and added to the output jar.
161 # jar_path: Use this to explicitly set the output jar path. Defaults to
162 # "${target_gen_dir}/${target_name}.jar.
163 template("java_library") {
164 assert(defined(invoker.java_files))
165 assert(defined(invoker.build_config))
166 assert(defined(invoker.jar_path))
168 java_files = invoker.java_files
169 jar_path = invoker.jar_path
170 jar_toc_path = jar_path + ".TOC"
172 build_config = invoker.build_config
174 jar_excluded_patterns = []
175 if (defined(invoker.jar_excluded_patterns)) {
176 jar_excluded_patterns += invoker.jar_excluded_patterns
179 chromium_code = false
180 if (defined(invoker.chromium_code)) {
181 chromium_code = chromium_code || invoker.chromium_code
185 if (defined(invoker.srcjar_deps)) {
186 srcjar_deps += invoker.srcjar_deps
190 foreach(dep, srcjar_deps) {
191 dep_gen_dir = get_label_info(dep, "target_gen_dir")
192 dep_name = get_label_info(dep, "name")
193 java_srcjars += [ "$dep_gen_dir/$dep_name.srcjar" ]
195 # Mark srcjar_deps as used.
196 assert(srcjar_deps == [] || srcjar_deps != [])
198 rebase_jar_path = rebase_path(jar_path, root_build_dir)
200 system_jars = [ "${android_sdk}/android.jar" ]
201 action("${target_name}__javac") {
202 script = "//build/android/gyp/javac.py"
203 depfile = "$target_gen_dir/$target_name.d"
207 jar_path + ".md5.stamp"
209 sources = java_files + java_srcjars
210 inputs = system_jars + [ build_config ]
212 rebase_system_jars = rebase_path(system_jars, root_build_dir)
213 rebase_java_srcjars = rebase_path(java_srcjars, root_build_dir)
214 rebase_build_config = rebase_path(build_config, root_build_dir)
215 rebase_depfile = rebase_path(depfile, root_build_dir)
217 "--depfile=$rebase_depfile",
218 "--classpath=$rebase_system_jars",
219 "--classpath=@FileArg($rebase_build_config:javac:classpath)",
220 "--jar-path=$rebase_jar_path",
221 "--java-srcjars=$rebase_java_srcjars",
222 "--java-srcjars=@FileArg($rebase_build_config:javac:srcjars)",
223 "--jar-excluded-classes=$jar_excluded_patterns",
226 args += [ "--chromium-code" ]
229 args += rebase_path(java_files, root_build_dir)
232 # TODO(cjhopman): proguard
234 rebase_jar_toc_path = rebase_path(jar_toc_path, root_build_dir)
235 action("${target_name}__jar_toc") {
236 script = "//build/android/gyp/jar_toc.py"
237 depfile = "$target_gen_dir/$target_name.d"
241 jar_toc_path + ".md5.stamp"
243 inputs = [ jar_path ]
245 "--depfile", rebase_path(depfile, root_build_dir),
246 "--jar-path=${rebase_jar_path}",
247 "--toc-path=${rebase_jar_toc_path}",
253 ":${target_name}__javac",
254 ":${target_name}__jar_toc",
260 # This adds Android-specific parts to the java_library template.
262 # Runs Android lint against the compiled java files.
263 # Dexes the output jar for inclusion in an APK.
264 template("android_java_library") {
265 assert(defined(invoker.java_files))
266 assert(defined(invoker.build_config))
267 assert(defined(invoker.jar_path))
268 assert(defined(invoker.dex_path))
270 _jar_path = invoker.jar_path
271 _dex_path = invoker.dex_path
273 java_library("${target_name}__java_library") {
275 if (defined(invoker.jar_excluded_patterns)) {
276 jar_excluded_patterns = invoker.jar_excluded_patterns
278 build_config = invoker.build_config
279 java_files = invoker.java_files
281 if (defined(invoker.srcjar_deps)) {
282 srcjar_deps = invoker.srcjar_deps
286 # TODO(cjhopman): lint
289 dex("${target_name}__dex") {
290 sources = [_jar_path]
296 ":${target_name}__java_library",
297 ":${target_name}__dex",
303 # Runs process_resources.py
304 template("process_resources") {
305 zip_path = invoker.zip_path
306 srcjar_path = invoker.srcjar_path
307 build_config = invoker.build_config
308 resource_dirs = invoker.resource_dirs
309 android_manifest = invoker.android_manifest
311 non_constant_id = true
312 if (defined(invoker.generate_constant_ids) && invoker.generate_constant_ids) {
313 non_constant_id = false
316 action(target_name) {
317 script = "//build/android/gyp/process_resources.py"
319 depfile = "$target_gen_dir/$target_name.d"
326 sources_build_rel = exec_script(
327 "//build/android/gyp/find.py",
328 rebase_path(resource_dirs, root_build_dir),
331 sources = rebase_path(sources_build_rel, ".", root_build_dir)
338 rebase_resource_dirs = rebase_path(resource_dirs, root_build_dir)
339 rebase_build_config = rebase_path(build_config, root_build_dir)
341 "--depfile", rebase_path(depfile, root_build_dir),
342 "--android-sdk", rebase_path(android_sdk, root_build_dir),
343 "--android-sdk-tools", rebase_path(android_sdk_build_tools, root_build_dir),
344 "--android-manifest", rebase_path(android_manifest, root_build_dir),
346 "--resource-dirs=$rebase_resource_dirs",
347 "--srcjar-out", rebase_path(srcjar_path, root_build_dir),
348 "--resource-zip-out", rebase_path(zip_path, root_build_dir),
350 "--dependencies-res-zips=@FileArg($rebase_build_config:resources:dependency_zips)",
353 if (non_constant_id) {
354 args += [ "--non-constant-id" ]
357 if (defined(invoker.custom_package)) {
359 "--custom-package", invoker.custom_package,
363 if (defined(invoker.v14_verify_only) && invoker.v14_verify_only) {
364 args += ["--v14-verify-only"]
367 if (defined(invoker.all_resources_zip_path)) {
368 all_resources_zip = invoker.all_resources_zip_path
369 outputs += [ all_resources_zip ]
371 "--all-resources-zip-out", rebase_path(all_resources_zip, root_build_dir)
375 if (defined(invoker.args)) {