Fix spelling and remove bogus formatting from README.chromium
[chromium-blink-merge.git] / build / java.gypi
blobaf0bf0ea224453308413bb00ccc08b7391474cb5
1 # 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.
5 # This file is meant to be included into a target to provide a rule
6 # to build Java in a consistent manner.
8 # To use this, create a gyp target with the following form:
9 # {
10 #   'target_name': 'my-package_java',
11 #   'type': 'none',
12 #   'variables': {
13 #     'java_in_dir': 'path/to/package/root',
14 #   },
15 #   'includes': ['path/to/this/gypi/file'],
16 # }
18 # Required variables:
19 #  java_in_dir - The top-level java directory. The src should be in
20 #    <java_in_dir>/src.
21 # Optional/automatic variables:
22 #  add_to_dependents_classpaths - Set to 0 if the resulting jar file should not
23 #    be added to its dependents' classpaths.
24 #  additional_input_paths - These paths will be included in the 'inputs' list to
25 #    ensure that this target is rebuilt when one of these paths changes.
26 #  additional_src_dirs - Additional directories with .java files to be compiled
27 #    and included in the output of this target.
28 #  generated_src_dirs - Same as additional_src_dirs except used for .java files
29 #    that are generated at build time. This should be set automatically by a
30 #    target's dependencies. The .java files in these directories are not
31 #    included in the 'inputs' list (unlike additional_src_dirs).
32 #  input_jars_paths - The path to jars to be included in the classpath. This
33 #    should be filled automatically by depending on the appropriate targets.
34 #  javac_includes - A list of specific files to include. This is by default
35 #    empty, which leads to inclusion of all files specified. May include
36 #    wildcard, and supports '**/' for recursive path wildcards, ie.:
37 #    '**/MyFileRegardlessOfDirectory.java', '**/IncludedPrefix*.java'.
38 #  has_java_resources - Set to 1 if the java target contains an
39 #    Android-compatible resources folder named res.  If 1, R_package and
40 #    R_package_relpath must also be set.
41 #  R_package - The java package in which the R class (which maps resources to
42 #    integer IDs) should be generated, e.g. org.chromium.content.
43 #  R_package_relpath - Same as R_package, but replace each '.' with '/'.
44 #  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.
47 #  never_lint - Set to 1 to not run lint on this target.
50   'dependencies': [
51     '<(DEPTH)/build/android/setup.gyp:build_output_dirs'
52   ],
53   'variables': {
54     'add_to_dependents_classpaths%': 1,
55     'android_jar': '<(android_sdk)/android.jar',
56     'input_jars_paths': [ '<(android_jar)' ],
57     'additional_src_dirs': [],
58     'javac_includes': [],
59     'jar_name': '<(_target_name).jar',
60     'jar_dir': '<(PRODUCT_DIR)/lib.java',
61     'jar_path': '<(intermediate_dir)/<(jar_name)',
62     'jar_final_path': '<(jar_dir)/<(jar_name)',
63     'jar_excluded_classes': [ '*/R.class', '*/R##*.class' ],
64     'instr_stamp': '<(intermediate_dir)/instr.stamp',
65     'additional_input_paths': [],
66     'dex_path': '<(PRODUCT_DIR)/lib.java/<(_target_name).dex.jar',
67     'generated_src_dirs': ['>@(generated_R_dirs)'],
68     'generated_R_dirs': [],
69     'has_java_resources%': 0,
70     'res_extra_dirs': [],
71     'res_extra_files': [],
72     'res_v14_verify_only%': 0,
73     'resource_input_paths': ['>@(res_extra_files)'],
74     'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
75     'compile_stamp': '<(intermediate_dir)/compile.stamp',
76     'lint_stamp': '<(intermediate_dir)/lint.stamp',
77     'lint_result': '<(intermediate_dir)/lint_result.xml',
78     'lint_config': '<(intermediate_dir)/lint_config.xml',
79     'never_lint%': 0,
80     'proguard_config%': '',
81     'proguard_preprocess%': '0',
82     'variables': {
83       'variables': {
84         'proguard_preprocess%': 0,
85         'emma_never_instrument%': 0,
86       },
87       'conditions': [
88         ['proguard_preprocess == 1', {
89           'javac_jar_path': '<(intermediate_dir)/<(_target_name).pre.jar'
90         }, {
91           'javac_jar_path': '<(jar_path)'
92         }],
93         ['chromium_code != 0 and emma_coverage != 0 and emma_never_instrument == 0', {
94           'emma_instrument': 1,
95         }, {
96           'emma_instrument': 0,
97         }],
98       ],
99     },
100     'emma_instrument': '<(emma_instrument)',
101     'javac_jar_path': '<(javac_jar_path)',
102   },
103   'conditions': [
104     ['add_to_dependents_classpaths == 1', {
105       # This all_dependent_settings is used for java targets only. This will add the
106       # jar path to the classpath of dependent java targets.
107       'all_dependent_settings': {
108         'variables': {
109           'input_jars_paths': ['<(jar_final_path)'],
110           'library_dexed_jars_paths': ['<(dex_path)'],
111         },
112       },
113     }],
114     ['has_java_resources == 1', {
115       'variables': {
116         'res_dir': '<(java_in_dir)/res',
117         'res_input_dirs': ['<(res_dir)', '<@(res_extra_dirs)'],
118         'resource_input_paths': ['<!@(find <(res_dir) -type f)'],
120         'R_dir': '<(intermediate_dir)/java_R',
121         'R_text_file': '<(R_dir)/R.txt',
123         'generated_src_dirs': ['<(R_dir)'],
124         'additional_input_paths': ['<(resource_zip_path)', ],
126         'dependencies_res_zip_paths': [],
127         'resource_zip_path': '<(PRODUCT_DIR)/res.java/<(_target_name).zip',
128       },
129       'all_dependent_settings': {
130         'variables': {
131           # Dependent libraries include this target's R.java file via
132           # generated_R_dirs.
133           'generated_R_dirs': ['<(R_dir)'],
135           # Dependent libraries and apks include this target's resources via
136           # dependencies_res_zip_paths.
137           'additional_input_paths': ['<(resource_zip_path)'],
138           'dependencies_res_zip_paths': ['<(resource_zip_path)'],
140           # additional_res_packages and additional_R_text_files are used to
141           # create this packages R.java files when building the APK.
142           'additional_res_packages': ['<(R_package)'],
143           'additional_R_text_files': ['<(R_text_file)'],
144         },
145       },
146       'actions': [
147         # Generate R.java and crunch image resources.
148         {
149           'action_name': 'process_resources',
150           'message': 'processing resources for <(_target_name)',
151           'variables': {
152             'android_manifest': '<(DEPTH)/build/android/AndroidManifest.xml',
153             # Write the inputs list to a file, so that its mtime is updated when
154             # the list of inputs changes.
155             'inputs_list_file': '>|(java_resources.<(_target_name).gypcmd >@(resource_input_paths))',
156             'process_resources_options': [],
157             'conditions': [
158               ['res_v14_verify_only == 1', {
159                 'process_resources_options': ['--v14-verify-only']
160               }],
161             ],
162           },
163           'inputs': [
164             '<(DEPTH)/build/android/gyp/util/build_utils.py',
165             '<(DEPTH)/build/android/gyp/process_resources.py',
166             '<(DEPTH)/build/android/gyp/generate_v14_compatible_resources.py',
167             '>@(resource_input_paths)',
168             '>@(dependencies_res_zip_paths)',
169             '>(inputs_list_file)',
170           ],
171           'outputs': [
172             '<(resource_zip_path)',
173           ],
174           'action': [
175             'python', '<(DEPTH)/build/android/gyp/process_resources.py',
176             '--android-sdk', '<(android_sdk)',
177             '--android-sdk-tools', '<(android_sdk_tools)',
178             '--non-constant-id',
180             '--android-manifest', '<(android_manifest)',
181             '--custom-package', '<(R_package)',
183             '--dependencies-res-zips', '>(dependencies_res_zip_paths)',
184             '--resource-dirs', '<(res_input_dirs)',
186             '--R-dir', '<(R_dir)',
187             '--resource-zip-out', '<(resource_zip_path)',
189             '<@(process_resources_options)',
190           ],
191         },
192       ],
193     }],
194     ['proguard_preprocess == 1', {
195       'actions': [
196         {
197           'action_name': 'proguard_<(_target_name)',
198           'message': 'Proguard preprocessing <(_target_name) jar',
199           'inputs': [
200             '<(android_sdk_root)/tools/proguard/lib/proguard.jar',
201             '<(DEPTH)/build/android/gyp/util/build_utils.py',
202             '<(DEPTH)/build/android/gyp/proguard.py',
203             '<(javac_jar_path)',
204             '<(proguard_config)',
205           ],
206           'outputs': [
207             '<(jar_path)',
208           ],
209           'action': [
210             'python', '<(DEPTH)/build/android/gyp/proguard.py',
211             '--proguard-path=<(android_sdk_root)/tools/proguard/lib/proguard.jar',
212             '--input-path=<(javac_jar_path)',
213             '--output-path=<(jar_path)',
214             '--proguard-config=<(proguard_config)',
215             '--classpath=<(android_sdk_jar) >(input_jars_paths)',
216           ]
217         },
218       ],
219     }],
220   ],
221   'actions': [
222     {
223       'action_name': 'javac_<(_target_name)',
224       'message': 'Compiling <(_target_name) java sources',
225       'variables': {
226         'java_sources': ['>!@(find >(java_in_dir)/src >(additional_src_dirs) -name "*.java")'],
227       },
228       'inputs': [
229         '<(DEPTH)/build/android/gyp/util/build_utils.py',
230         '<(DEPTH)/build/android/gyp/javac.py',
231         '>@(java_sources)',
232         '>@(input_jars_paths)',
233         '>@(additional_input_paths)',
234       ],
235       'outputs': [
236         '<(compile_stamp)',
237         '<(javac_jar_path)',
238       ],
239       'action': [
240         'python', '<(DEPTH)/build/android/gyp/javac.py',
241         '--classpath=>(input_jars_paths)',
242         '--src-gendirs=>(generated_src_dirs)',
243         '--javac-includes=<(javac_includes)',
244         '--chromium-code=<(chromium_code)',
245         '--jar-path=<(javac_jar_path)',
246         '--jar-excluded-classes=<(jar_excluded_classes)',
247         '--stamp=<(compile_stamp)',
248         '>@(java_sources)',
249       ]
250     },
251     {
252       'action_name': 'instr_jar_<(_target_name)',
253       'message': 'Instrumenting <(_target_name) jar',
254       'variables': {
255         'input_path': '<(jar_path)',
256         'output_path': '<(jar_final_path)',
257         'stamp_path': '<(instr_stamp)',
258         'instr_type': 'jar',
259       },
260       'outputs': [
261         '<(jar_final_path)',
262       ],
263       'inputs': [
264         '<(jar_path)',
265       ],
266       'includes': [ 'android/instr_action.gypi' ],
267     },
268     {
269       'variables': {
270         'src_dirs': [
271           '<(java_in_dir)/src',
272           '>@(additional_src_dirs)',
273         ],
274         'stamp_path': '<(lint_stamp)',
275         'result_path': '<(lint_result)',
276         'config_path': '<(lint_config)',
277         'lint_jar_path': '<(jar_final_path)',
278       },
279       'inputs': [
280         '<(jar_final_path)',
281         '<(compile_stamp)',
282       ],
283       'outputs': [
284         '<(lint_stamp)',
285       ],
286       'includes': [ 'android/lint_action.gypi' ],
287     },
288     {
289       'action_name': 'jar_toc_<(_target_name)',
290       'message': 'Creating <(_target_name) jar.TOC',
291       'inputs': [
292         '<(DEPTH)/build/android/gyp/util/build_utils.py',
293         '<(DEPTH)/build/android/gyp/util/md5_check.py',
294         '<(DEPTH)/build/android/gyp/jar_toc.py',
295         '<(jar_final_path)',
296       ],
297       'outputs': [
298         '<(jar_final_path).TOC',
299       ],
300       'action': [
301         'python', '<(DEPTH)/build/android/gyp/jar_toc.py',
302         '--jar-path=<(jar_final_path)',
303         '--toc-path=<(jar_final_path).TOC',
304       ]
305     },
306     {
307       'action_name': 'dex_<(_target_name)',
308       'variables': {
309         'conditions': [
310           ['emma_instrument != 0', {
311             'dex_no_locals': 1,
312           }],
313         ],
314         'dex_input_paths': [ '<(jar_final_path)' ],
315         'output_path': '<(dex_path)',
316       },
317       'includes': [ 'android/dex_action.gypi' ],
318     },
319   ],