OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 #include "tools/gn/functions.h" | 5 #include "tools/gn/functions.h" |
6 | 6 |
7 #include "tools/gn/config_values_generator.h" | 7 #include "tools/gn/config_values_generator.h" |
8 #include "tools/gn/err.h" | 8 #include "tools/gn/err.h" |
9 #include "tools/gn/parse_tree.h" | 9 #include "tools/gn/parse_tree.h" |
10 #include "tools/gn/scope.h" | 10 #include "tools/gn/scope.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 // custom ---------------------------------------------------------------------- | 116 // custom ---------------------------------------------------------------------- |
117 | 117 |
118 const char kCustom[] = "custom"; | 118 const char kCustom[] = "custom"; |
119 const char kCustom_Help[] = | 119 const char kCustom_Help[] = |
120 "custom: Declare a script-generated target.\n" | 120 "custom: Declare a script-generated target.\n" |
121 "\n" | 121 "\n" |
122 " This target type allows you to run a script over a set of source\n" | 122 " This target type allows you to run a script over a set of source\n" |
123 " files and generate a set of output files.\n" | 123 " files and generate a set of output files.\n" |
124 "\n" | 124 "\n" |
125 " The script will be executed with the given arguments with the current\n" | 125 " The script will be executed with the given arguments with the current\n" |
126 " directory being that of the current BUILD file.\n" | 126 " directory being that of the root build directory. If you pass\n" |
| 127 " to your script, see \"gn help to_build_path\" for how to convert\n" |
| 128 " file names to be relative to the build directory (file names in the\n" |
| 129 " sources, outputs, and source_prereqs will be all treated as relative\n" |
| 130 " to the current build file and converted as needed automatically).\n" |
127 "\n" | 131 "\n" |
128 " There are two modes. The first mode is the \"per-file\" mode where you\n" | 132 " There are two modes. The first mode is the \"per-file\" mode where you\n" |
129 " specify a list of sources and the script is run once for each one as a\n" | 133 " specify a list of sources and the script is run once for each one as a\n" |
130 " build rule. In this case, each file specified in the |outputs|\n" | 134 " build rule. In this case, each file specified in the |outputs|\n" |
131 " variable must be unique when applied to each source file (normally you\n" | 135 " variable must be unique when applied to each source file (normally you\n" |
132 " would reference |{{source_name_part}}| from within each one) or the\n" | 136 " would reference |{{source_name_part}}| from within each one) or the\n" |
133 " build system will get confused about how to build those files. You\n" | 137 " build system will get confused about how to build those files. You\n" |
134 " should use the |source_prereqs| variable to list all additional\n" | 138 " should use the |source_prereqs| variable to list all additional\n" |
135 " dependencies of your script: these will be added as dependencies for\n" | 139 " dependencies of your script: these will be added as dependencies for\n" |
136 " each build step.\n" | 140 " each build step.\n" |
137 "\n" | 141 "\n" |
138 " The second mode is when you just want to run a script once rather than\n" | 142 " The second mode is when you just want to run a script once rather than\n" |
139 " as a general rule over a set of files. In this case you don't list any\n" | 143 " as a general rule over a set of files. In this case you don't list any\n" |
140 " sources. Dependencies of your script are specified only in the\n" | 144 " sources. Dependencies of your script are specified only in the\n" |
141 " |source_prereqs| variable and your |outputs| variable should just list\n" | 145 " |source_prereqs| variable and your |outputs| variable should just list\n" |
142 " all outputs.\n" | 146 " all outputs.\n" |
143 "\n" | 147 "\n" |
144 "Variables:\n" | 148 "Variables:\n" |
145 "\n" | 149 "\n" |
146 " args, deps, outputs, script*, source_prereqs, sources\n" | 150 " args, deps, outputs, script*, source_prereqs, sources\n" |
147 " * = required\n" | 151 " * = required\n" |
148 "\n" | 152 "\n" |
149 " There are some special substrings that will be searched for when\n" | 153 " There are some special substrings that will be searched for when\n" |
150 " processing some variables:\n" | 154 " processing some variables:\n" |
151 "\n" | 155 "\n" |
152 " {{source}}\n" | 156 " {{source}}\n" |
153 " Expanded in |args|, this is the name of the source file relative\n" | 157 " Expanded in |args|, this is the name of the source file relative\n" |
154 " to the current directory when running the script. This is how\n" | 158 " to the build directory This is how you specify the current input\n" |
155 " you specify the current input file to your script.\n" | 159 " file to your script.\n" |
156 "\n" | 160 "\n" |
157 " {{source_name_part}}\n" | 161 " {{source_name_part}}\n" |
158 " Expanded in |args| and |outputs|, this is just the filename part\n" | 162 " Expanded in |args| and |outputs|, this is just the filename part\n" |
159 " of the current source file with no directory or extension. This\n" | 163 " of the current source file with no directory or extension. This\n" |
160 " is how you specify a name transformation to the output. Normally\n" | 164 " is how you specify a name transformation to the output. Normally\n" |
161 " you would write an output as\n" | 165 " you would write an output as\n" |
162 " \"$target_output_dir/{{source_name_part}}.o\".\n" | 166 " \"$target_output_dir/{{source_name_part}}.o\".\n" |
163 "\n" | 167 "\n" |
164 " All |outputs| files must be inside the output directory of the build.\n" | 168 " All |outputs| files must be inside the output directory of the build.\n" |
165 " You would generally use |$target_output_dir| or |$target_gen_dir| to\n" | 169 " You would generally use |$target_output_dir| or |$target_gen_dir| to\n" |
166 " reference the output or generated intermediate file directories,\n" | 170 " reference the output or generated intermediate file directories,\n" |
167 " respectively.\n" | 171 " respectively.\n" |
168 "\n" | 172 "\n" |
169 "Examples:\n" | 173 "Examples:\n" |
170 "\n" | 174 "\n" |
171 " # Runs the script over each IDL file. The IDL script will generate\n" | 175 " # Runs the script over each IDL file. The IDL script will generate\n" |
172 " # both a .cc and a .h file for each input.\n" | 176 " # both a .cc and a .h file for each input.\n" |
173 " custom(\"general_rule\") {\n" | 177 " custom(\"general_rule\") {\n" |
174 " script = \"idl_processor.py\"\n" | 178 " script = \"idl_processor.py\"\n" |
175 " sources = [ \"foo.idl\", \"bar.idl\" ]\n" | 179 " sources = [ \"foo.idl\", \"bar.idl\" ]\n" |
176 " source_prereqs = [ \"my_configuration.txt\" ]\n" | 180 " source_prereqs = [ \"my_configuration.txt\" ]\n" |
177 " outputs = [ \"$target_gen_dir/{{source_name_part}}.h\",\n" | 181 " outputs = [ \"$target_gen_dir/{{source_name_part}}.h\",\n" |
178 " \"$target_gen_dir/{{source_name_part}}.cc\" ]\n" | 182 " \"$target_gen_dir/{{source_name_part}}.cc\" ]\n" |
| 183 "\n" |
| 184 " # Note that since \"args\" is opaque to GN, if you specify paths\n" |
| 185 " # here, you will need to convert it to be relative to the build\n" |
| 186 " # directory using \"to_build_path()\".\n" |
179 " args = [ \"{{source}}\",\n" | 187 " args = [ \"{{source}}\",\n" |
180 " \"-o\",\n" | 188 " \"-o\",\n" |
181 " \"$relative_target_gen_dir/{{source_name_part}}.h\" ]\n" | 189 " to_build_path(relative_target_gen_dir) + \"/\" +\n" |
| 190 " {{source_name_part}}.h\" ]\n" |
182 " }\n" | 191 " }\n" |
183 "\n" | 192 "\n" |
184 " custom(\"just_run_this_guy_once\") {\n" | 193 " custom(\"just_run_this_guy_once\") {\n" |
185 " script = \"doprocessing.py\"\n" | 194 " script = \"doprocessing.py\"\n" |
186 " source_prereqs = [ \"my_configuration.txt\" ]\n" | 195 " source_prereqs = [ \"my_configuration.txt\" ]\n" |
187 " outputs = [ \"$target_gen_dir/insightful_output.txt\" ]\n" | 196 " outputs = [ \"$target_gen_dir/insightful_output.txt\" ]\n" |
188 " args = [ \"--output_dir\", $target_gen_dir ]\n" | 197 " args = [ \"--output_dir\", to_build_path(target_gen_dir) ]\n" |
189 " }\n"; | 198 " }\n"; |
190 | 199 |
191 Value RunCustom(Scope* scope, | 200 Value RunCustom(Scope* scope, |
192 const FunctionCallNode* function, | 201 const FunctionCallNode* function, |
193 const std::vector<Value>& args, | 202 const std::vector<Value>& args, |
194 BlockNode* block, | 203 BlockNode* block, |
195 Err* err) { | 204 Err* err) { |
196 return ExecuteGenericTarget(functions::kCustom, scope, function, args, | 205 return ExecuteGenericTarget(functions::kCustom, scope, function, args, |
197 block, err); | 206 block, err); |
198 } | 207 } |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 Value RunTest(Scope* scope, | 320 Value RunTest(Scope* scope, |
312 const FunctionCallNode* function, | 321 const FunctionCallNode* function, |
313 const std::vector<Value>& args, | 322 const std::vector<Value>& args, |
314 BlockNode* block, | 323 BlockNode* block, |
315 Err* err) { | 324 Err* err) { |
316 return ExecuteGenericTarget(functions::kExecutable, scope, function, args, | 325 return ExecuteGenericTarget(functions::kExecutable, scope, function, args, |
317 block, err); | 326 block, err); |
318 } | 327 } |
319 | 328 |
320 } // namespace functions | 329 } // namespace functions |
OLD | NEW |