| 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" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 " when that function can't be used (like there's no target or the target\n" | 30 " when that function can't be used (like there's no target or the target\n" |
| 31 " is defined in another build file).\n" | 31 " is defined in another build file).\n" |
| 32 "\n" | 32 "\n" |
| 33 "Arguments:\n" | 33 "Arguments:\n" |
| 34 "\n" | 34 "\n" |
| 35 " The source_list is a list of file names.\n" | 35 " The source_list is a list of file names.\n" |
| 36 "\n" | 36 "\n" |
| 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\n" |
| 38 " output strings are generated for each input.\n" | 38 " output strings are generated for each input.\n" |
| 39 "\n" | 39 "\n" |
| 40 " The following template substrings are used in the template arguments\n" | 40 " The template should contain source expansions to which each name in\n" |
| 41 " and are replaced with the corresponding part of the input file name:\n" | 41 " the source list is applied. See \"gn help source_expansion\".\n" |
| 42 "\n" | |
| 43 " {{source}}\n" | |
| 44 " The entire source name.\n" | |
| 45 "\n" | |
| 46 " {{source_name_part}}\n" | |
| 47 " The source name with no path or extension.\n" | |
| 48 "\n" | 42 "\n" |
| 49 "Example:\n" | 43 "Example:\n" |
| 50 "\n" | 44 "\n" |
| 51 " sources = [\n" | 45 " sources = [\n" |
| 52 " \"foo.idl\",\n" | 46 " \"foo.idl\",\n" |
| 53 " \"bar.idl\",\n" | 47 " \"bar.idl\",\n" |
| 54 " ]\n" | 48 " ]\n" |
| 55 " myoutputs = process_file_template(\n" | 49 " myoutputs = process_file_template(\n" |
| 56 " sources,\n" | 50 " sources,\n" |
| 57 " [ \"$target_gen_dir/{{source_name_part}}.cc\",\n" | 51 " [ \"$target_gen_dir/{{source_name_part}}.cc\",\n" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 71 *err = Err(function->function(), "Expected two arguments"); | 65 *err = Err(function->function(), "Expected two arguments"); |
| 72 return Value(); | 66 return Value(); |
| 73 } | 67 } |
| 74 | 68 |
| 75 // Source list. | 69 // Source list. |
| 76 Target::FileList input_files; | 70 Target::FileList input_files; |
| 77 if (!ExtractListOfRelativeFiles(scope->settings()->build_settings(), args[0], | 71 if (!ExtractListOfRelativeFiles(scope->settings()->build_settings(), args[0], |
| 78 scope->GetSourceDir(), &input_files, err)) | 72 scope->GetSourceDir(), &input_files, err)) |
| 79 return Value(); | 73 return Value(); |
| 80 | 74 |
| 75 std::vector<std::string> result_files; |
| 76 SubstitutionList subst; |
| 77 |
| 81 // Template. | 78 // Template. |
| 82 SubstitutionList subst; | 79 const Value& template_arg = args[1]; |
| 83 if (!subst.Parse(args[1], err)) | 80 if (template_arg.type() == Value::STRING) { |
| 81 // Convert the string to a SubstitutionList with one pattern in it to |
| 82 // simplify the code below. |
| 83 std::vector<std::string> list; |
| 84 list.push_back(template_arg.string_value()); |
| 85 if (!subst.Parse(list, template_arg.origin(), err)) |
| 86 return Value(); |
| 87 } else if (template_arg.type() == Value::LIST) { |
| 88 if (!subst.Parse(template_arg, err)) |
| 89 return Value(); |
| 90 } else { |
| 91 *err = Err(template_arg, "Not a string or a list."); |
| 84 return Value(); | 92 return Value(); |
| 93 } |
| 85 | 94 |
| 86 std::vector<SourceFile> result_files; | 95 SubstitutionWriter::ApplyListToSourcesAsString( |
| 87 SubstitutionWriter::ApplyListToSources( | |
| 88 scope->settings(), subst, input_files, &result_files); | 96 scope->settings(), subst, input_files, &result_files); |
| 89 | 97 |
| 98 // Convert the list of strings to the return Value. |
| 90 Value ret(function, Value::LIST); | 99 Value ret(function, Value::LIST); |
| 91 ret.list_value().reserve(result_files.size()); | 100 ret.list_value().reserve(result_files.size()); |
| 92 for (size_t i = 0; i < result_files.size(); i++) | 101 for (size_t i = 0; i < result_files.size(); i++) |
| 93 ret.list_value().push_back(Value(function, result_files[i].value())); | 102 ret.list_value().push_back(Value(function, result_files[i])); |
| 94 | 103 |
| 95 return ret; | 104 return ret; |
| 96 } | 105 } |
| 97 | 106 |
| 98 } // namespace functions | 107 } // namespace functions |
| OLD | NEW |