From b90606f4e40aa0bee5944164c44d7317a5a88318 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 30 May 2005 11:46:55 +0000 Subject: [PATCH] * Don't forget to apply the rewritten paths to the hash rewrite map that's applied to the environment variables / command-line arguments. Otherwise the builder will still use the unconsolidated paths. --- src/libstore/build.cc | 21 +++++++++++++++++++-- src/libstore/misc.cc | 16 ++++++++++++---- src/libstore/misc.hh | 5 ++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/src/libstore/build.cc b/src/libstore/build.cc index c20d3cbcc..ce4b59901 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -988,10 +988,27 @@ bool DerivationGoal::prepareBuild() different input closures might contain different paths from the *same* output path equivalence class. We should pick one from each, and rewrite dependent paths. */ - inputPaths = consolidatePaths(inputPaths, false); + Replacements replacements; + inputPaths = consolidatePaths(inputPaths, false, replacements); + HashRewrites rewrites2; + for (Replacements::iterator i = replacements.begin(); + i != replacements.end(); ++i) + { + printMsg(lvlError, format("FOO %1% %2%") + % i->first % i->second); + printMsg(lvlError, format("HASH REWRITE %1% %2%") + % hashPartOf(i->first).toString() % hashPartOf(i->second).toString()); + rewrites2[hashPartOf(i->first)] = hashPartOf(i->second); + } + + for (HashRewrites::iterator i = rewrites.begin(); + i != rewrites.end(); ++i) + rewrites[i->first] = PathHash(rewriteHashes(i->second.toString(), rewrites2)); + /* !!! remove, debug only */ - consolidatePaths(inputPaths, true); + Replacements dummy; + consolidatePaths(inputPaths, true, dummy); printMsg(lvlError, format("added input paths %1%") % showPaths(inputPaths)); /* !!! */ diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index ff443af17..009e0fd7d 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -104,9 +104,12 @@ static void findBestRewrite(const ClassMap::const_iterator & pos, static Path maybeRewrite(const Path & path, const PathSet & selection, - const FinalClassMap & finalClassMap) + const FinalClassMap & finalClassMap, + Replacements & replacements) { assert(selection.find(path) != selection.end()); + + if (replacements.find(path) != replacements.end()) return replacements[path]; PathSet references; queryReferences(noTxn, path, references); @@ -131,7 +134,8 @@ static Path maybeRewrite(const Path & path, const PathSet & selection, printMsg(lvlError, format("replacing with `%1%'") % j->second); - Path newPath = maybeRewrite(j->second, selection, finalClassMap); + Path newPath = maybeRewrite(j->second, selection, + finalClassMap, replacements); if (*i != newPath) rewrites[hashPartOf(*i)] = hashPartOf(newPath); } @@ -148,11 +152,14 @@ static Path maybeRewrite(const Path & path, const PathSet & selection, printMsg(lvlError, format("rewrote `%1%' to `%2%'") % path % newPath); + replacements[path] = newPath; + return newPath; } -PathSet consolidatePaths(const PathSet & paths, bool checkOnly) +PathSet consolidatePaths(const PathSet & paths, bool checkOnly, + Replacements & replacements) { printMsg(lvlError, format("consolidating")); @@ -199,9 +206,10 @@ PathSet consolidatePaths(const PathSet & paths, bool checkOnly) finalClassMap[i->first] = *j; PathSet newPaths; + replacements.clear(); for (PathSet::iterator i = bestSelection.begin(); i != bestSelection.end(); ++i) - newPaths.insert(maybeRewrite(*i, bestSelection, finalClassMap)); + newPaths.insert(maybeRewrite(*i, bestSelection, finalClassMap, replacements)); return newPaths; } diff --git a/src/libstore/misc.hh b/src/libstore/misc.hh index 57b2ab0bd..449b087af 100644 --- a/src/libstore/misc.hh +++ b/src/libstore/misc.hh @@ -33,7 +33,10 @@ Path findTrustedEqClassMember(const OutputEqClass & eqClass, const TrustId & trustId); -PathSet consolidatePaths(const PathSet & paths, bool checkOnly); +typedef map Replacements; + +PathSet consolidatePaths(const PathSet & paths, bool checkOnly, + Replacements & replacements); #endif /* !__MISC_H */