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

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

Issue 318383003: Improve error messages and reporting in GN (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
« no previous file with comments | « no previous file | tools/gn/builder_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/builder.h" 5 #include "tools/gn/builder.h"
6 6
7 #include "tools/gn/config.h" 7 #include "tools/gn/config.h"
8 #include "tools/gn/err.h" 8 #include "tools/gn/err.h"
9 #include "tools/gn/loader.h" 9 #include "tools/gn/loader.h"
10 #include "tools/gn/scheduler.h" 10 #include "tools/gn/scheduler.h"
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (!record) { 251 if (!record) {
252 // Not seen this record yet, create a new one. 252 // Not seen this record yet, create a new one.
253 record = new BuilderRecord(type, label); 253 record = new BuilderRecord(type, label);
254 record->set_originally_referenced_from(request_from); 254 record->set_originally_referenced_from(request_from);
255 records_[label] = record; 255 records_[label] = record;
256 return record; 256 return record;
257 } 257 }
258 258
259 // Check types. 259 // Check types.
260 if (record->type() != type) { 260 if (record->type() != type) {
261 *err = Err(request_from, "Item type does not match.", 261 std::string msg =
262 "The item \"" + label.GetUserVisibleName(false) + 262 "The type of " + label.GetUserVisibleName(false) +
263 "\"\nwas expected to be a " + 263 "\nhere is a " + BuilderRecord::GetNameForType(type) +
264 BuilderRecord::GetNameForType(type) + 264 " but was previously seen as a " +
265 " but was previously referenced as a " + 265 BuilderRecord::GetNameForType(record->type()) + ".\n\n"
266 BuilderRecord::GetNameForType(record->type())); 266 "The most common cause is that the label of a config was put in the\n"
267 "in the deps section of a target (or vice-versa).";
268 *err = Err(request_from, "Item type does not match.", msg);
267 if (record->originally_referenced_from()) { 269 if (record->originally_referenced_from()) {
268 err->AppendSubErr(Err(record->originally_referenced_from(), 270 err->AppendSubErr(Err(record->originally_referenced_from(),
269 "The previous reference was here.")); 271 std::string()));
270 } 272 }
271 return NULL; 273 return NULL;
272 } 274 }
273 275
274 return record; 276 return record;
275 } 277 }
276 278
277 BuilderRecord* Builder::GetResolvedRecordOfType(const Label& label, 279 BuilderRecord* Builder::GetResolvedRecordOfType(const Label& label,
278 const ParseNode* origin, 280 const ParseNode* origin,
279 BuilderRecord::ItemType type, 281 BuilderRecord::ItemType type,
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 i != deps.end(); i++) { 356 i != deps.end(); i++) {
355 BuilderRecord* cur = *i; 357 BuilderRecord* cur = *i;
356 if (!cur->should_generate()) { 358 if (!cur->should_generate()) {
357 ScheduleItemLoadIfNecessary(cur); 359 ScheduleItemLoadIfNecessary(cur);
358 RecursiveSetShouldGenerate(cur, false); 360 RecursiveSetShouldGenerate(cur, false);
359 } 361 }
360 } 362 }
361 } 363 }
362 364
363 void Builder::ScheduleItemLoadIfNecessary(BuilderRecord* record) { 365 void Builder::ScheduleItemLoadIfNecessary(BuilderRecord* record) {
364 loader_->Load(record->label()); 366 const ParseNode* origin = record->originally_referenced_from();
367 loader_->Load(record->label(),
368 origin ? origin->GetRange() : LocationRange());
365 } 369 }
366 370
367 bool Builder::ResolveItem(BuilderRecord* record, Err* err) { 371 bool Builder::ResolveItem(BuilderRecord* record, Err* err) {
368 DCHECK(record->can_resolve() && !record->resolved()); 372 DCHECK(record->can_resolve() && !record->resolved());
369 373
370 if (record->type() == BuilderRecord::ITEM_TARGET) { 374 if (record->type() == BuilderRecord::ITEM_TARGET) {
371 Target* target = record->item()->AsTarget(); 375 Target* target = record->item()->AsTarget();
372 if (!ResolveDeps(&target->deps(), err) || 376 if (!ResolveDeps(&target->deps(), err) ||
373 !ResolveDeps(&target->datadeps(), err) || 377 !ResolveDeps(&target->datadeps(), err) ||
374 !ResolveConfigs(&target->configs(), err) || 378 !ResolveConfigs(&target->configs(), err) ||
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // Walk backwards since the dependency arrows point in the reverse direction. 470 // Walk backwards since the dependency arrows point in the reverse direction.
467 std::string ret; 471 std::string ret;
468 for (int i = static_cast<int>(cycle.size()) - 1; i >= 0; i--) { 472 for (int i = static_cast<int>(cycle.size()) - 1; i >= 0; i--) {
469 ret += " " + cycle[i]->label().GetUserVisibleName(false); 473 ret += " " + cycle[i]->label().GetUserVisibleName(false);
470 if (i != 0) 474 if (i != 0)
471 ret += " ->\n"; 475 ret += " ->\n";
472 } 476 }
473 477
474 return ret; 478 return ret;
475 } 479 }
OLDNEW
« no previous file with comments | « no previous file | tools/gn/builder_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698