Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: tools/gn/function_exec_script.cc

Issue 129043005: GN: Add the ability to trim whitespace from script results. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/function_read_file.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..2109522da1d1fb39484e855b02eec80c518337e9 100644
--- a/tools/gn/function_exec_script.cc
+++ b/tools/gn/function_exec_script.cc
@@ -236,8 +236,10 @@ 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,\n"
+ " arguments = [],\n"
+ " input_conversion = \"\",\n"
+ " 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 +258,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 +280,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 +337,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 +407,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
« no previous file with comments | « no previous file | tools/gn/function_read_file.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698