Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: tools/gn/substitution_writer.cc

Issue 462103004: GN: Bug fixes in process_file_template (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 } 122 }
123 123
124 SubstitutionWriter::~SubstitutionWriter() { 124 SubstitutionWriter::~SubstitutionWriter() {
125 } 125 }
126 126
127 // static 127 // static
128 SourceFile SubstitutionWriter::ApplyPatternToSource( 128 SourceFile SubstitutionWriter::ApplyPatternToSource(
129 const Settings* settings, 129 const Settings* settings,
130 const SubstitutionPattern& pattern, 130 const SubstitutionPattern& pattern,
131 const SourceFile& source) { 131 const SourceFile& source) {
132 std::string result_value = ApplyPatternToSourceAsString(
133 settings, pattern, source);
134 CHECK(!result_value.empty() && result_value[0] == '/')
135 << "The result of the pattern \""
136 << pattern.AsString()
137 << "\" was not a path beginning in \"/\" or \"//\".";
138 return SourceFile(SourceFile::SWAP_IN, &result_value);
139 }
140
141 // static
142 std::string SubstitutionWriter::ApplyPatternToSourceAsString(
143 const Settings* settings,
144 const SubstitutionPattern& pattern,
145 const SourceFile& source) {
132 std::string result_value; 146 std::string result_value;
133 for (size_t i = 0; i < pattern.ranges().size(); i++) { 147 for (size_t i = 0; i < pattern.ranges().size(); i++) {
134 const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i]; 148 const SubstitutionPattern::Subrange& subrange = pattern.ranges()[i];
135 if (subrange.type == SUBSTITUTION_LITERAL) { 149 if (subrange.type == SUBSTITUTION_LITERAL) {
136 result_value.append(subrange.literal); 150 result_value.append(subrange.literal);
137 } else { 151 } else {
138 result_value.append( 152 result_value.append(
139 GetSourceSubstitution(settings, source, subrange.type, 153 GetSourceSubstitution(settings, source, subrange.type,
140 OUTPUT_ABSOLUTE, SourceDir())); 154 OUTPUT_ABSOLUTE, SourceDir()));
141 } 155 }
142 } 156 }
143 CHECK(!result_value.empty() && result_value[0] == '/') 157 return result_value;
144 << "The result of the pattern \""
145 << pattern.AsString()
146 << "\" was not a path beginning in \"/\" or \"//\".";
147 return SourceFile(SourceFile::SWAP_IN, &result_value);
148 } 158 }
149 159
150 // static 160 // static
151 OutputFile SubstitutionWriter::ApplyPatternToSourceAsOutputFile( 161 OutputFile SubstitutionWriter::ApplyPatternToSourceAsOutputFile(
152 const Settings* settings, 162 const Settings* settings,
153 const SubstitutionPattern& pattern, 163 const SubstitutionPattern& pattern,
154 const SourceFile& source) { 164 const SourceFile& source) {
155 SourceFile result_as_source = ApplyPatternToSource(settings, pattern, source); 165 SourceFile result_as_source = ApplyPatternToSource(settings, pattern, source);
156 CHECK(result_as_source.is_source_absolute()) 166 CHECK(result_as_source.is_source_absolute())
157 << "The result of the pattern \"" 167 << "The result of the pattern \""
(...skipping 10 matching lines...) Expand all
168 const SubstitutionList& list, 178 const SubstitutionList& list,
169 const SourceFile& source, 179 const SourceFile& source,
170 std::vector<SourceFile>* output) { 180 std::vector<SourceFile>* output) {
171 for (size_t i = 0; i < list.list().size(); i++) { 181 for (size_t i = 0; i < list.list().size(); i++) {
172 output->push_back(ApplyPatternToSource( 182 output->push_back(ApplyPatternToSource(
173 settings, list.list()[i], source)); 183 settings, list.list()[i], source));
174 } 184 }
175 } 185 }
176 186
177 // static 187 // static
188 void SubstitutionWriter::ApplyListToSourceAsString(
189 const Settings* settings,
190 const SubstitutionList& list,
191 const SourceFile& source,
192 std::vector<std::string>* output) {
193 for (size_t i = 0; i < list.list().size(); i++) {
194 output->push_back(ApplyPatternToSourceAsString(
195 settings, list.list()[i], source));
196 }
197 }
198
199 // static
178 void SubstitutionWriter::ApplyListToSourceAsOutputFile( 200 void SubstitutionWriter::ApplyListToSourceAsOutputFile(
179 const Settings* settings, 201 const Settings* settings,
180 const SubstitutionList& list, 202 const SubstitutionList& list,
181 const SourceFile& source, 203 const SourceFile& source,
182 std::vector<OutputFile>* output) { 204 std::vector<OutputFile>* output) {
183 for (size_t i = 0; i < list.list().size(); i++) { 205 for (size_t i = 0; i < list.list().size(); i++) {
184 output->push_back(ApplyPatternToSourceAsOutputFile( 206 output->push_back(ApplyPatternToSourceAsOutputFile(
185 settings, list.list()[i], source)); 207 settings, list.list()[i], source));
186 } 208 }
187 } 209 }
188 210
189 // static 211 // static
190 void SubstitutionWriter::ApplyListToSources( 212 void SubstitutionWriter::ApplyListToSources(
191 const Settings* settings, 213 const Settings* settings,
192 const SubstitutionList& list, 214 const SubstitutionList& list,
193 const std::vector<SourceFile>& sources, 215 const std::vector<SourceFile>& sources,
194 std::vector<SourceFile>* output) { 216 std::vector<SourceFile>* output) {
195 output->clear(); 217 output->clear();
196 for (size_t i = 0; i < sources.size(); i++) 218 for (size_t i = 0; i < sources.size(); i++)
197 ApplyListToSource(settings, list, sources[i], output); 219 ApplyListToSource(settings, list, sources[i], output);
198 } 220 }
199 221
200 // static 222 // static
223 void SubstitutionWriter::ApplyListToSourcesAsString(
224 const Settings* settings,
225 const SubstitutionList& list,
226 const std::vector<SourceFile>& sources,
227 std::vector<std::string>* output) {
228 output->clear();
229 for (size_t i = 0; i < sources.size(); i++)
230 ApplyListToSourceAsString(settings, list, sources[i], output);
231 }
232
233 // static
201 void SubstitutionWriter::ApplyListToSourcesAsOutputFile( 234 void SubstitutionWriter::ApplyListToSourcesAsOutputFile(
202 const Settings* settings, 235 const Settings* settings,
203 const SubstitutionList& list, 236 const SubstitutionList& list,
204 const std::vector<SourceFile>& sources, 237 const std::vector<SourceFile>& sources,
205 std::vector<OutputFile>* output) { 238 std::vector<OutputFile>* output) {
206 output->clear(); 239 output->clear();
207 for (size_t i = 0; i < sources.size(); i++) 240 for (size_t i = 0; i < sources.size(); i++)
208 ApplyListToSourceAsOutputFile(settings, list, sources[i], output); 241 ApplyListToSourceAsOutputFile(settings, list, sources[i], output);
209 } 242 }
210 243
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 return std::string(); 341 return std::string();
309 } 342 }
310 343
311 // If we get here, the result is a path that should be made relative or 344 // 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 345 // absolute according to the output_style. Other cases (just file name or
313 // extension extraction) will have been handled via early return above. 346 // extension extraction) will have been handled via early return above.
314 if (output_style == OUTPUT_ABSOLUTE) 347 if (output_style == OUTPUT_ABSOLUTE)
315 return to_rebase; 348 return to_rebase;
316 return RebaseSourceAbsolutePath(to_rebase, relative_to); 349 return RebaseSourceAbsolutePath(to_rebase, relative_to);
317 } 350 }
OLDNEW
« tools/gn/function_process_file_template.cc ('K') | « tools/gn/substitution_writer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698