mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 12:10:59 +01:00
* Handle the case where all the direct references of a path are in the
selection but some indirect reference isn't (in which case the path should still be rewritten).
This commit is contained in:
parent
b90606f4e4
commit
48190ccfca
2 changed files with 33 additions and 26 deletions
|
|
@ -995,8 +995,6 @@ bool DerivationGoal::prepareBuild()
|
||||||
for (Replacements::iterator i = replacements.begin();
|
for (Replacements::iterator i = replacements.begin();
|
||||||
i != replacements.end(); ++i)
|
i != replacements.end(); ++i)
|
||||||
{
|
{
|
||||||
printMsg(lvlError, format("FOO %1% %2%")
|
|
||||||
% i->first % i->second);
|
|
||||||
printMsg(lvlError, format("HASH REWRITE %1% %2%")
|
printMsg(lvlError, format("HASH REWRITE %1% %2%")
|
||||||
% hashPartOf(i->first).toString() % hashPartOf(i->second).toString());
|
% hashPartOf(i->first).toString() % hashPartOf(i->second).toString());
|
||||||
rewrites2[hashPartOf(i->first)] = hashPartOf(i->second);
|
rewrites2[hashPartOf(i->first)] = hashPartOf(i->second);
|
||||||
|
|
|
||||||
|
|
@ -105,8 +105,11 @@ static void findBestRewrite(const ClassMap::const_iterator & pos,
|
||||||
|
|
||||||
static Path maybeRewrite(const Path & path, const PathSet & selection,
|
static Path maybeRewrite(const Path & path, const PathSet & selection,
|
||||||
const FinalClassMap & finalClassMap,
|
const FinalClassMap & finalClassMap,
|
||||||
Replacements & replacements)
|
Replacements & replacements,
|
||||||
|
unsigned int & nrRewrites)
|
||||||
{
|
{
|
||||||
|
startNest(nest, lvlError, format("considering rewriting `%1%'") % path);
|
||||||
|
|
||||||
assert(selection.find(path) != selection.end());
|
assert(selection.find(path) != selection.end());
|
||||||
|
|
||||||
if (replacements.find(path) != replacements.end()) return replacements[path];
|
if (replacements.find(path) != replacements.end()) return replacements[path];
|
||||||
|
|
@ -115,34 +118,35 @@ static Path maybeRewrite(const Path & path, const PathSet & selection,
|
||||||
queryReferences(noTxn, path, references);
|
queryReferences(noTxn, path, references);
|
||||||
|
|
||||||
HashRewrites rewrites;
|
HashRewrites rewrites;
|
||||||
|
PathSet newReferences;
|
||||||
|
|
||||||
bool okay = true;
|
|
||||||
for (PathSet::iterator i = references.begin(); i != references.end(); ++i) {
|
for (PathSet::iterator i = references.begin(); i != references.end(); ++i) {
|
||||||
if (*i == path) continue; /* ignore self-references */
|
|
||||||
if (selection.find(*i) == selection.end()) {
|
|
||||||
OutputEqClasses classes;
|
|
||||||
queryOutputEqClasses(noTxn, *i, classes);
|
|
||||||
|
|
||||||
if (classes.size() > 0) /* !!! hacky; ignore sources; they
|
|
||||||
are not in any eq class */
|
|
||||||
{
|
|
||||||
printMsg(lvlError, format("in `%1%': missing `%2%'") % path % *i);
|
|
||||||
okay = false;
|
|
||||||
|
|
||||||
FinalClassMap::const_iterator j = finalClassMap.find(*(classes.begin()));
|
OutputEqClasses classes;
|
||||||
assert(j != finalClassMap.end());
|
queryOutputEqClasses(noTxn, *i, classes);
|
||||||
|
|
||||||
printMsg(lvlError, format("replacing with `%1%'") % j->second);
|
/* !!! hacky; ignore sources; they are not in any eq class */
|
||||||
|
if (*i == path || classes.size() == 0) {
|
||||||
Path newPath = maybeRewrite(j->second, selection,
|
newReferences.insert(*i);
|
||||||
finalClassMap, replacements);
|
continue; /* ignore self-references */
|
||||||
if (*i != newPath)
|
|
||||||
rewrites[hashPartOf(*i)] = hashPartOf(newPath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FinalClassMap::const_iterator j = finalClassMap.find(*(classes.begin()));
|
||||||
|
assert(j != finalClassMap.end());
|
||||||
|
|
||||||
|
Path newPath = maybeRewrite(j->second, selection,
|
||||||
|
finalClassMap, replacements, nrRewrites);
|
||||||
|
|
||||||
|
if (*i != newPath)
|
||||||
|
rewrites[hashPartOf(*i)] = hashPartOf(newPath);
|
||||||
|
|
||||||
|
references.insert(newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rewrites.size() == 0) return path;
|
if (rewrites.size() == 0) {
|
||||||
|
replacements[path] = path;
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
printMsg(lvlError, format("rewriting `%1%'") % path);
|
printMsg(lvlError, format("rewriting `%1%'") % path);
|
||||||
|
|
||||||
|
|
@ -150,6 +154,8 @@ static Path maybeRewrite(const Path & path, const PathSet & selection,
|
||||||
hashPartOf(path), namePartOf(path),
|
hashPartOf(path), namePartOf(path),
|
||||||
references, rewrites);
|
references, rewrites);
|
||||||
|
|
||||||
|
nrRewrites++;
|
||||||
|
|
||||||
printMsg(lvlError, format("rewrote `%1%' to `%2%'") % path % newPath);
|
printMsg(lvlError, format("rewrote `%1%' to `%2%'") % path % newPath);
|
||||||
|
|
||||||
replacements[path] = newPath;
|
replacements[path] = newPath;
|
||||||
|
|
@ -206,10 +212,13 @@ PathSet consolidatePaths(const PathSet & paths, bool checkOnly,
|
||||||
finalClassMap[i->first] = *j;
|
finalClassMap[i->first] = *j;
|
||||||
|
|
||||||
PathSet newPaths;
|
PathSet newPaths;
|
||||||
|
unsigned int nrRewrites = 0;
|
||||||
replacements.clear();
|
replacements.clear();
|
||||||
for (PathSet::iterator i = bestSelection.begin();
|
for (PathSet::iterator i = bestSelection.begin();
|
||||||
i != bestSelection.end(); ++i)
|
i != bestSelection.end(); ++i)
|
||||||
newPaths.insert(maybeRewrite(*i, bestSelection, finalClassMap, replacements));
|
newPaths.insert(maybeRewrite(*i, bestSelection, finalClassMap, replacements, nrRewrites));
|
||||||
|
|
||||||
|
assert(nrRewrites == bestCost);
|
||||||
|
|
||||||
return newPaths;
|
return newPaths;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue