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