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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/file_util.h" | 6 #include "base/file_util.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/process/kill.h" | 8 #include "base/process/kill.h" |
9 #include "base/process/launch.h" | 9 #include "base/process/launch.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 "\n" | 238 "\n" |
239 " exec_script(filename, arguments, input_conversion,\n" | 239 " exec_script(filename, arguments, input_conversion,\n" |
240 " [file_dependencies])\n" | 240 " [file_dependencies])\n" |
241 "\n" | 241 "\n" |
242 " Runs the given script, returning the stdout of the script. The build\n" | 242 " Runs the given script, returning the stdout of the script. The build\n" |
243 " generation will fail if the script does not exist or returns a nonzero\n" | 243 " generation will fail if the script does not exist or returns a nonzero\n" |
244 " exit code.\n" | 244 " exit code.\n" |
245 "\n" | 245 "\n" |
246 " The current directory when executing the script will be the root\n" | 246 " The current directory when executing the script will be the root\n" |
247 " build directory. If you are passing file names, you will want to use\n" | 247 " build directory. If you are passing file names, you will want to use\n" |
248 " the to_build_dir() function to make file names relative to this\n" | 248 " the rebase_path() function to make file names relative to this\n" |
249 " path (see \"gn help to_build_dir\").\n" | 249 " path (see \"gn help rebase_path\").\n" |
250 "\n" | 250 "\n" |
251 "Arguments:\n" | 251 "Arguments:\n" |
252 "\n" | 252 "\n" |
253 " filename:\n" | 253 " filename:\n" |
254 " File name of python script to execute. Non-absolute names will\n" | 254 " File name of python script to execute. Non-absolute names will\n" |
255 " be treated as relative to the current build file.\n" | 255 " be treated as relative to the current build file.\n" |
256 "\n" | 256 "\n" |
257 " arguments:\n" | 257 " arguments:\n" |
258 " A list of strings to be passed to the script as arguments.\n" | 258 " A list of strings to be passed to the script as arguments.\n" |
259 "\n" | 259 "\n" |
260 " input_conversion:\n" | 260 " input_conversion:\n" |
261 " Controls how the file is read and parsed.\n" | 261 " Controls how the file is read and parsed.\n" |
262 " See \"gn help input_conversion\".\n" | 262 " See \"gn help input_conversion\".\n" |
263 "\n" | 263 "\n" |
264 " dependencies:\n" | 264 " dependencies:\n" |
265 " (Optional) A list of files that this script reads or otherwise\n" | 265 " (Optional) A list of files that this script reads or otherwise\n" |
266 " depends on. These dependencies will be added to the build result\n" | 266 " depends on. These dependencies will be added to the build result\n" |
267 " such that if any of them change, the build will be regenerated and\n" | 267 " such that if any of them change, the build will be regenerated and\n" |
268 " the script will be re-run.\n" | 268 " the script will be re-run.\n" |
269 "\n" | 269 "\n" |
270 " The script itself will be an implicit dependency so you do not\n" | 270 " The script itself will be an implicit dependency so you do not\n" |
271 " need to list it.\n" | 271 " need to list it.\n" |
272 "\n" | 272 "\n" |
273 "Example:\n" | 273 "Example:\n" |
274 "\n" | 274 "\n" |
275 " all_lines = exec_script(\"myscript.py\", [some_input], \"list lines\",\n" | 275 " all_lines = exec_script(\"myscript.py\", [some_input], \"list lines\",\n" |
276 " [ to_build_dir(\"data_file.txt\") ])\n"; | 276 " [ rebase_path(\"data_file.txt\", \".\"," |
| 277 " root_build_dir) ])\n"; |
277 | 278 |
278 Value RunExecScript(Scope* scope, | 279 Value RunExecScript(Scope* scope, |
279 const FunctionCallNode* function, | 280 const FunctionCallNode* function, |
280 const std::vector<Value>& args, | 281 const std::vector<Value>& args, |
281 Err* err) { | 282 Err* err) { |
282 if (args.size() != 3 && args.size() != 4) { | 283 if (args.size() != 3 && args.size() != 4) { |
283 *err = Err(function->function(), "Wrong number of args to write_file", | 284 *err = Err(function->function(), "Wrong number of arguments to exec_script", |
284 "I expected three or four arguments."); | 285 "I expected three or four arguments."); |
285 return Value(); | 286 return Value(); |
286 } | 287 } |
287 | 288 |
288 const Settings* settings = scope->settings(); | 289 const Settings* settings = scope->settings(); |
289 const BuildSettings* build_settings = settings->build_settings(); | 290 const BuildSettings* build_settings = settings->build_settings(); |
290 const SourceDir& cur_dir = scope->GetSourceDir(); | 291 const SourceDir& cur_dir = scope->GetSourceDir(); |
291 | 292 |
292 // Find the python script to run. | 293 // Find the python script to run. |
293 if (!args[0].VerifyTypeIs(Value::STRING, err)) | 294 if (!args[0].VerifyTypeIs(Value::STRING, err)) |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 msg += "."; | 391 msg += "."; |
391 *err = Err(function->function(), "Script returned non-zero exit code.", | 392 *err = Err(function->function(), "Script returned non-zero exit code.", |
392 msg); | 393 msg); |
393 return Value(); | 394 return Value(); |
394 } | 395 } |
395 | 396 |
396 return ConvertInputToValue(output, function, args[2], err); | 397 return ConvertInputToValue(output, function, args[2], err); |
397 } | 398 } |
398 | 399 |
399 } // namespace functions | 400 } // namespace functions |
OLD | NEW |