blob: fdcbe576652a7438bd60734f59797f7e171c5215 [file] [log] [blame]
[email protected]65208a02012-04-17 04:39:521# Copyright (c) 2012 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# This file is meant to be included into a target to provide a rule
6# to build Java in a consistent manner.
7#
8# To use this, create a gyp target with the following form:
9# {
10# 'target_name': 'my-package_java',
11# 'type': 'none',
12# 'variables': {
[email protected]65208a02012-04-17 04:39:5213# 'java_in_dir': 'path/to/package/root',
14# },
15# 'includes': ['path/to/this/gypi/file'],
16# }
17#
[email protected]d54f19b2012-09-28 18:22:2918# Required variables:
[email protected]d54f19b2012-09-28 18:22:2919# java_in_dir - The top-level java directory. The src should be in
20# <java_in_dir>/src.
21# Optional/automatic variables:
22# additional_input_paths - These paths will be included in the 'inputs' list to
23# ensure that this target is rebuilt when one of these paths changes.
24# additional_src_dirs - Additional directories with .java files to be compiled
25# and included in the output of this target.
26# generated_src_dirs - Same as additional_src_dirs except used for .java files
27# that are generated at build time. This should be set automatically by a
28# target's dependencies. The .java files in these directories are not
29# included in the 'inputs' list (unlike additional_src_dirs).
30# input_jars_paths - The path to jars to be included in the classpath. This
31# should be filled automatically by depending on the appropriate targets.
[email protected]d339e3c2012-11-14 21:20:4732# javac_includes - A list of specific files to include. This is by default
[email protected]8b393472012-11-14 01:23:4033# empty, which leads to inclusion of all files specified. May include
34# wildcard, and supports '**/' for recursive path wildcards, ie.:
35# '**/MyFileRegardlessOfDirectory.java', '**/IncludedPrefix*.java'.
[email protected]3ac503672012-11-16 20:39:2036# has_java_resources - Set to 1 if the java target contains an
37# Android-compatible resources folder named res. If 1, R_package and
38# R_package_relpath must also be set.
39# R_package - The java package in which the R class (which maps resources to
40# integer IDs) should be generated, e.g. org.chromium.content.
41# R_package_relpath - Same as R_package, but replace each '.' with '/'.
[email protected]8f097c22013-01-16 17:54:4242# java_strings_grd - The name of the grd file from which to generate localized
43# strings.xml files, if any.
[email protected]7dc76812013-03-26 07:31:5744# res_extra_dirs - A list of extra directories containing Android resources.
45# These directories may be generated at build time.
46# res_extra_files - A list of the files in res_extra_dirs.
[email protected]65208a02012-04-17 04:39:5247
48{
[email protected]218b2f42012-09-19 18:19:1849 'dependencies': [
[email protected]225ec632013-04-03 18:20:2250 '<(DEPTH)/build/android/setup.gyp:build_output_dirs'
[email protected]218b2f42012-09-19 18:19:1851 ],
[email protected]efdbdb02012-08-09 18:08:1952 'variables': {
[email protected]2d401ff82013-03-23 18:38:3253 'android_jar': '<(android_sdk)/android.jar',
54 'input_jars_paths': [ '<(android_jar)' ],
[email protected]8bf6c172012-08-13 18:35:4955 'additional_src_dirs': [],
[email protected]8b393472012-11-14 01:23:4056 'javac_includes': [],
[email protected]37434b42013-02-20 22:39:1757 'jar_name': '<(_target_name).jar',
58 'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
[email protected]a934b412013-03-26 20:44:2959 'jar_excluded_classes': [ '*/R.class', '*/R##*.class' ],
[email protected]2d401ff82013-03-23 18:38:3260 'additional_input_paths': [],
[email protected]b13f73e2013-03-27 23:31:2761 'dex_path': '<(PRODUCT_DIR)/lib.java/<(_target_name).dex.jar',
[email protected]3ac503672012-11-16 20:39:2062 'generated_src_dirs': ['>@(generated_R_dirs)'],
63 'generated_R_dirs': [],
[email protected]3ac503672012-11-16 20:39:2064 'has_java_resources%': 0,
[email protected]8f097c22013-01-16 17:54:4265 'java_strings_grd%': '',
[email protected]7dc76812013-03-26 07:31:5766 'res_extra_dirs': [],
67 'res_extra_files': [],
68 'resource_input_paths': ['>@(res_extra_files)'],
[email protected]187017362013-03-16 16:25:2269 'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
70 'classes_dir': '<(intermediate_dir)/classes',
71 'compile_stamp': '<(intermediate_dir)/compile.stamp',
[email protected]efdbdb02012-08-09 18:08:1972 },
[email protected]37434b42013-02-20 22:39:1773 # This all_dependent_settings is used for java targets only. This will add the
74 # jar path to the classpath of dependent java targets.
75 'all_dependent_settings': {
76 'variables': {
77 'input_jars_paths': ['<(jar_path)'],
[email protected]b13f73e2013-03-27 23:31:2778 'library_dexed_jars_paths': ['<(dex_path)'],
[email protected]37434b42013-02-20 22:39:1779 },
80 },
[email protected]3ac503672012-11-16 20:39:2081 'conditions': [
82 ['has_java_resources == 1', {
83 'variables': {
[email protected]bfd82e22012-12-12 21:01:0884 'res_dir': '<(java_in_dir)/res',
[email protected]7dc76812013-03-26 07:31:5785 'res_crunched_dir': '<(intermediate_dir)/res_crunched',
86 'res_input_dirs': ['<(res_dir)', '<@(res_extra_dirs)'],
87 'resource_input_paths': ['<!@(find <(res_dir) -type f)'],
[email protected]187017362013-03-16 16:25:2288 'R_dir': '<(intermediate_dir)/java_R',
[email protected]94542cd2013-01-10 23:33:3889 'R_text_file': '<(R_dir)/R.txt',
[email protected]2d401ff82013-03-23 18:38:3290 'R_stamp': '<(intermediate_dir)/resources.stamp',
[email protected]3ac503672012-11-16 20:39:2091 'generated_src_dirs': ['<(R_dir)'],
[email protected]2d401ff82013-03-23 18:38:3292 'additional_input_paths': ['<(R_stamp)'],
[email protected]4f73ab5d2013-03-27 09:48:0393 'additional_res_dirs': [],
94 'dependencies_res_files': [],
[email protected]3ac503672012-11-16 20:39:2095 },
96 'all_dependent_settings': {
97 'variables': {
98 # Dependent jars include this target's R.java file via
[email protected]4f73ab5d2013-03-27 09:48:0399 # generated_R_dirs and include its resources via
100 # dependencies_res_files.
[email protected]3ac503672012-11-16 20:39:20101 'generated_R_dirs': ['<(R_dir)'],
[email protected]2d401ff82013-03-23 18:38:32102 'additional_input_paths': ['<(R_stamp)'],
[email protected]4f73ab5d2013-03-27 09:48:03103 'dependencies_res_files': ['<@(resource_input_paths)'],
[email protected]3ac503672012-11-16 20:39:20104
105 # Dependent APKs include this target's resources via
[email protected]7dc76812013-03-26 07:31:57106 # additional_res_dirs, additional_res_packages, and
107 # additional_R_text_files.
108 'additional_res_dirs': ['<(res_crunched_dir)', '<@(res_input_dirs)'],
[email protected]3ac503672012-11-16 20:39:20109 'additional_res_packages': ['<(R_package)'],
[email protected]7dc76812013-03-26 07:31:57110 'additional_R_text_files': ['<(R_text_file)'],
[email protected]3ac503672012-11-16 20:39:20111 },
112 },
[email protected]8f097c22013-01-16 17:54:42113 'conditions': [
114 ['java_strings_grd != ""', {
[email protected]2d401ff82013-03-23 18:38:32115 'variables': {
[email protected]7dc76812013-03-26 07:31:57116 'res_grit_dir': '<(intermediate_dir)/res_grit',
117 'res_input_dirs': ['<(res_grit_dir)'],
118 'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)',
119 'resource_input_paths': ['<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(res_grit_dir)" <(grit_grd_file))'],
[email protected]2d401ff82013-03-23 18:38:32120 },
[email protected]8f097c22013-01-16 17:54:42121 'actions': [
122 {
123 'action_name': 'generate_localized_strings_xml',
124 'variables': {
[email protected]7dc76812013-03-26 07:31:57125 'grit_additional_defines': ['-E', 'ANDROID_JAVA_TAGGED_ONLY=false'],
126 'grit_out_dir': '<(res_grit_dir)',
[email protected]8f097c22013-01-16 17:54:42127 # resource_ids is unneeded since we don't generate .h headers.
128 'grit_resource_ids': '',
129 },
130 'includes': ['../build/grit_action.gypi'],
131 },
132 ],
133 }],
134 ],
[email protected]3ac503672012-11-16 20:39:20135 'actions': [
[email protected]bfd82e22012-12-12 21:01:08136 # Generate R.java and crunch image resources.
[email protected]3ac503672012-11-16 20:39:20137 {
[email protected]bfd82e22012-12-12 21:01:08138 'action_name': 'process_resources',
[email protected]37434b42013-02-20 22:39:17139 'message': 'processing resources for <(_target_name)',
[email protected]2d401ff82013-03-23 18:38:32140 'variables': {
141 'android_manifest': '<(DEPTH)/build/android/AndroidManifest.xml',
[email protected]4f73ab5d2013-03-27 09:48:03142 # Include the dependencies' res dirs so that references to
143 # resources in dependencies can be resolved.
144 'all_res_dirs': ['<@(res_input_dirs)', '>@(additional_res_dirs)'],
[email protected]2d401ff82013-03-23 18:38:32145 },
[email protected]3ac503672012-11-16 20:39:20146 'inputs': [
[email protected]2f601632013-04-04 23:04:40147 '<(DEPTH)/build/android/gyp/util/build_utils.py',
148 '<(DEPTH)/build/android/gyp/process_resources.py',
[email protected]7dc76812013-03-26 07:31:57149 '>@(resource_input_paths)',
[email protected]4f73ab5d2013-03-27 09:48:03150 '>@(dependencies_res_files)',
[email protected]3ac503672012-11-16 20:39:20151 ],
152 'outputs': [
[email protected]2d401ff82013-03-23 18:38:32153 '<(R_stamp)',
[email protected]3ac503672012-11-16 20:39:20154 ],
155 'action': [
[email protected]2f601632013-04-04 23:04:40156 'python', '<(DEPTH)/build/android/gyp/process_resources.py',
[email protected]bfd82e22012-12-12 21:01:08157 '--android-sdk', '<(android_sdk)',
158 '--android-sdk-tools', '<(android_sdk_tools)',
[email protected]bfd82e22012-12-12 21:01:08159 '--R-dir', '<(R_dir)',
[email protected]4f73ab5d2013-03-27 09:48:03160 '--res-dirs', '>(all_res_dirs)',
[email protected]7dc76812013-03-26 07:31:57161 '--crunch-input-dir', '>(res_dir)',
162 '--crunch-output-dir', '<(res_crunched_dir)',
[email protected]2d401ff82013-03-23 18:38:32163 '--android-manifest', '<(android_manifest)',
164 '--non-constant-id',
165 '--custom-package', '<(R_package)',
166 '--stamp', '<(R_stamp)',
[email protected]a63d0d572013-03-06 00:36:41167
[email protected]7dc76812013-03-26 07:31:57168 # Add hash of inputs to the command line, so if inputs change
[email protected]a63d0d572013-03-06 00:36:41169 # (e.g. if a resource if removed), the command will be re-run.
170 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
[email protected]2d401ff82013-03-23 18:38:32171 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
[email protected]3ac503672012-11-16 20:39:20172 ],
173 },
174 ],
175 }],
176 ],
[email protected]65208a02012-04-17 04:39:52177 'actions': [
178 {
[email protected]187017362013-03-16 16:25:22179 'action_name': 'javac_<(_target_name)',
180 'message': 'Compiling <(_target_name) java sources',
181 'variables': {
182 'all_src_dirs': [
[email protected]a934b412013-03-26 20:44:29183 '>(java_in_dir)/src',
[email protected]187017362013-03-16 16:25:22184 '>@(additional_src_dirs)',
185 '>@(generated_src_dirs)',
186 ],
187 },
[email protected]65208a02012-04-17 04:39:52188 'inputs': [
[email protected]2f601632013-04-04 23:04:40189 '<(DEPTH)/build/android/gyp/util/build_utils.py',
[email protected]c3aae52a2013-04-04 09:35:50190 '<(DEPTH)/build/android/gyp/javac.py',
[email protected]d54f19b2012-09-28 18:22:29191 '>!@(find >(java_in_dir) >(additional_src_dirs) -name "*.java")',
[email protected]efdbdb02012-08-09 18:08:19192 '>@(input_jars_paths)',
[email protected]7ebed72c2012-09-22 01:21:32193 '>@(additional_input_paths)',
[email protected]65208a02012-04-17 04:39:52194 ],
195 'outputs': [
[email protected]187017362013-03-16 16:25:22196 '<(compile_stamp)',
197 ],
198 'action': [
[email protected]c3aae52a2013-04-04 09:35:50199 'python', '<(DEPTH)/build/android/gyp/javac.py',
[email protected]187017362013-03-16 16:25:22200 '--output-dir=<(classes_dir)',
201 '--classpath=>(input_jars_paths)',
202 '--src-dirs=>(all_src_dirs)',
203 '--javac-includes=<(javac_includes)',
[email protected]9ac32ff2013-04-01 23:52:40204 '--chromium-code=<(chromium_code)',
[email protected]187017362013-03-16 16:25:22205 '--stamp=<(compile_stamp)',
206
207 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
[email protected]ae550472013-03-18 17:23:18208 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
[email protected]187017362013-03-16 16:25:22209 ]
210 },
211 {
212 'action_name': 'jar_<(_target_name)',
213 'message': 'Creating <(_target_name) jar',
214 'inputs': [
[email protected]2f601632013-04-04 23:04:40215 '<(DEPTH)/build/android/gyp/util/build_utils.py',
[email protected]c3aae52a2013-04-04 09:35:50216 '<(DEPTH)/build/android/gyp/util/md5_check.py',
217 '<(DEPTH)/build/android/gyp/jar.py',
[email protected]187017362013-03-16 16:25:22218 '<(compile_stamp)',
219 ],
220 'outputs': [
[email protected]37434b42013-02-20 22:39:17221 '<(jar_path)',
[email protected]65208a02012-04-17 04:39:52222 ],
223 'action': [
[email protected]c3aae52a2013-04-04 09:35:50224 'python', '<(DEPTH)/build/android/gyp/jar.py',
[email protected]187017362013-03-16 16:25:22225 '--classes-dir=<(classes_dir)',
226 '--jar-path=<(jar_path)',
[email protected]a934b412013-03-26 20:44:29227 '--excluded-classes=<(jar_excluded_classes)',
[email protected]d54f19b2012-09-28 18:22:29228
[email protected]187017362013-03-16 16:25:22229 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
[email protected]ae550472013-03-18 17:23:18230 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
[email protected]65208a02012-04-17 04:39:52231 ]
232 },
[email protected]b13f73e2013-03-27 23:31:27233 {
[email protected]6117aaf2013-04-13 02:49:36234 'action_name': 'jar_toc_<(_target_name)',
235 'message': 'Creating <(_target_name) jar.TOC',
236 'inputs': [
237 '<(DEPTH)/build/android/gyp/util/build_utils.py',
238 '<(DEPTH)/build/android/gyp/util/md5_check.py',
239 '<(DEPTH)/build/android/gyp/jar_toc.py',
240 '<(jar_path)',
241 ],
242 'outputs': [
243 '<(jar_path).TOC',
244 ],
245 'action': [
246 'python', '<(DEPTH)/build/android/gyp/jar_toc.py',
247 '--jar-path=<(jar_path)',
248 '--toc-path=<(jar_path).TOC',
249
250 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
251 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
252 ]
253 },
254 {
[email protected]b13f73e2013-03-27 23:31:27255 'action_name': 'dex_<(_target_name)',
256 'message': 'Dexing <(_target_name) jar',
257 'inputs': [
[email protected]2f601632013-04-04 23:04:40258 '<(DEPTH)/build/android/gyp/util/build_utils.py',
[email protected]c3aae52a2013-04-04 09:35:50259 '<(DEPTH)/build/android/gyp/util/md5_check.py',
260 '<(DEPTH)/build/android/gyp/dex.py',
[email protected]b13f73e2013-03-27 23:31:27261 '<(jar_path)',
262 ],
263 'outputs': [
264 '<(dex_path)',
265 ],
266 'action': [
[email protected]c3aae52a2013-04-04 09:35:50267 'python', '<(DEPTH)/build/android/gyp/dex.py',
[email protected]b13f73e2013-03-27 23:31:27268 '--dex-path=<(dex_path)',
269 '--android-sdk-root=<(android_sdk_root)',
270
271 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
[email protected]c5f783b2013-03-29 15:51:39272 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
[email protected]b13f73e2013-03-27 23:31:27273
274 '<(jar_path)',
275 ]
276 },
277
[email protected]65208a02012-04-17 04:39:52278 ],
279}