If a build A depends on a derivation that is the top-level derivation of some build B, then we should process B before A (meaning we shouldn't make the derivation runnable before B has been added). Otherwise, the derivation will be "accounted" to A rather than B (so the build step will show up in the wrong build).
JAUB2FT5SNQWXR24TWTOHVT6UUJ6OQPAFPBZIQAQBHVWHWWFHLYAC HHOMBU7GGRAEXODSDY3WUHQGOSQ35OTGRNBWKKAS2D4YEIZTTNUAC ENXUSMSVOU3AZFMH2ZXR4ZVPV2LRRQYQJ6IFX33YN6IH2ORSNSAAC 24BMQDZAWDQ7VNIA7TIROXSOYLOJBNZ2E4264WHWNJAEN6ZB3UOAC GKZN4UV75GV7GEHQGBM2O6UHN6CVSHA7BMASCUQSDIDYVUKKZL7AC 22LDPAIPRVSZVZXEDCM54GUOH72VQ52EIY47PQV2VELZ3NORC5IQC N5O7VEEOY2IE27VCOYRBG7YCY3K7JMQEDEMRT4OQ2MUE3NWULHHQC IWB3F4Z6QZYHQFJ6FWZTGWLCPBYEUTFLUS3F7QT7JOA4DV4YLYGAC 5AIYUMTBY6TFQTBRP3MJ2PYWUMRF57I77NIVWYE74UMEVQMBWZVQC /* Now instantiate build steps for each new build. The builderthreads can start building the runnable build steps right away,even while we're still processing other new builds. */for (auto & build : newBuilds) {// FIXME: remove build from newBuilds to ensure quick destruction// FIXME: exception handling
std::set<Step::ptr> newRunnable;unsigned int nrAdded;std::function<void(Build::ptr)> createBuild;
/* Some of the new steps may be the top level of builds thatwe haven't processed yet. So do them now. This ensures thatif build A depends on build B with top-level step X, then Xwill be "accounted" to B in doBuildStep(). */for (auto & r : newSteps) {while (true) {auto i = newBuilds.find(r->drvPath);if (i == newBuilds.end()) break;Build::ptr b = i->second;newBuilds.erase(i);createBuild(b);}}
printMsg(lvlChatty, format("added build %1% (top-level step %2%, %3% new steps, %4% new runnable steps)")% build->id % step->drvPath % newSteps.size() % newRunnable.size());
printMsg(lvlChatty, format("added build %1% (top-level step %2%, %3% new steps)")% build->id % step->drvPath % newSteps.size());
};/* Now instantiate build steps for each new build. The builderthreads can start building the runnable build steps right away,even while we're still processing other new builds. */while (!newBuilds.empty()) {auto build = newBuilds.begin()->second;newBuilds.erase(newBuilds.begin());newRunnable.clear();nrAdded = 0;createBuild(build);