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/functions.h" | 5 #include "tools/gn/functions.h" |
6 #include "tools/gn/parse_tree.h" | 6 #include "tools/gn/parse_tree.h" |
7 #include "tools/gn/scope.h" | 7 #include "tools/gn/scope.h" |
8 #include "tools/gn/settings.h" | 8 #include "tools/gn/settings.h" |
9 #include "tools/gn/substitution_list.h" | 9 #include "tools/gn/substitution_list.h" |
10 #include "tools/gn/substitution_writer.h" | 10 #include "tools/gn/substitution_writer.h" |
11 #include "tools/gn/target.h" | 11 #include "tools/gn/target.h" |
12 #include "tools/gn/value_extractors.h" | 12 #include "tools/gn/value_extractors.h" |
13 | 13 |
14 namespace functions { | 14 namespace functions { |
15 | 15 |
16 const char kProcessFileTemplate[] = "process_file_template"; | 16 const char kProcessFileTemplate[] = "process_file_template"; |
17 const char kProcessFileTemplate_HelpShort[] = | 17 const char kProcessFileTemplate_HelpShort[] = |
18 "process_file_template: Do template expansion over a list of files."; | 18 "process_file_template: Do template expansion over a list of files."; |
19 const char kProcessFileTemplate_Help[] = | 19 const char kProcessFileTemplate_Help[] = |
20 "process_file_template: Do template expansion over a list of files.\n" | 20 R"(process_file_template: Do template expansion over a list of files. |
21 "\n" | 21 |
22 " process_file_template(source_list, template)\n" | 22 process_file_template(source_list, template) |
23 "\n" | 23 |
24 " process_file_template applies a template list to a source file list,\n" | 24 process_file_template applies a template list to a source file list, |
25 " returning the result of applying each template to each source. This is\n" | 25 returning the result of applying each template to each source. This is |
26 " typically used for computing output file names from input files.\n" | 26 typically used for computing output file names from input files. |
27 "\n" | 27 |
28 " In most cases, get_target_outputs() will give the same result with\n" | 28 In most cases, get_target_outputs() will give the same result with shorter, |
29 " shorter, more maintainable code. This function should only be used\n" | 29 more maintainable code. This function should only be used when that function |
30 " when that function can't be used (like there's no target or the target\n" | 30 can't be used (like there's no target or the target is defined in another |
31 " is defined in another build file).\n" | 31 build file). |
32 "\n" | 32 |
33 "Arguments:\n" | 33 Arguments |
34 "\n" | 34 |
35 " The source_list is a list of file names.\n" | 35 The source_list is a list of file names. |
36 "\n" | 36 |
37 " The template can be a string or a list. If it is a list, multiple\n" | 37 The template can be a string or a list. If it is a list, multiple output |
38 " output strings are generated for each input.\n" | 38 strings are generated for each input. |
39 "\n" | 39 |
40 " The template should contain source expansions to which each name in\n" | 40 The template should contain source expansions to which each name in the |
41 " the source list is applied. See \"gn help source_expansion\".\n" | 41 source list is applied. See "gn help source_expansion". |
42 "\n" | 42 |
43 "Example:\n" | 43 Example |
44 "\n" | 44 |
45 " sources = [\n" | 45 sources = [ |
46 " \"foo.idl\",\n" | 46 "foo.idl", |
47 " \"bar.idl\",\n" | 47 "bar.idl", |
48 " ]\n" | 48 ] |
49 " myoutputs = process_file_template(\n" | 49 myoutputs = process_file_template( |
50 " sources,\n" | 50 sources, |
51 " [ \"$target_gen_dir/{{source_name_part}}.cc\",\n" | 51 [ "$target_gen_dir/{{source_name_part}}.cc", |
52 " \"$target_gen_dir/{{source_name_part}}.h\" ])\n" | 52 "$target_gen_dir/{{source_name_part}}.h" ]) |
53 "\n" | 53 |
54 " The result in this case will be:\n" | 54 The result in this case will be: |
55 " [ \"//out/Debug/foo.cc\"\n" | 55 [ "//out/Debug/foo.cc" |
56 " \"//out/Debug/foo.h\"\n" | 56 "//out/Debug/foo.h" |
57 " \"//out/Debug/bar.cc\"\n" | 57 "//out/Debug/bar.cc" |
58 " \"//out/Debug/bar.h\" ]\n"; | 58 "//out/Debug/bar.h" ])"; |
59 | 59 |
60 Value RunProcessFileTemplate(Scope* scope, | 60 Value RunProcessFileTemplate(Scope* scope, |
61 const FunctionCallNode* function, | 61 const FunctionCallNode* function, |
62 const std::vector<Value>& args, | 62 const std::vector<Value>& args, |
63 Err* err) { | 63 Err* err) { |
64 if (args.size() != 2) { | 64 if (args.size() != 2) { |
65 *err = Err(function->function(), "Expected two arguments"); | 65 *err = Err(function->function(), "Expected two arguments"); |
66 return Value(); | 66 return Value(); |
67 } | 67 } |
68 | 68 |
(...skipping 29 matching lines...) Expand all Loading... |
98 // Convert the list of strings to the return Value. | 98 // Convert the list of strings to the return Value. |
99 Value ret(function, Value::LIST); | 99 Value ret(function, Value::LIST); |
100 ret.list_value().reserve(result_files.size()); | 100 ret.list_value().reserve(result_files.size()); |
101 for (const auto& file : result_files) | 101 for (const auto& file : result_files) |
102 ret.list_value().push_back(Value(function, file)); | 102 ret.list_value().push_back(Value(function, file)); |
103 | 103 |
104 return ret; | 104 return ret; |
105 } | 105 } |
106 | 106 |
107 } // namespace functions | 107 } // namespace functions |
OLD | NEW |