OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "tools/gn/file_template.h" |
| 6 #include "tools/gn/functions.h" |
| 7 #include "tools/gn/parse_tree.h" |
| 8 |
| 9 /* |
| 10 process_file_template: Do template expansion over a list of files. |
| 11 |
| 12 process_file_template(source_list, template) |
| 13 |
| 14 process_file_template applies a template list to a source file list, |
| 15 returning the result of applying each template to each source. This is |
| 16 typically used for computing output file names from input files. |
| 17 |
| 18 Arguments: |
| 19 |
| 20 The source_list is a list of file names. |
| 21 |
| 22 The template can be a string or a list. If it is a list, multiple output |
| 23 strings are generated for each input. |
| 24 |
| 25 The following template substrings are used in the template arguments |
| 26 and are replaced with the corresponding part of the input file name: |
| 27 |
| 28 "{{source}}": The entire source name. |
| 29 |
| 30 "{{source_name_part}}": The source name with no path or extension. |
| 31 |
| 32 Example: |
| 33 |
| 34 sources = [ |
| 35 "foo.idl", |
| 36 "bar.idl", |
| 37 ] |
| 38 myoutputs = process_file_template( |
| 39 sources, |
| 40 [ "$target_gen_dir/{{source_name_part}}.cc", |
| 41 "$target_gen_dir/{{source_name_part}}.h" ]) |
| 42 |
| 43 The result in this case will be: |
| 44 [ "/out/Debug/foo.cc" |
| 45 "/out/Debug/foo.h" |
| 46 "/out/Debug/bar.cc" |
| 47 "/out/Debug/bar.h" ] |
| 48 */ |
| 49 Value ExecuteProcessFileTemplate(Scope* scope, |
| 50 const FunctionCallNode* function, |
| 51 const std::vector<Value>& args, |
| 52 Err* err) { |
| 53 if (args.size() != 2) { |
| 54 *err = Err(function->function(), "Expected two arguments"); |
| 55 return Value(); |
| 56 } |
| 57 |
| 58 FileTemplate file_template(args[1], err); |
| 59 if (err->has_error()) |
| 60 return Value(); |
| 61 |
| 62 Value ret(function, Value::LIST); |
| 63 file_template.Apply(args[0], function, &ret.list_value(), err); |
| 64 return ret; |
| 65 } |
OLD | NEW |