- add sources.
[platform/framework/web/crosswalk.git] / src / build / java.gypi
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.
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': {
13 #     'java_in_dir': 'path/to/package/root',
14 #   },
15 #   'includes': ['path/to/this/gypi/file'],
16 # }
17 #
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 #  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.
32 #  javac_includes - A list of specific files to include. This is by default
33 #    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'.
36 #  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 '/'.
42 #  java_strings_grd - The name of the grd file from which to generate localized
43 #    strings.xml files, if any.
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
48 {
49   'dependencies': [
50     '<(DEPTH)/build/android/setup.gyp:build_output_dirs'
51   ],
52   'variables': {
53     'android_jar': '<(android_sdk)/android.jar',
54     'input_jars_paths': [ '<(android_jar)' ],
55     'additional_src_dirs': [],
56     'javac_includes': [],
57     'jar_name': '<(_target_name).jar',
58     'jar_dir': '<(PRODUCT_DIR)/lib.java',
59     'jar_path': '<(intermediate_dir)/<(jar_name)',
60     'jar_final_path': '<(jar_dir)/<(jar_name)',
61     'jar_excluded_classes': [ '*/R.class', '*/R##*.class' ],
62     'instr_stamp': '<(intermediate_dir)/instr.stamp',
63     'additional_input_paths': [],
64     'dex_path': '<(PRODUCT_DIR)/lib.java/<(_target_name).dex.jar',
65     'generated_src_dirs': ['>@(generated_R_dirs)'],
66     'generated_R_dirs': [],
67     'has_java_resources%': 0,
68     'java_strings_grd%': '',
69     'res_extra_dirs': [],
70     'res_extra_files': [],
71     'res_v14_verify_only%': 0,
72     'resource_input_paths': ['>@(res_extra_files)'],
73     'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
74     'classes_dir': '<(intermediate_dir)/classes',
75     'compile_stamp': '<(intermediate_dir)/compile.stamp',
76     'proguard_config%': '',
77     'proguard_preprocess%': '0',
78     'variables': {
79       'variables': {
80         'proguard_preprocess%': 0,
81         'emma_never_instrument%': 0,
82       },
83       'conditions': [
84         ['proguard_preprocess == 1', {
85           'javac_jar_path': '<(intermediate_dir)/<(_target_name).pre.jar'
86         }, {
87           'javac_jar_path': '<(jar_path)'
88         }],
89         ['chromium_code != 0 and emma_coverage != 0 and emma_never_instrument == 0', {
90           'emma_instrument': 1,
91         }, {
92           'emma_instrument': 0,
93         }],
94       ],
95     },
96     'emma_instrument': '<(emma_instrument)',
97     'javac_jar_path': '<(javac_jar_path)',
98   },
99   # This all_dependent_settings is used for java targets only. This will add the
100   # jar path to the classpath of dependent java targets.
101   'all_dependent_settings': {
102     'variables': {
103       'input_jars_paths': ['<(jar_final_path)'],
104       'library_dexed_jars_paths': ['<(dex_path)'],
105     },
106   },
107   'conditions': [
108     ['has_java_resources == 1', {
109       'variables': {
110         'res_dir': '<(java_in_dir)/res',
111         'res_crunched_dir': '<(intermediate_dir)/res_crunched',
112         'res_v14_compatibility_stamp': '<(intermediate_dir)/res_v14_compatibility.stamp',
113         'res_v14_compatibility_dir': '<(intermediate_dir)/res_v14_compatibility',
114         'res_input_dirs': ['<(res_dir)', '<@(res_extra_dirs)'],
115         'resource_input_paths': ['<!@(find <(res_dir) -type f)'],
116         'R_dir': '<(intermediate_dir)/java_R',
117         'R_text_file': '<(R_dir)/R.txt',
118         'R_stamp': '<(intermediate_dir)/resources.stamp',
119         'generated_src_dirs': ['<(R_dir)'],
120         'additional_input_paths': ['<(R_stamp)',
121                                    '<(res_v14_compatibility_stamp)',],
122         'additional_res_dirs': [],
123         'dependencies_res_input_dirs': [],
124         'dependencies_res_files': [],
125       },
126       'all_dependent_settings': {
127         'variables': {
128           # Dependent jars include this target's R.java file via
129           # generated_R_dirs and include its resources via
130           # dependencies_res_files.
131           'generated_R_dirs': ['<(R_dir)'],
132           'additional_input_paths': ['<(R_stamp)',
133                                      '<(res_v14_compatibility_stamp)',],
134           'dependencies_res_files': ['<@(resource_input_paths)'],
135
136           'dependencies_res_input_dirs': ['<@(res_input_dirs)'],
137
138           # Dependent APKs include this target's resources via
139           # additional_res_dirs, additional_res_packages, and
140           # additional_R_text_files.
141           'additional_res_dirs': ['<(res_crunched_dir)',
142                                   '<(res_v14_compatibility_dir)',
143                                   '<@(res_input_dirs)'],
144           'additional_res_packages': ['<(R_package)'],
145           'additional_R_text_files': ['<(R_text_file)'],
146         },
147       },
148       'conditions': [
149         ['java_strings_grd != ""', {
150           'variables': {
151             'res_grit_dir': '<(intermediate_dir)/res_grit',
152             'res_input_dirs': ['<(res_grit_dir)'],
153             'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)',
154             'resource_input_paths': ['<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(res_grit_dir)" <(grit_grd_file))'],
155           },
156           'actions': [
157             {
158               'action_name': 'generate_localized_strings_xml',
159               'variables': {
160                 'grit_additional_defines': ['-E', 'ANDROID_JAVA_TAGGED_ONLY=false'],
161                 'grit_out_dir': '<(res_grit_dir)',
162                 # resource_ids is unneeded since we don't generate .h headers.
163                 'grit_resource_ids': '',
164               },
165               'includes': ['../build/grit_action.gypi'],
166             },
167           ],
168         }],
169       ],
170       'actions': [
171         # Generate R.java and crunch image resources.
172         {
173           'action_name': 'process_resources',
174           'message': 'processing resources for <(_target_name)',
175           'variables': {
176             'android_manifest': '<(DEPTH)/build/android/AndroidManifest.xml',
177             # Include the dependencies' res dirs so that references to
178             # resources in dependencies can be resolved.
179             'all_res_dirs': ['<@(res_input_dirs)',
180                              '>@(dependencies_res_input_dirs)',],
181             # Write the inputs list to a file, so that the action command
182             # line won't exceed the OS limits when calculating the checksum
183             # of the list.
184             'inputs_list_file': '>|(inputs_list.<(_target_name).gypcmd >@(_inputs))'
185           },
186           'inputs': [
187             '<(DEPTH)/build/android/gyp/util/build_utils.py',
188             '<(DEPTH)/build/android/gyp/process_resources.py',
189             '>@(resource_input_paths)',
190             '>@(dependencies_res_files)',
191           ],
192           'outputs': [
193             '<(R_stamp)',
194           ],
195           'action': [
196             'python', '<(DEPTH)/build/android/gyp/process_resources.py',
197             '--android-sdk', '<(android_sdk)',
198             '--android-sdk-tools', '<(android_sdk_tools)',
199             '--R-dir', '<(R_dir)',
200             '--res-dirs', '>(all_res_dirs)',
201             '--crunch-input-dir', '>(res_dir)',
202             '--crunch-output-dir', '<(res_crunched_dir)',
203             '--android-manifest', '<(android_manifest)',
204             '--non-constant-id',
205             '--custom-package', '<(R_package)',
206             '--stamp', '<(R_stamp)',
207
208             # Add hash of inputs to the command line, so if inputs change
209             # (e.g. if a resource if removed), the command will be re-run.
210             # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
211             '--ignore=>!(md5sum >(inputs_list_file))',
212           ],
213         },
214         # Generate API 14 resources.
215         {
216           'action_name': 'generate_api_14_resources_<(_target_name)',
217           'message': 'Generating Android API 14 resources <(_target_name)',
218           'variables' : {
219             'res_v14_additional_options': [],
220           },
221           'conditions': [
222             ['res_v14_verify_only == 1', {
223               'variables': {
224                 'res_v14_additional_options': ['--verify-only']
225               },
226             }],
227           ],
228           'inputs': [
229             '<(DEPTH)/build/android/gyp/util/build_utils.py',
230             '<(DEPTH)/build/android/gyp/generate_v14_compatible_resources.py',
231             '>@(resource_input_paths)',
232           ],
233           'outputs': [
234             '<(res_v14_compatibility_stamp)',
235           ],
236           'action': [
237             'python', '<(DEPTH)/build/android/gyp/generate_v14_compatible_resources.py',
238             '--res-dir=<(res_dir)',
239             '--res-v14-compatibility-dir=<(res_v14_compatibility_dir)',
240             '--stamp', '<(res_v14_compatibility_stamp)',
241             '<@(res_v14_additional_options)',
242           ]
243         },
244       ],
245     }],
246     ['proguard_preprocess == 1', {
247       'actions': [
248         {
249           'action_name': 'proguard_<(_target_name)',
250           'message': 'Proguard preprocessing <(_target_name) jar',
251           'inputs': [
252             '<(android_sdk_root)/tools/proguard/bin/proguard.sh',
253             '<(DEPTH)/build/android/gyp/util/build_utils.py',
254             '<(DEPTH)/build/android/gyp/proguard.py',
255             '<(javac_jar_path)',
256             '<(proguard_config)',
257           ],
258           'outputs': [
259             '<(jar_path)',
260           ],
261           'action': [
262             'python', '<(DEPTH)/build/android/gyp/proguard.py',
263             '--proguard-path=<(android_sdk_root)/tools/proguard/bin/proguard.sh',
264             '--input-path=<(javac_jar_path)',
265             '--output-path=<(jar_path)',
266             '--proguard-config=<(proguard_config)',
267             '--classpath=<(android_sdk_jar) >(input_jars_paths)',
268
269             # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
270             '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
271           ]
272         },
273       ],
274     }],
275   ],
276   'actions': [
277     {
278       'action_name': 'javac_<(_target_name)',
279       'message': 'Compiling <(_target_name) java sources',
280       'variables': {
281         'all_src_dirs': [
282           '>(java_in_dir)/src',
283           '>@(additional_src_dirs)',
284           '>@(generated_src_dirs)',
285         ],
286       },
287       'inputs': [
288         '<(DEPTH)/build/android/gyp/util/build_utils.py',
289         '<(DEPTH)/build/android/gyp/javac.py',
290         '>!@(find >(java_in_dir)/src >(additional_src_dirs) -name "*.java")',
291         '>@(input_jars_paths)',
292         '>@(additional_input_paths)',
293       ],
294       'outputs': [
295         '<(compile_stamp)',
296       ],
297       'action': [
298         'python', '<(DEPTH)/build/android/gyp/javac.py',
299         '--output-dir=<(classes_dir)',
300         '--classpath=>(input_jars_paths)',
301         '--src-dirs=>(all_src_dirs)',
302         '--javac-includes=<(javac_includes)',
303         '--chromium-code=<(chromium_code)',
304         '--stamp=<(compile_stamp)',
305
306         # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
307         '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
308       ]
309     },
310     {
311       'action_name': 'jar_<(_target_name)',
312       'message': 'Creating <(_target_name) jar',
313       'inputs': [
314         '<(DEPTH)/build/android/gyp/util/build_utils.py',
315         '<(DEPTH)/build/android/gyp/util/md5_check.py',
316         '<(DEPTH)/build/android/gyp/jar.py',
317         '<(compile_stamp)',
318       ],
319       'outputs': [
320         '<(javac_jar_path)',
321       ],
322       'action': [
323         'python', '<(DEPTH)/build/android/gyp/jar.py',
324         '--classes-dir=<(classes_dir)',
325         '--jar-path=<(javac_jar_path)',
326         '--excluded-classes=<(jar_excluded_classes)',
327
328         # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
329         '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
330       ]
331     },
332     {
333       'action_name': 'instr_jar_<(_target_name)',
334       'message': 'Instrumenting <(_target_name) jar',
335       'variables': {
336         'input_path': '<(jar_path)',
337         'output_path': '<(jar_final_path)',
338         'stamp_path': '<(instr_stamp)',
339         'instr_type': 'jar',
340       },
341       'outputs': [
342         '<(jar_final_path)',
343       ],
344       'inputs': [
345         '<(jar_path)',
346       ],
347       'includes': [ 'android/instr_action.gypi' ],
348     },
349     {
350       'action_name': 'jar_toc_<(_target_name)',
351       'message': 'Creating <(_target_name) jar.TOC',
352       'inputs': [
353         '<(DEPTH)/build/android/gyp/util/build_utils.py',
354         '<(DEPTH)/build/android/gyp/util/md5_check.py',
355         '<(DEPTH)/build/android/gyp/jar_toc.py',
356         '<(jar_final_path)',
357       ],
358       'outputs': [
359         '<(jar_final_path).TOC',
360       ],
361       'action': [
362         'python', '<(DEPTH)/build/android/gyp/jar_toc.py',
363         '--jar-path=<(jar_final_path)',
364         '--toc-path=<(jar_final_path).TOC',
365
366         # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
367         '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
368       ]
369     },
370     {
371       'action_name': 'dex_<(_target_name)',
372       'variables': {
373         'conditions': [
374           ['emma_instrument != 0', {
375             'dex_no_locals': 1,
376           }],
377         ],
378         'dex_input_paths': [ '<(jar_final_path)' ],
379         'output_path': '<(dex_path)',
380       },
381       'includes': [ 'android/dex_action.gypi' ],
382     },
383   ],
384 }