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