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 "tools/gn/file_template.h" | |
6 #include "tools/gn/functions.h" | 5 #include "tools/gn/functions.h" |
7 #include "tools/gn/parse_tree.h" | 6 #include "tools/gn/parse_tree.h" |
8 #include "tools/gn/scope.h" | 7 #include "tools/gn/scope.h" |
9 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
| 9 #include "tools/gn/substitution_list.h" |
| 10 #include "tools/gn/substitution_writer.h" |
10 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
11 #include "tools/gn/value_extractors.h" | 12 #include "tools/gn/value_extractors.h" |
12 | 13 |
13 namespace functions { | 14 namespace functions { |
14 | 15 |
15 const char kProcessFileTemplate[] = "process_file_template"; | 16 const char kProcessFileTemplate[] = "process_file_template"; |
16 const char kProcessFileTemplate_HelpShort[] = | 17 const char kProcessFileTemplate_HelpShort[] = |
17 "process_file_template: Do template expansion over a list of files."; | 18 "process_file_template: Do template expansion over a list of files."; |
18 const char kProcessFileTemplate_Help[] = | 19 const char kProcessFileTemplate_Help[] = |
19 "process_file_template: Do template expansion over a list of files.\n" | 20 "process_file_template: Do template expansion over a list of files.\n" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 65 |
65 Value RunProcessFileTemplate(Scope* scope, | 66 Value RunProcessFileTemplate(Scope* scope, |
66 const FunctionCallNode* function, | 67 const FunctionCallNode* function, |
67 const std::vector<Value>& args, | 68 const std::vector<Value>& args, |
68 Err* err) { | 69 Err* err) { |
69 if (args.size() != 2) { | 70 if (args.size() != 2) { |
70 *err = Err(function->function(), "Expected two arguments"); | 71 *err = Err(function->function(), "Expected two arguments"); |
71 return Value(); | 72 return Value(); |
72 } | 73 } |
73 | 74 |
74 FileTemplate file_template(scope->settings(), args[1], | 75 // Source list. |
75 FileTemplate::OUTPUT_ABSOLUTE, SourceDir(), err); | |
76 if (err->has_error()) | |
77 return Value(); | |
78 | |
79 Target::FileList input_files; | 76 Target::FileList input_files; |
80 if (!ExtractListOfRelativeFiles(scope->settings()->build_settings(), args[0], | 77 if (!ExtractListOfRelativeFiles(scope->settings()->build_settings(), args[0], |
81 scope->GetSourceDir(), &input_files, err)) | 78 scope->GetSourceDir(), &input_files, err)) |
82 return Value(); | 79 return Value(); |
83 | 80 |
| 81 // Template. |
| 82 SubstitutionList subst; |
| 83 if (!subst.Parse(args[1], err)) |
| 84 return Value(); |
| 85 |
| 86 std::vector<SourceFile> result_files; |
| 87 SubstitutionWriter::ApplyListToSources( |
| 88 scope->settings(), subst, input_files, &result_files); |
| 89 |
84 Value ret(function, Value::LIST); | 90 Value ret(function, Value::LIST); |
| 91 ret.list_value().reserve(result_files.size()); |
| 92 for (size_t i = 0; i < result_files.size(); i++) |
| 93 ret.list_value().push_back(Value(function, result_files[i].value())); |
85 | 94 |
86 // Temporary holding place, allocate outside to re-use buffer. | |
87 std::vector<std::string> string_output; | |
88 | |
89 for (size_t i = 0; i < input_files.size(); i++) { | |
90 string_output.clear(); | |
91 file_template.Apply(input_files[i], &string_output); | |
92 for (size_t out_i = 0; out_i < string_output.size(); out_i++) | |
93 ret.list_value().push_back(Value(function, string_output[out_i])); | |
94 } | |
95 return ret; | 95 return ret; |
96 } | 96 } |
97 | 97 |
98 } // namespace functions | 98 } // namespace functions |
OLD | NEW |