| 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/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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 return false; | 201 return false; |
| 202 } | 202 } |
| 203 | 203 |
| 204 if (!bad_records.empty()) { | 204 if (!bad_records.empty()) { |
| 205 // Our logic above found a bad node but didn't identify the problem. This | 205 // Our logic above found a bad node but didn't identify the problem. This |
| 206 // normally means a circular dependency. | 206 // normally means a circular dependency. |
| 207 depstring = CheckForCircularDependencies(bad_records); | 207 depstring = CheckForCircularDependencies(bad_records); |
| 208 if (depstring.empty()) { | 208 if (depstring.empty()) { |
| 209 // Something's very wrong, just dump out the bad nodes. | 209 // Something's very wrong, just dump out the bad nodes. |
| 210 depstring = "I have no idea what went wrong, but these are unresolved, " | 210 depstring = "I have no idea what went wrong, but these are unresolved, " |
| 211 "possible due to an\ninternal error:"; | 211 "possibly due to an\ninternal error:"; |
| 212 for (size_t i = 0; i < bad_records.size(); i++) { | 212 for (size_t i = 0; i < bad_records.size(); i++) { |
| 213 depstring += "\n\"" + | 213 depstring += "\n\"" + |
| 214 bad_records[i]->label().GetUserVisibleName(false) + "\""; | 214 bad_records[i]->label().GetUserVisibleName(false) + "\""; |
| 215 } | 215 } |
| 216 *err = Err(Location(), "", depstring); | 216 *err = Err(Location(), "", depstring); |
| 217 } else { | 217 } else { |
| 218 *err = Err(Location(), "Dependency cycle:", depstring); | 218 *err = Err(Location(), "Dependency cycle:", depstring); |
| 219 } | 219 } |
| 220 return false; | 220 return false; |
| 221 } | 221 } |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 | 519 |
| 520 return true; | 520 return true; |
| 521 } | 521 } |
| 522 | 522 |
| 523 std::string Builder::CheckForCircularDependencies( | 523 std::string Builder::CheckForCircularDependencies( |
| 524 const std::vector<const BuilderRecord*>& bad_records) const { | 524 const std::vector<const BuilderRecord*>& bad_records) const { |
| 525 std::vector<const BuilderRecord*> cycle; | 525 std::vector<const BuilderRecord*> cycle; |
| 526 if (!RecursiveFindCycle(bad_records[0], &cycle)) | 526 if (!RecursiveFindCycle(bad_records[0], &cycle)) |
| 527 return std::string(); // Didn't find a cycle, something else is wrong. | 527 return std::string(); // Didn't find a cycle, something else is wrong. |
| 528 | 528 |
| 529 // Walk backwards since the dependency arrows point in the reverse direction. | |
| 530 std::string ret; | 529 std::string ret; |
| 531 for (int i = static_cast<int>(cycle.size()) - 1; i >= 0; i--) { | 530 for (size_t i = 0; i < cycle.size(); i++) { |
| 532 ret += " " + cycle[i]->label().GetUserVisibleName(false); | 531 ret += " " + cycle[i]->label().GetUserVisibleName(false); |
| 533 if (i != 0) | 532 if (i != cycle.size() - 1) |
| 534 ret += " ->\n"; | 533 ret += " ->"; |
| 534 ret += "\n"; |
| 535 } | 535 } |
| 536 | 536 |
| 537 return ret; | 537 return ret; |
| 538 } | 538 } |
| OLD | NEW |