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:
10 # 'target_name': 'my-package_java',
13 # 'java_in_dir': 'path/to/package/root',
15 # 'includes': ['path/to/this/gypi/file'],
19 # java_in_dir - The top-level java directory. The src should be in
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.
47 '<(DEPTH)/build/build_output_dirs_android.gyp:build_output_dirs'
50 'input_jars_paths': [ '<(android_sdk_jar)' ],
51 'additional_src_dirs': [],
53 'jar_name': '<(_target_name).jar',
54 'jar_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)',
55 'excluded_classes': [ '*/R.class', '*/R##*.class' ],
56 'additional_input_paths': ['>@(additional_R_files)'],
57 'generated_src_dirs': ['>@(generated_R_dirs)'],
58 'generated_R_dirs': [],
59 'additional_R_files': [],
60 'has_java_resources%': 0,
61 'java_strings_grd%': '',
62 'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)',
63 'classes_dir': '<(intermediate_dir)/classes',
64 'compile_stamp': '<(intermediate_dir)/compile.stamp',
66 # This all_dependent_settings is used for java targets only. This will add the
67 # jar path to the classpath of dependent java targets.
68 'all_dependent_settings': {
70 'input_jars_paths': ['<(jar_path)'],
74 ['has_java_resources == 1', {
76 'res_dir': '<(java_in_dir)/res',
77 'out_res_dir': '<(intermediate_dir)/res',
78 'R_dir': '<(intermediate_dir)/java_R',
79 'R_file': '<(R_dir)/<(R_package_relpath)/R.java',
80 'R_text_file': '<(R_dir)/R.txt',
81 'generated_src_dirs': ['<(R_dir)'],
82 'additional_input_paths': ['<(R_file)'],
83 # grit_grd_file is used by grit_action.gypi, included below.
84 'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)',
86 'all_dependent_settings': {
88 # Dependent jars include this target's R.java file via
89 # generated_R_dirs and additional_R_files.
90 'generated_R_dirs': ['<(R_dir)'],
91 'additional_R_files': ['<(R_file)'],
92 'additional_R_text_files': ['<(R_text_file)'],
94 # Dependent APKs include this target's resources via
95 # additional_res_dirs and additional_res_packages.
96 'additional_res_dirs': ['<(out_res_dir)', '<(res_dir)'],
97 'additional_res_packages': ['<(R_package)'],
101 ['java_strings_grd != ""', {
104 'action_name': 'generate_localized_strings_xml',
106 'grit_out_dir': '<(out_res_dir)',
107 # resource_ids is unneeded since we don't generate .h headers.
108 'grit_resource_ids': '',
110 'includes': ['../build/grit_action.gypi'],
116 # Generate R.java and crunch image resources.
118 'action_name': 'process_resources',
119 'message': 'processing resources for <(_target_name)',
121 ['java_strings_grd != ""', {
123 # TODO(newt): replace this with .../values/strings.xml once
124 # the English strings.xml is generated as well? That would be
125 # simpler and faster and should be equivalent.
126 '<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(out_res_dir)" <(grit_grd_file))',
131 '<(DEPTH)/build/android/process_resources.py',
132 '<!@(find <(res_dir) -type f)',
138 '<(DEPTH)/build/android/process_resources.py',
139 '--android-sdk', '<(android_sdk)',
140 '--android-sdk-tools', '<(android_sdk_tools)',
141 '--R-package', '<(R_package)',
142 '--R-dir', '<(R_dir)',
143 '--res-dir', '<(res_dir)',
144 '--out-res-dir', '<(out_res_dir)',
146 # Add list of inputs to the command line, so if inputs change
147 # (e.g. if a resource if removed), the command will be re-run.
148 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja.
149 '--ignore', '>(_inputs)',
157 'action_name': 'javac_<(_target_name)',
158 'message': 'Compiling <(_target_name) java sources',
161 '>@(java_in_dir)/src',
162 '>@(additional_src_dirs)',
163 '>@(generated_src_dirs)',
167 '<(DEPTH)/build/android/pylib/build_utils.py',
168 '<(DEPTH)/build/android/javac.py',
169 '>!@(find >(java_in_dir) >(additional_src_dirs) -name "*.java")',
170 '>@(input_jars_paths)',
171 '>@(additional_input_paths)',
177 'python', '<(DEPTH)/build/android/javac.py',
178 '--output-dir=<(classes_dir)',
179 '--classpath=>(input_jars_paths)',
180 '--src-dirs=>(all_src_dirs)',
181 '--javac-includes=<(javac_includes)',
182 '--stamp=<(compile_stamp)',
184 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
185 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',
189 'action_name': 'jar_<(_target_name)',
190 'message': 'Creating <(_target_name) jar',
192 '<(DEPTH)/build/android/pylib/build_utils.py',
193 '<(DEPTH)/build/android/jar.py',
200 'python', '<(DEPTH)/build/android/jar.py',
201 '--classes-dir=<(classes_dir)',
202 '--jar-path=<(jar_path)',
203 '--excluded-classes=<(excluded_classes)',
205 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja.
206 '--ignore=>!(echo \'>(_inputs)\' | md5sum)',