mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00:59 +01:00
* Handle sources (which are not in any equivalence class) properly.
This commit is contained in:
parent
48190ccfca
commit
cfe428f69c
1 changed files with 22 additions and 15 deletions
|
|
@ -80,8 +80,6 @@ static void findBestRewrite(const ClassMap::const_iterator & pos,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// printMsg(lvlError, format("selection %1%") % showPaths(selection));
|
|
||||||
|
|
||||||
PathSet badPaths;
|
PathSet badPaths;
|
||||||
for (PathSet::iterator i = selection.begin();
|
for (PathSet::iterator i = selection.begin();
|
||||||
i != selection.end(); ++i)
|
i != selection.end(); ++i)
|
||||||
|
|
@ -104,7 +102,7 @@ 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, const PathSet & sources,
|
||||||
Replacements & replacements,
|
Replacements & replacements,
|
||||||
unsigned int & nrRewrites)
|
unsigned int & nrRewrites)
|
||||||
{
|
{
|
||||||
|
|
@ -122,20 +120,20 @@ static Path maybeRewrite(const Path & path, const PathSet & selection,
|
||||||
|
|
||||||
for (PathSet::iterator i = references.begin(); i != references.end(); ++i) {
|
for (PathSet::iterator i = references.begin(); i != references.end(); ++i) {
|
||||||
|
|
||||||
OutputEqClasses classes;
|
if (*i == path || sources.find(*i) != sources.end()) {
|
||||||
queryOutputEqClasses(noTxn, *i, classes);
|
|
||||||
|
|
||||||
/* !!! hacky; ignore sources; they are not in any eq class */
|
|
||||||
if (*i == path || classes.size() == 0) {
|
|
||||||
newReferences.insert(*i);
|
newReferences.insert(*i);
|
||||||
continue; /* ignore self-references */
|
continue; /* ignore self-references */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OutputEqClasses classes;
|
||||||
|
queryOutputEqClasses(noTxn, *i, classes);
|
||||||
|
assert(classes.size() > 0);
|
||||||
|
|
||||||
FinalClassMap::const_iterator j = finalClassMap.find(*(classes.begin()));
|
FinalClassMap::const_iterator j = finalClassMap.find(*(classes.begin()));
|
||||||
assert(j != finalClassMap.end());
|
assert(j != finalClassMap.end());
|
||||||
|
|
||||||
Path newPath = maybeRewrite(j->second, selection,
|
Path newPath = maybeRewrite(j->second, selection,
|
||||||
finalClassMap, replacements, nrRewrites);
|
finalClassMap, sources, replacements, nrRewrites);
|
||||||
|
|
||||||
if (*i != newPath)
|
if (*i != newPath)
|
||||||
rewrites[hashPartOf(*i)] = hashPartOf(newPath);
|
rewrites[hashPartOf(*i)] = hashPartOf(newPath);
|
||||||
|
|
@ -170,18 +168,21 @@ PathSet consolidatePaths(const PathSet & paths, bool checkOnly,
|
||||||
printMsg(lvlError, format("consolidating"));
|
printMsg(lvlError, format("consolidating"));
|
||||||
|
|
||||||
ClassMap classMap;
|
ClassMap classMap;
|
||||||
|
PathSet sources;
|
||||||
|
|
||||||
for (PathSet::const_iterator i = paths.begin(); i != paths.end(); ++i) {
|
for (PathSet::const_iterator i = paths.begin(); i != paths.end(); ++i) {
|
||||||
OutputEqClasses classes;
|
OutputEqClasses classes;
|
||||||
queryOutputEqClasses(noTxn, *i, classes);
|
queryOutputEqClasses(noTxn, *i, classes);
|
||||||
|
|
||||||
/* !!! deal with sources */
|
if (classes.size() == 0)
|
||||||
|
sources.insert(*i);
|
||||||
for (OutputEqClasses::iterator j = classes.begin(); j != classes.end(); ++j) {
|
else
|
||||||
classMap[*j].insert(*i);
|
for (OutputEqClasses::iterator j = classes.begin(); j != classes.end(); ++j)
|
||||||
}
|
classMap[*j].insert(*i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
printMsg(lvlError, format("found %1% sources") % sources.size());
|
||||||
|
|
||||||
bool conflict = false;
|
bool conflict = false;
|
||||||
for (ClassMap::iterator i = classMap.begin(); i != classMap.end(); ++i)
|
for (ClassMap::iterator i = classMap.begin(); i != classMap.end(); ++i)
|
||||||
if (i->second.size() >= 2) {
|
if (i->second.size() >= 2) {
|
||||||
|
|
@ -193,6 +194,7 @@ PathSet consolidatePaths(const PathSet & paths, bool checkOnly,
|
||||||
|
|
||||||
assert(!checkOnly);
|
assert(!checkOnly);
|
||||||
|
|
||||||
|
|
||||||
/* !!! exponential-time algorithm! */
|
/* !!! exponential-time algorithm! */
|
||||||
const unsigned int infinity = 1000000;
|
const unsigned int infinity = 1000000;
|
||||||
unsigned int bestCost = infinity;
|
unsigned int bestCost = infinity;
|
||||||
|
|
@ -216,9 +218,14 @@ PathSet consolidatePaths(const PathSet & paths, bool checkOnly,
|
||||||
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, nrRewrites));
|
newPaths.insert(maybeRewrite(*i, bestSelection, finalClassMap,
|
||||||
|
sources, replacements, nrRewrites));
|
||||||
|
|
||||||
|
newPaths.insert(sources.begin(), sources.end());
|
||||||
|
|
||||||
assert(nrRewrites == bestCost);
|
assert(nrRewrites == bestCost);
|
||||||
|
|
||||||
|
assert(newPaths.size() < paths.size());
|
||||||
|
|
||||||
return newPaths;
|
return newPaths;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue