Chromium Code Reviews| Index: tools/gn/function_exec_script.cc |
| diff --git a/tools/gn/function_exec_script.cc b/tools/gn/function_exec_script.cc |
| index 9cbb2dd80c45ccd75bad9fc9e2443ee170c6d280..7058b1f99e001f5b578c0d82be6d7c598461ef56 100644 |
| --- a/tools/gn/function_exec_script.cc |
| +++ b/tools/gn/function_exec_script.cc |
| @@ -236,8 +236,8 @@ const char kExecScript[] = "exec_script"; |
| const char kExecScript_Help[] = |
| "exec_script: Synchronously run a script and return the output.\n" |
| "\n" |
| - " exec_script(filename, arguments, input_conversion,\n" |
| - " [file_dependencies])\n" |
| + " exec_script(filename [, arguments [, input_conversion [,\n" |
|
bbudge
2014/01/08 23:22:32
I can't grok these brackets.
brettw
2014/01/09 23:48:53
I changed this to use a more C++ style of annotati
bbudge
2014/01/10 00:37:54
Sorry, I somehow didn't think the left/right brack
|
| + " file_dependencies]]])\n" |
| "\n" |
| " Runs the given script, returning the stdout of the script. The build\n" |
| " generation will fail if the script does not exist or returns a nonzero\n" |
| @@ -256,11 +256,15 @@ const char kExecScript_Help[] = |
| "\n" |
| " arguments:\n" |
| " A list of strings to be passed to the script as arguments.\n" |
| + " May be unspecified or the empty list which means no arguments.\n" |
| "\n" |
| " input_conversion:\n" |
| " Controls how the file is read and parsed.\n" |
| " See \"gn help input_conversion\".\n" |
| "\n" |
| + " If unspecified, defaults to the empty string which causes the\n" |
| + " script result to be discarded. exec script will return None.\n" |
| + "\n" |
| " dependencies:\n" |
| " (Optional) A list of files that this script reads or otherwise\n" |
| " depends on. These dependencies will be added to the build result\n" |
| @@ -274,15 +278,19 @@ const char kExecScript_Help[] = |
| "\n" |
| " all_lines = exec_script(\"myscript.py\", [some_input], \"list lines\",\n" |
| " [ rebase_path(\"data_file.txt\", \".\"," |
| - " root_build_dir) ])\n"; |
| + " root_build_dir) ])\n" |
| + "\n" |
| + " # This example just calls the script with no arguments and discards\n" |
| + " # the result.\n" |
| + " exec_script(\"//foo/bar/myscript.py\")\n"; |
| Value RunExecScript(Scope* scope, |
| const FunctionCallNode* function, |
| const std::vector<Value>& args, |
| Err* err) { |
| - if (args.size() != 3 && args.size() != 4) { |
| + if (args.size() < 1 || args.size() > 4) { |
| *err = Err(function->function(), "Wrong number of arguments to exec_script", |
| - "I expected three or four arguments."); |
| + "I expected between one and four arguments."); |
| return Value(); |
| } |
| @@ -327,13 +335,16 @@ Value RunExecScript(Scope* scope, |
| CommandLine cmdline(python_path); |
| cmdline.AppendArgPath(script_path); |
| - const Value& script_args = args[1]; |
| - if (!script_args.VerifyTypeIs(Value::LIST, err)) |
| - return Value(); |
| - for (size_t i = 0; i < script_args.list_value().size(); i++) { |
| - if (!script_args.list_value()[i].VerifyTypeIs(Value::STRING, err)) |
| + if (args.size() >= 2) { |
| + // Optional command-line arguments to the script. |
| + const Value& script_args = args[1]; |
| + if (!script_args.VerifyTypeIs(Value::LIST, err)) |
| return Value(); |
| - cmdline.AppendArg(script_args.list_value()[i].string_value()); |
| + for (size_t i = 0; i < script_args.list_value().size(); i++) { |
| + if (!script_args.list_value()[i].VerifyTypeIs(Value::STRING, err)) |
| + return Value(); |
| + cmdline.AppendArg(script_args.list_value()[i].string_value()); |
| + } |
| } |
| // Log command line for debugging help. |
| @@ -394,7 +405,9 @@ Value RunExecScript(Scope* scope, |
| return Value(); |
| } |
| - return ConvertInputToValue(output, function, args[2], err); |
| + // Default to None value for the input conversion if unspecified. |
| + return ConvertInputToValue(output, function, |
| + args.size() >= 3 ? args[2] : Value(), err); |
| } |
| } // namespace functions |