OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # This file is meant to be included into a target to provide a rule | 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 | 6 # to generate Java source files from templates that are processed |
7 # through the host C pre-processor. | 7 # through the host C pre-processor. |
8 # | 8 # |
9 # This assumes a GNU-compatible pre-processor installed as 'cpp'. | 9 # This assumes a GNU-compatible pre-processor installed as 'cpp'. |
10 # Only tested on Linux. | 10 # Only tested on Linux. |
11 # | 11 # |
12 # To use this, create a gyp target with the following form: | 12 # To use this, create a gyp target with the following form: |
13 # { | 13 # { |
14 # 'target_name': 'android_net_java_constants', | 14 # 'target_name': 'android_net_java_constants', |
15 # 'type': 'none', | 15 # 'type': 'none', |
16 # 'sources': [ | 16 # 'sources': [ |
17 # 'net/base/certificate_mime_type_list.h', | |
18 # 'net/android/NetError.template', | 17 # 'net/android/NetError.template', |
19 # ], | 18 # ], |
20 # 'variables': { | 19 # 'variables': { |
21 # 'package_name': 'org.chromium.net', | 20 # 'package_name': 'org.chromium.net', |
| 21 # 'template_deps': ['net/base/certificate_mime_type_list.h'], |
22 # }, | 22 # }, |
23 # 'includes': [ '../build/android/java_constants.gypi' ], | 23 # 'includes': [ '../build/android/java_constants.gypi' ], |
24 # }, | 24 # }, |
25 # | 25 # |
26 # The 'sources' entry should list all input files. The template file | 26 # The 'sources' entry should only list template file. The template file |
27 # itself should use the 'ClassName.template' format, and will generate | 27 # itself should use the 'ClassName.template' format, and will generate |
28 # 'gen/templates/<package-name>/ClassName.java. Other source files | 28 # 'gen/templates/<package-name>/ClassName.java. The files which template |
29 # are those typically included by the template. Any change to them | 29 # dependents on and typically included by the template should be listed |
30 # will force a rebuild of the template, and hence of any source that | 30 # in template_deps variables. Any change to them will force a rebuild of |
31 # depends on it. | 31 # the template, and hence of any source that depends on it. |
32 # | 32 # |
33 | 33 |
34 { | 34 { |
35 # Location where all generated Java sources will be placed. | 35 # Location where all generated Java sources will be placed. |
36 'variables': { | 36 'variables': { |
37 'output_dir': '<(SHARED_INTERMEDIATE_DIR)/templates/<(package_name)' | 37 'output_dir': '<(SHARED_INTERMEDIATE_DIR)/templates/<(package_name)' |
38 }, | 38 }, |
39 # Ensure that the output directory is used in the class path | 39 # Ensure that the output directory is used in the class path |
40 # when building targets that depend on this one. | 40 # when building targets that depend on this one. |
41 'direct_dependent_settings': { | 41 'direct_dependent_settings': { |
42 'variables': { | 42 'variables': { |
43 'generated_src_dirs': [ | 43 'generated_src_dirs': [ |
44 '<(output_dir)/', | 44 '<(output_dir)/', |
45 ], | 45 ], |
46 }, | 46 }, |
47 }, | 47 }, |
48 # Define a single rule that will be apply to each .template file | 48 # Define a single rule that will be apply to each .template file |
49 # listed in 'sources'. | 49 # listed in 'sources'. |
50 'rules': [ | 50 'rules': [ |
51 { | 51 { |
52 'rule_name': 'generate_java_constants', | 52 'rule_name': 'generate_java_constants', |
53 'extension': 'template', | 53 'extension': 'template', |
54 'inputs': [ | 54 # Set template_deps as additional dependencies. |
55 '<(RULE_INPUT_PATH)', | 55 'inputs': ['<@(template_deps)'], |
56 ], | |
57 'outputs': [ | 56 'outputs': [ |
58 '<(output_dir)/<(RULE_INPUT_ROOT).java' | 57 '<(output_dir)/<(RULE_INPUT_ROOT).java' |
59 ], | 58 ], |
60 'action': [ | 59 'action': [ |
61 'cpp', # invoke host pre-processor. | 60 'cpp', # invoke host pre-processor. |
62 '-x', 'c-header', # treat sources as C header files | 61 '-x', 'c-header', # treat sources as C header files |
63 '-P', # disable line markers, i.e. '#line 309' | 62 '-P', # disable line markers, i.e. '#line 309' |
64 '-I', '<(DEPTH)', # Add project top-level to include path | 63 '-I', '<(DEPTH)', # Add project top-level to include path |
65 '-o', '<@(_outputs)', # Specify output file | 64 '-o', '<@(_outputs)', # Specify output file |
66 '<(RULE_INPUT_PATH)', # Specify input file | 65 '<(RULE_INPUT_PATH)', # Specify input file |
67 ], | 66 ], |
68 'message': 'Generating Java from cpp template <(RULE_INPUT_PATH)', | 67 'message': 'Generating Java from cpp template <(RULE_INPUT_PATH)', |
69 } | 68 } |
70 ], | 69 ], |
71 } | 70 } |
OLD | NEW |