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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/gn/BUILD.gn ('k') | tools/gn/function_process_file_template_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "tools/gn/parse_tree.h" 6 #include "tools/gn/parse_tree.h"
7 #include "tools/gn/scope.h" 7 #include "tools/gn/scope.h"
8 #include "tools/gn/settings.h" 8 #include "tools/gn/settings.h"
9 #include "tools/gn/substitution_list.h" 9 #include "tools/gn/substitution_list.h"
10 #include "tools/gn/substitution_writer.h" 10 #include "tools/gn/substitution_writer.h"
(...skipping 19 matching lines...) Expand all
30 " when that function can't be used (like there's no target or the target\n" 30 " when that function can't be used (like there's no target or the target\n"
31 " is defined in another build file).\n" 31 " is defined in another build file).\n"
32 "\n" 32 "\n"
33 "Arguments:\n" 33 "Arguments:\n"
34 "\n" 34 "\n"
35 " The source_list is a list of file names.\n" 35 " The source_list is a list of file names.\n"
36 "\n" 36 "\n"
37 " The template can be a string or a list. If it is a list, multiple\n" 37 " The template can be a string or a list. If it is a list, multiple\n"
38 " output strings are generated for each input.\n" 38 " output strings are generated for each input.\n"
39 "\n" 39 "\n"
40 " The following template substrings are used in the template arguments\n" 40 " The template should contain source expansions to which each name in\n"
41 " and are replaced with the corresponding part of the input file name:\n" 41 " the source list is applied. See \"gn help source_expansion\".\n"
42 "\n"
43 " {{source}}\n"
44 " The entire source name.\n"
45 "\n"
46 " {{source_name_part}}\n"
47 " The source name with no path or extension.\n"
48 "\n" 42 "\n"
49 "Example:\n" 43 "Example:\n"
50 "\n" 44 "\n"
51 " sources = [\n" 45 " sources = [\n"
52 " \"foo.idl\",\n" 46 " \"foo.idl\",\n"
53 " \"bar.idl\",\n" 47 " \"bar.idl\",\n"
54 " ]\n" 48 " ]\n"
55 " myoutputs = process_file_template(\n" 49 " myoutputs = process_file_template(\n"
56 " sources,\n" 50 " sources,\n"
57 " [ \"$target_gen_dir/{{source_name_part}}.cc\",\n" 51 " [ \"$target_gen_dir/{{source_name_part}}.cc\",\n"
(...skipping 13 matching lines...) Expand all
71 *err = Err(function->function(), "Expected two arguments"); 65 *err = Err(function->function(), "Expected two arguments");
72 return Value(); 66 return Value();
73 } 67 }
74 68
75 // Source list. 69 // Source list.
76 Target::FileList input_files; 70 Target::FileList input_files;
77 if (!ExtractListOfRelativeFiles(scope->settings()->build_settings(), args[0], 71 if (!ExtractListOfRelativeFiles(scope->settings()->build_settings(), args[0],
78 scope->GetSourceDir(), &input_files, err)) 72 scope->GetSourceDir(), &input_files, err))
79 return Value(); 73 return Value();
80 74
75 std::vector<std::string> result_files;
76 SubstitutionList subst;
77
81 // Template. 78 // Template.
82 SubstitutionList subst; 79 if (args[1].type() == Value::STRING) {
jamesr 2014/08/12 20:20:33 could you hoist args[1] into a local var of type c
83 if (!subst.Parse(args[1], err)) 80 // Convert the string to a SubstitutionList with one pattern in it to
81 // simplify the code below.
82 std::vector<std::string> list;
83 list.push_back(args[1].string_value());
84 if (!subst.Parse(list, args[1].origin(), err))
85 return Value();
86 } else if (args[1].type() == Value::LIST) {
87 if (!subst.Parse(args[1], err))
88 return Value();
89 } else {
90 *err = Err(args[1], "Not a string or a list.");
84 return Value(); 91 return Value();
92 }
85 93
86 std::vector<SourceFile> result_files; 94 SubstitutionWriter::ApplyListToSourcesAsString(
87 SubstitutionWriter::ApplyListToSources(
88 scope->settings(), subst, input_files, &result_files); 95 scope->settings(), subst, input_files, &result_files);
89 96
97 // Convert the list of strings to the return Value.
90 Value ret(function, Value::LIST); 98 Value ret(function, Value::LIST);
91 ret.list_value().reserve(result_files.size()); 99 ret.list_value().reserve(result_files.size());
92 for (size_t i = 0; i < result_files.size(); i++) 100 for (size_t i = 0; i < result_files.size(); i++)
93 ret.list_value().push_back(Value(function, result_files[i].value())); 101 ret.list_value().push_back(Value(function, result_files[i]));
94 102
95 return ret; 103 return ret;
96 } 104 }
97 105
98 } // namespace functions 106 } // namespace functions
OLDNEW
« 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