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_Help
[] =
13 "process_file_template: Do template expansion over a list of files.\n"
15 " process_file_template(source_list, template)\n"
17 " process_file_template applies a template list to a source file list,\n"
18 " returning the result of applying each template to each source. This is\n"
19 " typically used for computing output file names from input files.\n"
23 " The source_list is a list of file names.\n"
25 " The template can be a string or a list. If it is a list, multiple\n"
26 " output strings are generated for each input.\n"
28 " The following template substrings are used in the template arguments\n"
29 " and are replaced with the corresponding part of the input file name:\n"
32 " The entire source name.\n"
34 " {{source_name_part}}\n"
35 " The source name with no path or extension.\n"
43 " myoutputs = process_file_template(\n"
45 " [ \"$target_gen_dir/{{source_name_part}}.cc\",\n"
46 " \"$target_gen_dir/{{source_name_part}}.h\" ])\n"
48 " The result in this case will be:\n"
49 " [ \"//out/Debug/foo.cc\"\n"
50 " \"//out/Debug/foo.h\"\n"
51 " \"//out/Debug/bar.cc\"\n"
52 " \"//out/Debug/bar.h\" ]\n";
54 Value
RunProcessFileTemplate(Scope
* scope
,
55 const FunctionCallNode
* function
,
56 const std::vector
<Value
>& args
,
58 if (args
.size() != 2) {
59 *err
= Err(function
->function(), "Expected two arguments");
63 FileTemplate
file_template(args
[1], err
);
67 Value
ret(function
, Value::LIST
);
68 file_template
.Apply(args
[0], function
, &ret
.list_value(), err
);
72 } // namespace functions