[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 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 generate Java source files from templates that are processed |
| 7 | # through the host C pre-processor. |
| 8 | # |
mkosiba | dfdc7fb2 | 2014-10-23 13:56:12 | [diff] [blame] | 9 | # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum |
| 10 | # rule instead. |
| 11 | # |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 12 | # To use this, create a gyp target with the following form: |
| 13 | # { |
| 14 | # 'target_name': 'android_net_java_constants', |
| 15 | # 'type': 'none', |
| 16 | # 'sources': [ |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 17 | # 'net/android/NetError.template', |
| 18 | # ], |
| 19 | # 'variables': { |
[email protected] | 1b19c9a1e | 2013-03-02 16:39:08 | [diff] [blame] | 20 | # 'package_name': 'org/chromium/net', |
mkosiba | dfdc7fb2 | 2014-10-23 13:56:12 | [diff] [blame] | 21 | # 'template_deps': ['base/net_error_list.h'], |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 22 | # }, |
[email protected] | b50a8b5 | 2013-04-01 23:12:33 | [diff] [blame] | 23 | # 'includes': [ '../build/android/java_cpp_template.gypi' ], |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 24 | # }, |
| 25 | # |
[email protected] | 2716d84e | 2013-01-19 04:05:48 | [diff] [blame] | 26 | # The 'sources' entry should only list template file. The template file |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 27 | # itself should use the 'ClassName.template' format, and will generate |
newt | e0da096 | 2014-10-10 21:48:52 | [diff] [blame] | 28 | # 'gen/templates/<target-name>/<package-name>/ClassName.java. The files which |
| 29 | # template dependents on and typically included by the template should be listed |
[email protected] | 2716d84e | 2013-01-19 04:05:48 | [diff] [blame] | 30 | # in template_deps variables. Any change to them will force a rebuild of |
| 31 | # the template, and hence of any source that depends on it. |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 32 | # |
| 33 | |
| 34 | { |
| 35 | # Location where all generated Java sources will be placed. |
| 36 | 'variables': { |
jbudorick | f667d3b3a | 2015-11-13 00:44:58 | [diff] [blame] | 37 | 'additional_gcc_preprocess_options': [], |
[email protected] | b50a8b5 | 2013-04-01 23:12:33 | [diff] [blame] | 38 | 'include_path%': '<(DEPTH)', |
newt | e0da096 | 2014-10-10 21:48:52 | [diff] [blame] | 39 | 'output_dir': '<(SHARED_INTERMEDIATE_DIR)/templates/<(_target_name)/<(package_name)', |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 40 | }, |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 41 | 'direct_dependent_settings': { |
| 42 | 'variables': { |
[email protected] | 76e47fab | 2013-05-21 17:32:27 | [diff] [blame] | 43 | # Ensure that the output directory is used in the class path |
| 44 | # when building targets that depend on this one. |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 45 | 'generated_src_dirs': [ |
| 46 | '<(output_dir)/', |
| 47 | ], |
[email protected] | 76e47fab | 2013-05-21 17:32:27 | [diff] [blame] | 48 | # Ensure dependents are rebuilt when sources for this rule change. |
| 49 | 'additional_input_paths': [ |
| 50 | '<@(_sources)', |
| 51 | '<@(template_deps)', |
| 52 | ], |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 53 | }, |
| 54 | }, |
| 55 | # Define a single rule that will be apply to each .template file |
| 56 | # listed in 'sources'. |
| 57 | 'rules': [ |
| 58 | { |
| 59 | 'rule_name': 'generate_java_constants', |
| 60 | 'extension': 'template', |
[email protected] | 2716d84e | 2013-01-19 04:05:48 | [diff] [blame] | 61 | # Set template_deps as additional dependencies. |
[email protected] | b50a8b5 | 2013-04-01 23:12:33 | [diff] [blame] | 62 | 'variables': { |
| 63 | 'output_path': '<(output_dir)/<(RULE_INPUT_ROOT).java', |
| 64 | }, |
| 65 | 'inputs': [ |
[email protected] | 2f60163 | 2013-04-04 23:04:40 | [diff] [blame] | 66 | '<(DEPTH)/build/android/gyp/util/build_utils.py', |
| 67 | '<(DEPTH)/build/android/gyp/gcc_preprocess.py', |
[email protected] | b50a8b5 | 2013-04-01 23:12:33 | [diff] [blame] | 68 | '<@(template_deps)' |
| 69 | ], |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 70 | 'outputs': [ |
[email protected] | b50a8b5 | 2013-04-01 23:12:33 | [diff] [blame] | 71 | '<(output_path)', |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 72 | ], |
| 73 | 'action': [ |
[email protected] | 2f60163 | 2013-04-04 23:04:40 | [diff] [blame] | 74 | 'python', '<(DEPTH)/build/android/gyp/gcc_preprocess.py', |
[email protected] | b50a8b5 | 2013-04-01 23:12:33 | [diff] [blame] | 75 | '--include-path=<(include_path)', |
| 76 | '--output=<(output_path)', |
| 77 | '--template=<(RULE_INPUT_PATH)', |
jbudorick | f667d3b3a | 2015-11-13 00:44:58 | [diff] [blame] | 78 | '<@(additional_gcc_preprocess_options)', |
[email protected] | 4d49171 | 2012-12-10 12:38:24 | [diff] [blame] | 79 | ], |
| 80 | 'message': 'Generating Java from cpp template <(RULE_INPUT_PATH)', |
| 81 | } |
| 82 | ], |
| 83 | } |