OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/substitution_writer.h" | 5 #include "tools/gn/substitution_writer.h" |
6 | 6 |
7 #include "tools/gn/build_settings.h" | 7 #include "tools/gn/build_settings.h" |
8 #include "tools/gn/escape.h" | 8 #include "tools/gn/escape.h" |
9 #include "tools/gn/filesystem_utils.h" | 9 #include "tools/gn/filesystem_utils.h" |
10 #include "tools/gn/output_file.h" | 10 #include "tools/gn/output_file.h" |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 " //out/Debug/obj/mydirectory/input2.h\n" | 118 " //out/Debug/obj/mydirectory/input2.h\n" |
119 " //out/Debug/obj/mydirectory/input2.cc\n"; | 119 " //out/Debug/obj/mydirectory/input2.cc\n"; |
120 | 120 |
121 SubstitutionWriter::SubstitutionWriter() { | 121 SubstitutionWriter::SubstitutionWriter() { |
122 } | 122 } |
123 | 123 |
124 SubstitutionWriter::~SubstitutionWriter() { | 124 SubstitutionWriter::~SubstitutionWriter() { |
125 } | 125 } |
126 | 126 |
127 // static | 127 // static |
| 128 void SubstitutionWriter::GetListAsSourceFiles( |
| 129 const Settings* settings, |
| 130 const SubstitutionList& list, |
| 131 std::vector<SourceFile>* output) { |
| 132 for (size_t i = 0; i < list.list().size(); i++) { |
| 133 const SubstitutionPattern& pattern = list.list()[i]; |
| 134 CHECK(pattern.ranges().size() == 1 && |
| 135 pattern.ranges()[0].type == SUBSTITUTION_LITERAL) |
| 136 << "The substitution patterm \"" |
| 137 << pattern.AsString() |
| 138 << "\" was expected to be a literal with no {{substitutions}}."; |
| 139 const std::string& literal = pattern.ranges()[0].literal; |
| 140 CHECK(literal.size() >= 1 && literal[0] == '/') |
| 141 << "The result of the pattern \"" |
| 142 << pattern.AsString() |
| 143 << "\" was not an absolute path."; |
| 144 output->push_back(SourceFile(literal)); |
| 145 } |
| 146 } |
| 147 |
| 148 void SubstitutionWriter::GetListAsOutputFiles( |
| 149 const Settings* settings, |
| 150 const SubstitutionList& list, |
| 151 std::vector<OutputFile>* output) { |
| 152 std::vector<SourceFile> output_as_sources; |
| 153 GetListAsSourceFiles(settings, list, &output_as_sources); |
| 154 for (size_t i = 0; i < output_as_sources.size(); i++) { |
| 155 output->push_back(OutputFile( |
| 156 RebaseSourceAbsolutePath(output_as_sources[i].value(), |
| 157 settings->build_settings()->build_dir()))); |
| 158 } |
| 159 } |
| 160 |
| 161 // static |
128 SourceFile SubstitutionWriter::ApplyPatternToSource( | 162 SourceFile SubstitutionWriter::ApplyPatternToSource( |
129 const Settings* settings, | 163 const Settings* settings, |
130 const SubstitutionPattern& pattern, | 164 const SubstitutionPattern& pattern, |
131 const SourceFile& source) { | 165 const SourceFile& source) { |
132 std::string result_value; | 166 std::string result_value; |
133 for (size_t i = 0; i < pattern.ranges().size(); i++) { | 167 for (size_t i = 0; i < pattern.ranges().size(); i++) { |
134 const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i]; | 168 const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i]; |
135 if (subrange.type == SUBSTITUTION_LITERAL) { | 169 if (subrange.type == SUBSTITUTION_LITERAL) { |
136 result_value.append(subrange.literal); | 170 result_value.append(subrange.literal); |
137 } else { | 171 } else { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 return std::string(); | 342 return std::string(); |
309 } | 343 } |
310 | 344 |
311 // If we get here, the result is a path that should be made relative or | 345 // If we get here, the result is a path that should be made relative or |
312 // absolute according to the output_style. Other cases (just file name or | 346 // absolute according to the output_style. Other cases (just file name or |
313 // extension extraction) will have been handled via early return above. | 347 // extension extraction) will have been handled via early return above. |
314 if (output_style == OUTPUT_ABSOLUTE) | 348 if (output_style == OUTPUT_ABSOLUTE) |
315 return to_rebase; | 349 return to_rebase; |
316 return RebaseSourceAbsolutePath(to_rebase, relative_to); | 350 return RebaseSourceAbsolutePath(to_rebase, relative_to); |
317 } | 351 } |
OLD | NEW |