Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / gn / function_process_file_template.cc
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 namespace functions {
10
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"
16     "\n"
17     "  process_file_template(source_list, template)\n"
18     "\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"
22     "\n"
23     "Arguments:\n"
24     "\n"
25     "  The source_list is a list of file names.\n"
26     "\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"
29     "\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"
32     "\n"
33     "    {{source}}\n"
34     "        The entire source name.\n"
35     "\n"
36     "    {{source_name_part}}\n"
37     "        The source name with no path or extension.\n"
38     "\n"
39     "Example:\n"
40     "\n"
41     "  sources = [\n"
42     "    \"foo.idl\",\n"
43     "    \"bar.idl\",\n"
44     "  ]\n"
45     "  myoutputs = process_file_template(\n"
46     "      sources,\n"
47     "      [ \"$target_gen_dir/{{source_name_part}}.cc\",\n"
48     "        \"$target_gen_dir/{{source_name_part}}.h\" ])\n"
49     "\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";
55
56 Value RunProcessFileTemplate(Scope* scope,
57                              const FunctionCallNode* function,
58                              const std::vector<Value>& args,
59                              Err* err) {
60   if (args.size() != 2) {
61     *err = Err(function->function(), "Expected two arguments");
62     return Value();
63   }
64
65   FileTemplate file_template(args[1], err);
66   if (err->has_error())
67     return Value();
68
69   Value ret(function, Value::LIST);
70   file_template.Apply(args[0], function, &ret.list_value(), err);
71   return ret;
72 }
73
74 }  // namespace functions