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.
5 #include "tools/gn/file_template.h"
6 #include "tools/gn/functions.h"
7 #include "tools/gn/parse_tree.h"
11 const char kProcessFileTemplate[] = "process_file_template";
12 const char kProcessFileTemplate_HelpShort[] =
13 "process_file_template: Do template expansion over a list of files.";
14 const char kProcessFileTemplate_Help[] =
15 "process_file_template: Do template expansion over a list of files.\n"
17 " process_file_template(source_list, template)\n"
19 " process_file_template applies a template list to a source file list,\n"
20 " returning the result of applying each template to each source. This is\n"
21 " typically used for computing output file names from input files.\n"
25 " The source_list is a list of file names.\n"
27 " The template can be a string or a list. If it is a list, multiple\n"
28 " output strings are generated for each input.\n"
30 " The following template substrings are used in the template arguments\n"
31 " and are replaced with the corresponding part of the input file name:\n"
34 " The entire source name.\n"
36 " {{source_name_part}}\n"
37 " The source name with no path or extension.\n"
45 " myoutputs = process_file_template(\n"
47 " [ \"$target_gen_dir/{{source_name_part}}.cc\",\n"
48 " \"$target_gen_dir/{{source_name_part}}.h\" ])\n"
50 " The result in this case will be:\n"
51 " [ \"//out/Debug/foo.cc\"\n"
52 " \"//out/Debug/foo.h\"\n"
53 " \"//out/Debug/bar.cc\"\n"
54 " \"//out/Debug/bar.h\" ]\n";
56 Value RunProcessFileTemplate(Scope* scope,
57 const FunctionCallNode* function,
58 const std::vector<Value>& args,
60 if (args.size() != 2) {
61 *err = Err(function->function(), "Expected two arguments");
65 FileTemplate file_template(args[1], err);
69 Value ret(function, Value::LIST);
70 file_template.Apply(args[0], function, &ret.list_value(), err);
74 } // namespace functions