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_path': '<(PRODUCT_DIR)/lib.java/<(jar_name)', 59 'jar_excluded_classes': [ '*/R.class', '*/R##*.class' ], 60 'additional_input_paths': [], 61 'dex_path': '<(PRODUCT_DIR)/lib.java/<(_target_name).dex.jar', 62 'generated_src_dirs': ['>@(generated_R_dirs)'], 63 'generated_R_dirs': [], 64 'has_java_resources%': 0, 65 'java_strings_grd%': '', 66 'res_extra_dirs': [], 67 'res_extra_files': [], 68 'res_v14_verify_only%': 0, 69 'resource_input_paths': ['>@(res_extra_files)'], 70 'intermediate_dir': '<(SHARED_INTERMEDIATE_DIR)/<(_target_name)', 71 'classes_dir': '<(intermediate_dir)/classes', 72 'compile_stamp': '<(intermediate_dir)/compile.stamp', 73 }, 74 # This all_dependent_settings is used for java targets only. This will add the 75 # jar path to the classpath of dependent java targets. 76 'all_dependent_settings': { 77 'variables': { 78 'input_jars_paths': ['<(jar_path)'], 79 'library_dexed_jars_paths': ['<(dex_path)'], 80 }, 81 }, 82 'conditions': [ 83 ['has_java_resources == 1', { 84 'variables': { 85 'res_dir': '<(java_in_dir)/res', 86 'res_crunched_dir': '<(intermediate_dir)/res_crunched', 87 'res_v14_compatibility_stamp': '<(intermediate_dir)/res_v14_compatibility.stamp', 88 'res_v14_compatibility_dir': '<(intermediate_dir)/res_v14_compatibility', 89 'res_input_dirs': ['<(res_dir)', '<@(res_extra_dirs)'], 90 'resource_input_paths': ['<!@(find <(res_dir) -type f)'], 91 'R_dir': '<(intermediate_dir)/java_R', 92 'R_text_file': '<(R_dir)/R.txt', 93 'R_stamp': '<(intermediate_dir)/resources.stamp', 94 'generated_src_dirs': ['<(R_dir)'], 95 'additional_input_paths': ['<(R_stamp)', 96 '<(res_v14_compatibility_stamp)',], 97 'additional_res_dirs': [], 98 'dependencies_res_input_dirs': [], 99 'dependencies_res_files': [], 100 }, 101 'all_dependent_settings': { 102 'variables': { 103 # Dependent jars include this target's R.java file via 104 # generated_R_dirs and include its resources via 105 # dependencies_res_files. 106 'generated_R_dirs': ['<(R_dir)'], 107 'additional_input_paths': ['<(R_stamp)', 108 '<(res_v14_compatibility_stamp)',], 109 'dependencies_res_files': ['<@(resource_input_paths)'], 110 111 'dependencies_res_input_dirs': ['<@(res_input_dirs)'], 112 113 # Dependent APKs include this target's resources via 114 # additional_res_dirs, additional_res_packages, and 115 # additional_R_text_files. 116 'additional_res_dirs': ['<(res_crunched_dir)', 117 '<(res_v14_compatibility_dir)', 118 '<@(res_input_dirs)'], 119 'additional_res_packages': ['<(R_package)'], 120 'additional_R_text_files': ['<(R_text_file)'], 121 }, 122 }, 123 'conditions': [ 124 ['java_strings_grd != ""', { 125 'variables': { 126 'res_grit_dir': '<(intermediate_dir)/res_grit', 127 'res_input_dirs': ['<(res_grit_dir)'], 128 'grit_grd_file': '<(java_in_dir)/strings/<(java_strings_grd)', 129 'resource_input_paths': ['<!@pymod_do_main(grit_info <@(grit_defines) --outputs "<(res_grit_dir)" <(grit_grd_file))'], 130 }, 131 'actions': [ 132 { 133 'action_name': 'generate_localized_strings_xml', 134 'variables': { 135 'grit_additional_defines': ['-E', 'ANDROID_JAVA_TAGGED_ONLY=false'], 136 'grit_out_dir': '<(res_grit_dir)', 137 # resource_ids is unneeded since we don't generate .h headers. 138 'grit_resource_ids': '', 139 }, 140 'includes': ['../build/grit_action.gypi'], 141 }, 142 ], 143 }], 144 ], 145 'actions': [ 146 # Generate R.java and crunch image resources. 147 { 148 'action_name': 'process_resources', 149 'message': 'processing resources for <(_target_name)', 150 'variables': { 151 'android_manifest': '<(DEPTH)/build/android/AndroidManifest.xml', 152 # Include the dependencies' res dirs so that references to 153 # resources in dependencies can be resolved. 154 'all_res_dirs': ['<@(res_input_dirs)', 155 '>@(dependencies_res_input_dirs)',], 156 # Write the inputs list to a file, so that the action command 157 # line won't exceed the OS limits when calculating the checksum 158 # of the list. 159 'inputs_list_file': '>|(inputs_list.<(_target_name).gypcmd >@(_inputs))' 160 }, 161 'inputs': [ 162 '<(DEPTH)/build/android/gyp/util/build_utils.py', 163 '<(DEPTH)/build/android/gyp/process_resources.py', 164 '>@(resource_input_paths)', 165 '>@(dependencies_res_files)', 166 ], 167 'outputs': [ 168 '<(R_stamp)', 169 ], 170 'action': [ 171 'python', '<(DEPTH)/build/android/gyp/process_resources.py', 172 '--android-sdk', '<(android_sdk)', 173 '--android-sdk-tools', '<(android_sdk_tools)', 174 '--R-dir', '<(R_dir)', 175 '--res-dirs', '>(all_res_dirs)', 176 '--crunch-input-dir', '>(res_dir)', 177 '--crunch-output-dir', '<(res_crunched_dir)', 178 '--android-manifest', '<(android_manifest)', 179 '--non-constant-id', 180 '--custom-package', '<(R_package)', 181 '--stamp', '<(R_stamp)', 182 183 # Add hash of inputs to the command line, so if inputs change 184 # (e.g. if a resource if removed), the command will be re-run. 185 # TODO(newt): remove this once crbug.com/177552 is fixed in ninja. 186 '--ignore=>!(md5sum >(inputs_list_file))', 187 ], 188 }, 189 # Generate API 14 resources. 190 { 191 'action_name': 'generate_api_14_resources_<(_target_name)', 192 'message': 'Generating Android API 14 resources <(_target_name)', 193 'variables' : { 194 'res_v14_additional_options': [], 195 }, 196 'conditions': [ 197 ['res_v14_verify_only == 1', { 198 'variables': { 199 'res_v14_additional_options': ['--verify-only'] 200 }, 201 }], 202 ], 203 'inputs': [ 204 '<(DEPTH)/build/android/gyp/util/build_utils.py', 205 '<(DEPTH)/build/android/gyp/generate_v14_compatible_resources.py', 206 '>@(resource_input_paths)', 207 ], 208 'outputs': [ 209 '<(res_v14_compatibility_stamp)', 210 ], 211 'action': [ 212 'python', '<(DEPTH)/build/android/gyp/generate_v14_compatible_resources.py', 213 '--res-dir=<(res_dir)', 214 '--res-v14-compatibility-dir=<(res_v14_compatibility_dir)', 215 '--stamp', '<(res_v14_compatibility_stamp)', 216 '<@(res_v14_additional_options)', 217 ] 218 }, 219 ], 220 }], 221 ], 222 'actions': [ 223 { 224 'action_name': 'javac_<(_target_name)', 225 'message': 'Compiling <(_target_name) java sources', 226 'variables': { 227 'all_src_dirs': [ 228 '>(java_in_dir)/src', 229 '>@(additional_src_dirs)', 230 '>@(generated_src_dirs)', 231 ], 232 }, 233 'inputs': [ 234 '<(DEPTH)/build/android/gyp/util/build_utils.py', 235 '<(DEPTH)/build/android/gyp/javac.py', 236 '>!@(find >(java_in_dir)/src >(additional_src_dirs) -name "*.java")', 237 '>@(input_jars_paths)', 238 '>@(additional_input_paths)', 239 ], 240 'outputs': [ 241 '<(compile_stamp)', 242 ], 243 'action': [ 244 'python', '<(DEPTH)/build/android/gyp/javac.py', 245 '--output-dir=<(classes_dir)', 246 '--classpath=>(input_jars_paths)', 247 '--src-dirs=>(all_src_dirs)', 248 '--javac-includes=<(javac_includes)', 249 '--chromium-code=<(chromium_code)', 250 '--stamp=<(compile_stamp)', 251 252 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. 253 '--ignore=>!(echo \'>(_inputs)\' | md5sum)', 254 ] 255 }, 256 { 257 'action_name': 'jar_<(_target_name)', 258 'message': 'Creating <(_target_name) jar', 259 'inputs': [ 260 '<(DEPTH)/build/android/gyp/util/build_utils.py', 261 '<(DEPTH)/build/android/gyp/util/md5_check.py', 262 '<(DEPTH)/build/android/gyp/jar.py', 263 '<(compile_stamp)', 264 ], 265 'outputs': [ 266 '<(jar_path)', 267 ], 268 'action': [ 269 'python', '<(DEPTH)/build/android/gyp/jar.py', 270 '--classes-dir=<(classes_dir)', 271 '--jar-path=<(jar_path)', 272 '--excluded-classes=<(jar_excluded_classes)', 273 274 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. 275 '--ignore=>!(echo \'>(_inputs)\' | md5sum)', 276 ] 277 }, 278 { 279 'action_name': 'jar_toc_<(_target_name)', 280 'message': 'Creating <(_target_name) jar.TOC', 281 'inputs': [ 282 '<(DEPTH)/build/android/gyp/util/build_utils.py', 283 '<(DEPTH)/build/android/gyp/util/md5_check.py', 284 '<(DEPTH)/build/android/gyp/jar_toc.py', 285 '<(jar_path)', 286 ], 287 'outputs': [ 288 '<(jar_path).TOC', 289 ], 290 'action': [ 291 'python', '<(DEPTH)/build/android/gyp/jar_toc.py', 292 '--jar-path=<(jar_path)', 293 '--toc-path=<(jar_path).TOC', 294 295 # TODO(newt): remove this once http://crbug.com/177552 is fixed in ninja. 296 '--ignore=>!(echo \'>(_inputs)\' | md5sum)', 297 ] 298 }, 299 { 300 'action_name': 'dex_<(_target_name)', 301 'variables': { 302 'dex_input_paths': [ '<(jar_path)' ], 303 'output_path': '<(dex_path)', 304 }, 305 'includes': [ 'android/dex_action.gypi' ], 306 }, 307 ], 308 } 309