| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "tools/gn/config.h" | 10 #include "tools/gn/config.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 // participates in a cycle. | 26 // participates in a cycle. |
| 27 // | 27 // |
| 28 // If this returns true, the cycle will be in *path. This should point to an | 28 // If this returns true, the cycle will be in *path. This should point to an |
| 29 // empty vector for the first call. During computation, the path will contain | 29 // empty vector for the first call. During computation, the path will contain |
| 30 // the full dependency path to the current node. | 30 // the full dependency path to the current node. |
| 31 // | 31 // |
| 32 // Return false means no cycle was found. | 32 // Return false means no cycle was found. |
| 33 bool RecursiveFindCycle(const BuilderRecord* search_in, | 33 bool RecursiveFindCycle(const BuilderRecord* search_in, |
| 34 std::vector<const BuilderRecord*>* path) { | 34 std::vector<const BuilderRecord*>* path) { |
| 35 path->push_back(search_in); | 35 path->push_back(search_in); |
| 36 for (const auto& cur : search_in->unresolved_deps()) { | 36 for (auto* cur : search_in->unresolved_deps()) { |
| 37 std::vector<const BuilderRecord*>::iterator found = | 37 std::vector<const BuilderRecord*>::iterator found = |
| 38 std::find(path->begin(), path->end(), cur); | 38 std::find(path->begin(), path->end(), cur); |
| 39 if (found != path->end()) { | 39 if (found != path->end()) { |
| 40 // This item is already in the set, we found the cycle. Everything before | 40 // This item is already in the set, we found the cycle. Everything before |
| 41 // the first definition of cur is irrelevant to the cycle. | 41 // the first definition of cur is irrelevant to the cycle. |
| 42 path->erase(path->begin(), found); | 42 path->erase(path->begin(), found); |
| 43 path->push_back(cur); | 43 path->push_back(cur); |
| 44 return true; | 44 return true; |
| 45 } | 45 } |
| 46 | 46 |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 std::string depstring; | 175 std::string depstring; |
| 176 for (const auto& record_pair : records_) { | 176 for (const auto& record_pair : records_) { |
| 177 const BuilderRecord* src = record_pair.second; | 177 const BuilderRecord* src = record_pair.second; |
| 178 if (!src->should_generate()) | 178 if (!src->should_generate()) |
| 179 continue; // Skip ungenerated nodes. | 179 continue; // Skip ungenerated nodes. |
| 180 | 180 |
| 181 if (!src->resolved()) { | 181 if (!src->resolved()) { |
| 182 bad_records.push_back(src); | 182 bad_records.push_back(src); |
| 183 | 183 |
| 184 // Check dependencies. | 184 // Check dependencies. |
| 185 for (const auto& dest : src->unresolved_deps()) { | 185 for (auto* dest : src->unresolved_deps()) { |
| 186 if (!dest->item()) { | 186 if (!dest->item()) { |
| 187 depstring += src->label().GetUserVisibleName(true) + | 187 depstring += src->label().GetUserVisibleName(true) + |
| 188 "\n needs " + dest->label().GetUserVisibleName(true) + "\n"; | 188 "\n needs " + dest->label().GetUserVisibleName(true) + "\n"; |
| 189 } | 189 } |
| 190 } | 190 } |
| 191 } | 191 } |
| 192 } | 192 } |
| 193 | 193 |
| 194 if (!depstring.empty()) { | 194 if (!depstring.empty()) { |
| 195 *err = Err(Location(), "Unresolved dependencies.", depstring); | 195 *err = Err(Location(), "Unresolved dependencies.", depstring); |
| 196 return false; | 196 return false; |
| 197 } | 197 } |
| 198 | 198 |
| 199 if (!bad_records.empty()) { | 199 if (!bad_records.empty()) { |
| 200 // Our logic above found a bad node but didn't identify the problem. This | 200 // Our logic above found a bad node but didn't identify the problem. This |
| 201 // normally means a circular dependency. | 201 // normally means a circular dependency. |
| 202 depstring = CheckForCircularDependencies(bad_records); | 202 depstring = CheckForCircularDependencies(bad_records); |
| 203 if (depstring.empty()) { | 203 if (depstring.empty()) { |
| 204 // Something's very wrong, just dump out the bad nodes. | 204 // Something's very wrong, just dump out the bad nodes. |
| 205 depstring = "I have no idea what went wrong, but these are unresolved, " | 205 depstring = "I have no idea what went wrong, but these are unresolved, " |
| 206 "possibly due to an\ninternal error:"; | 206 "possibly due to an\ninternal error:"; |
| 207 for (const auto& bad_record : bad_records) { | 207 for (auto* bad_record : bad_records) { |
| 208 depstring += "\n\"" + | 208 depstring += "\n\"" + |
| 209 bad_record->label().GetUserVisibleName(false) + "\""; | 209 bad_record->label().GetUserVisibleName(false) + "\""; |
| 210 } | 210 } |
| 211 *err = Err(Location(), "", depstring); | 211 *err = Err(Location(), "", depstring); |
| 212 } else { | 212 } else { |
| 213 *err = Err(Location(), "Dependency cycle:", depstring); | 213 *err = Err(Location(), "Dependency cycle:", depstring); |
| 214 } | 214 } |
| 215 return false; | 215 return false; |
| 216 } | 216 } |
| 217 | 217 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 245 if (!AddDeps(record, config->configs(), err)) | 245 if (!AddDeps(record, config->configs(), err)) |
| 246 return false; | 246 return false; |
| 247 | 247 |
| 248 // Make sure all deps of this config are scheduled to be loaded. For other | 248 // Make sure all deps of this config are scheduled to be loaded. For other |
| 249 // item types like targets, the "should generate" flag is propagated around | 249 // item types like targets, the "should generate" flag is propagated around |
| 250 // to mark whether this should happen. We could call | 250 // to mark whether this should happen. We could call |
| 251 // RecursiveSetShouldGenerate to do this step here, but since configs nor | 251 // RecursiveSetShouldGenerate to do this step here, but since configs nor |
| 252 // anything they depend on is actually written, the "generate" flag isn't | 252 // anything they depend on is actually written, the "generate" flag isn't |
| 253 // relevant and means extra book keeping. Just force load any deps of this | 253 // relevant and means extra book keeping. Just force load any deps of this |
| 254 // config. | 254 // config. |
| 255 for (const auto& cur : record->all_deps()) | 255 for (auto* cur : record->all_deps()) |
| 256 ScheduleItemLoadIfNecessary(cur); | 256 ScheduleItemLoadIfNecessary(cur); |
| 257 | 257 |
| 258 return true; | 258 return true; |
| 259 } | 259 } |
| 260 | 260 |
| 261 bool Builder::ToolchainDefined(BuilderRecord* record, Err* err) { | 261 bool Builder::ToolchainDefined(BuilderRecord* record, Err* err) { |
| 262 Toolchain* toolchain = record->item()->AsToolchain(); | 262 Toolchain* toolchain = record->item()->AsToolchain(); |
| 263 | 263 |
| 264 if (!AddDeps(record, toolchain->deps(), err)) | 264 if (!AddDeps(record, toolchain->deps(), err)) |
| 265 return false; | 265 return false; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 401 |
| 402 return true; | 402 return true; |
| 403 } | 403 } |
| 404 | 404 |
| 405 void Builder::RecursiveSetShouldGenerate(BuilderRecord* record, | 405 void Builder::RecursiveSetShouldGenerate(BuilderRecord* record, |
| 406 bool force) { | 406 bool force) { |
| 407 if (!force && record->should_generate()) | 407 if (!force && record->should_generate()) |
| 408 return; // Already set. | 408 return; // Already set. |
| 409 record->set_should_generate(true); | 409 record->set_should_generate(true); |
| 410 | 410 |
| 411 for (const auto& cur : record->all_deps()) { | 411 for (auto* cur : record->all_deps()) { |
| 412 if (!cur->should_generate()) { | 412 if (!cur->should_generate()) { |
| 413 ScheduleItemLoadIfNecessary(cur); | 413 ScheduleItemLoadIfNecessary(cur); |
| 414 RecursiveSetShouldGenerate(cur, false); | 414 RecursiveSetShouldGenerate(cur, false); |
| 415 } | 415 } |
| 416 } | 416 } |
| 417 } | 417 } |
| 418 | 418 |
| 419 void Builder::ScheduleItemLoadIfNecessary(BuilderRecord* record) { | 419 void Builder::ScheduleItemLoadIfNecessary(BuilderRecord* record) { |
| 420 const ParseNode* origin = record->originally_referenced_from(); | 420 const ParseNode* origin = record->originally_referenced_from(); |
| 421 loader_->Load(record->label(), | 421 loader_->Load(record->label(), |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 std::string ret; | 545 std::string ret; |
| 546 for (size_t i = 0; i < cycle.size(); i++) { | 546 for (size_t i = 0; i < cycle.size(); i++) { |
| 547 ret += " " + cycle[i]->label().GetUserVisibleName(false); | 547 ret += " " + cycle[i]->label().GetUserVisibleName(false); |
| 548 if (i != cycle.size() - 1) | 548 if (i != cycle.size() - 1) |
| 549 ret += " ->"; | 549 ret += " ->"; |
| 550 ret += "\n"; | 550 ret += "\n"; |
| 551 } | 551 } |
| 552 | 552 |
| 553 return ret; | 553 return ret; |
| 554 } | 554 } |
| OLD | NEW |