| 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/file_template.h" | 5 #include "tools/gn/file_template.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <iostream> | 8 #include <iostream> |
| 9 | 9 |
| 10 #include "tools/gn/escape.h" | 10 #include "tools/gn/escape.h" |
| 11 #include "tools/gn/filesystem_utils.h" | 11 #include "tools/gn/filesystem_utils.h" |
| 12 #include "tools/gn/string_utils.h" |
| 13 #include "tools/gn/target.h" |
| 12 | 14 |
| 13 const char FileTemplate::kSource[] = "{{source}}"; | 15 const char FileTemplate::kSource[] = "{{source}}"; |
| 14 const char FileTemplate::kSourceNamePart[] = "{{source_name_part}}"; | 16 const char FileTemplate::kSourceNamePart[] = "{{source_name_part}}"; |
| 15 const char FileTemplate::kSourceFilePart[] = "{{source_file_part}}"; | 17 const char FileTemplate::kSourceFilePart[] = "{{source_file_part}}"; |
| 16 | 18 |
| 17 const char kSourceExpansion_Help[] = | 19 const char kSourceExpansion_Help[] = |
| 18 "How Source Expansion Works\n" | 20 "How Source Expansion Works\n" |
| 19 "\n" | 21 "\n" |
| 20 " Source expansion is used for the custom script and copy target types\n" | 22 " Source expansion is used for the custom script and copy target types\n" |
| 21 " to map source file names to output file names or arguments.\n" | 23 " to map source file names to output file names or arguments.\n" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 FileTemplate::FileTemplate(const std::vector<std::string>& t) | 87 FileTemplate::FileTemplate(const std::vector<std::string>& t) |
| 86 : has_substitutions_(false) { | 88 : has_substitutions_(false) { |
| 87 std::fill(types_required_, &types_required_[Subrange::NUM_TYPES], false); | 89 std::fill(types_required_, &types_required_[Subrange::NUM_TYPES], false); |
| 88 for (size_t i = 0; i < t.size(); i++) | 90 for (size_t i = 0; i < t.size(); i++) |
| 89 ParseOneTemplateString(t[i]); | 91 ParseOneTemplateString(t[i]); |
| 90 } | 92 } |
| 91 | 93 |
| 92 FileTemplate::~FileTemplate() { | 94 FileTemplate::~FileTemplate() { |
| 93 } | 95 } |
| 94 | 96 |
| 97 // static |
| 98 FileTemplate FileTemplate::GetForTargetOutputs(const Target* target) { |
| 99 const Target::FileList& outputs = target->script_values().outputs(); |
| 100 std::vector<std::string> output_template_args; |
| 101 for (size_t i = 0; i < outputs.size(); i++) |
| 102 output_template_args.push_back(outputs[i].value()); |
| 103 return FileTemplate(output_template_args); |
| 104 } |
| 105 |
| 95 bool FileTemplate::IsTypeUsed(Subrange::Type type) const { | 106 bool FileTemplate::IsTypeUsed(Subrange::Type type) const { |
| 96 DCHECK(type > Subrange::LITERAL && type < Subrange::NUM_TYPES); | 107 DCHECK(type > Subrange::LITERAL && type < Subrange::NUM_TYPES); |
| 97 return types_required_[type]; | 108 return types_required_[type]; |
| 98 } | 109 } |
| 99 | 110 |
| 100 void FileTemplate::Apply(const Value& sources, | 111 void FileTemplate::Apply(const Value& sources, |
| 101 const ParseNode* origin, | 112 const ParseNode* origin, |
| 102 std::vector<Value>* dest, | 113 std::vector<Value>* dest, |
| 103 Err* err) const { | 114 Err* err) const { |
| 104 if (!sources.VerifyTypeIs(Value::LIST, err)) | 115 if (!sources.VerifyTypeIs(Value::LIST, err)) |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 cur = next + arraysize(kSourceFilePart) - 1; | 295 cur = next + arraysize(kSourceFilePart) - 1; |
| 285 } else { | 296 } else { |
| 286 // If it's not a match, treat it like a one-char literal (this will be | 297 // If it's not a match, treat it like a one-char literal (this will be |
| 287 // rare, so it's not worth the bother to add to the previous literal) so | 298 // rare, so it's not worth the bother to add to the previous literal) so |
| 288 // we can keep going. | 299 // we can keep going. |
| 289 t.container().push_back(Subrange(Subrange::LITERAL, "{")); | 300 t.container().push_back(Subrange(Subrange::LITERAL, "{")); |
| 290 cur = next + 1; | 301 cur = next + 1; |
| 291 } | 302 } |
| 292 } | 303 } |
| 293 } | 304 } |
| OLD | NEW |