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

Unified Diff: tools/gn/function_process_file_template.cc

Issue 462103004: GN: Bug fixes in process_file_template (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: ihoist Created 6 years, 4 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 | « tools/gn/BUILD.gn ('k') | tools/gn/function_process_file_template_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/function_process_file_template.cc
diff --git a/tools/gn/function_process_file_template.cc b/tools/gn/function_process_file_template.cc
index 2e540f4fbfdc78400d39170f9437291a9e31ee91..540d1edf55fd939d0c5f8c729776ae0585925a06 100644
--- a/tools/gn/function_process_file_template.cc
+++ b/tools/gn/function_process_file_template.cc
@@ -37,14 +37,8 @@ const char kProcessFileTemplate_Help[] =
" The template can be a string or a list. If it is a list, multiple\n"
" output strings are generated for each input.\n"
"\n"
- " The following template substrings are used in the template arguments\n"
- " and are replaced with the corresponding part of the input file name:\n"
- "\n"
- " {{source}}\n"
- " The entire source name.\n"
- "\n"
- " {{source_name_part}}\n"
- " The source name with no path or extension.\n"
+ " The template should contain source expansions to which each name in\n"
+ " the source list is applied. See \"gn help source_expansion\".\n"
"\n"
"Example:\n"
"\n"
@@ -78,19 +72,34 @@ Value RunProcessFileTemplate(Scope* scope,
scope->GetSourceDir(), &input_files, err))
return Value();
- // Template.
+ std::vector<std::string> result_files;
SubstitutionList subst;
- if (!subst.Parse(args[1], err))
+
+ // Template.
+ const Value& template_arg = args[1];
+ if (template_arg.type() == Value::STRING) {
+ // Convert the string to a SubstitutionList with one pattern in it to
+ // simplify the code below.
+ std::vector<std::string> list;
+ list.push_back(template_arg.string_value());
+ if (!subst.Parse(list, template_arg.origin(), err))
+ return Value();
+ } else if (template_arg.type() == Value::LIST) {
+ if (!subst.Parse(template_arg, err))
+ return Value();
+ } else {
+ *err = Err(template_arg, "Not a string or a list.");
return Value();
+ }
- std::vector<SourceFile> result_files;
- SubstitutionWriter::ApplyListToSources(
+ SubstitutionWriter::ApplyListToSourcesAsString(
scope->settings(), subst, input_files, &result_files);
+ // Convert the list of strings to the return Value.
Value ret(function, Value::LIST);
ret.list_value().reserve(result_files.size());
for (size_t i = 0; i < result_files.size(); i++)
- ret.list_value().push_back(Value(function, result_files[i].value()));
+ ret.list_value().push_back(Value(function, result_files[i]));
return ret;
}
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/function_process_file_template_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698