mirror of
https://github.com/NixOS/nix.git
synced 2025-11-27 12:41:00 +01:00
Merged R8636
This commit is contained in:
parent
8e9c7d9338
commit
854e155b2c
8 changed files with 97 additions and 33 deletions
|
|
@ -107,6 +107,15 @@ MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const
|
|||
}
|
||||
|
||||
|
||||
string DrvInfo::queryMetaInfo(EvalState & state, const string & name) const
|
||||
{
|
||||
/* !!! evaluates all meta attributes => inefficient */
|
||||
MetaInfo meta = queryMetaInfo(state);
|
||||
MetaInfo::iterator i = meta.find(name);
|
||||
return i == meta.end() ? "" : i->second;
|
||||
}
|
||||
|
||||
|
||||
void DrvInfo::setMetaInfo(const MetaInfo & meta)
|
||||
{
|
||||
ATermMap metaAttrs;
|
||||
|
|
@ -214,12 +223,21 @@ static void getDerivations(EvalState & state, Expr e,
|
|||
if (matchAttrs(e, es)) {
|
||||
ATermMap drvMap(ATgetLength(es));
|
||||
queryAllAttrs(e, drvMap);
|
||||
|
||||
/* !!! undocumented hackery to support
|
||||
corepkgs/channels/unpack.sh. */
|
||||
Expr e2 = drvMap.get(toATerm("_combineChannels"));
|
||||
bool combineChannels = e2 && evalBool(state, e2);
|
||||
|
||||
for (ATermMap::const_iterator i = drvMap.begin(); i != drvMap.end(); ++i) {
|
||||
startNest(nest, lvlDebug,
|
||||
format("evaluating attribute `%1%'") % aterm2String(i->key));
|
||||
string pathPrefix2 = addToPath(pathPrefix, aterm2String(i->key));
|
||||
if (getDerivation(state, i->value, pathPrefix2, drvs, doneExprs)) {
|
||||
if (combineChannels) {
|
||||
if (((string) aterm2String(i->key)) != "_combineChannels")
|
||||
getDerivations(state, i->value, pathPrefix2, autoArgs, drvs, doneExprs);
|
||||
}
|
||||
else if (getDerivation(state, i->value, pathPrefix2, drvs, doneExprs)) {
|
||||
/* If the value of this attribute is itself an
|
||||
attribute set, should we recurse into it? => Only
|
||||
if it has a `recurseForDerivations = true'
|
||||
|
|
@ -229,8 +247,8 @@ static void getDerivations(EvalState & state, Expr e,
|
|||
if (matchAttrs(e, es)) {
|
||||
ATermMap attrs(ATgetLength(es));
|
||||
queryAllAttrs(e, attrs, false);
|
||||
Expr e2 = attrs.get(toATerm("recurseForDerivations"));
|
||||
if (e2 && evalBool(state, e2))
|
||||
if (((e2 = attrs.get(toATerm("recurseForDerivations")))
|
||||
&& evalBool(state, e2)))
|
||||
getDerivations(state, e, pathPrefix2, autoArgs, drvs, doneExprs);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,7 @@ public:
|
|||
string queryStateIdentifier(EvalState & state) const;
|
||||
string queryRuntimeStateArgs(EvalState & state) const;
|
||||
MetaInfo queryMetaInfo(EvalState & state) const;
|
||||
string queryMetaInfo(EvalState & state, const string & name) const;
|
||||
|
||||
void setDrvPath(const string & s)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -252,6 +252,16 @@ static void createUserEnv(EvalState & state, const DrvInfos & elems,
|
|||
}
|
||||
|
||||
|
||||
static int comparePriorities(EvalState & state,
|
||||
const DrvInfo & drv1, const DrvInfo & drv2)
|
||||
{
|
||||
int prio1, prio2;
|
||||
if (!string2Int(drv1.queryMetaInfo(state, "priority"), prio1)) prio1 = 0;
|
||||
if (!string2Int(drv2.queryMetaInfo(state, "priority"), prio2)) prio2 = 0;
|
||||
return prio2 - prio1; /* higher number = lower priority, so negate */
|
||||
}
|
||||
|
||||
|
||||
static DrvInfos filterBySelector(EvalState & state,
|
||||
const DrvInfos & allElems,
|
||||
const Strings & args, bool newestOnly)
|
||||
|
|
@ -278,8 +288,10 @@ static DrvInfos filterBySelector(EvalState & state,
|
|||
}
|
||||
|
||||
/* If `newestOnly', if a selector matches multiple derivations
|
||||
with the same name, pick the one with the highest version.
|
||||
If there are multiple derivations with the same name *and*
|
||||
with the same name, pick the one with the highest priority.
|
||||
If there are multiple derivations with the same priority,
|
||||
pick the one with the highest version. If there are
|
||||
multiple derivations with the same priority and name and
|
||||
version, then pick the first one. */
|
||||
if (newestOnly) {
|
||||
|
||||
|
|
@ -290,13 +302,22 @@ static DrvInfos filterBySelector(EvalState & state,
|
|||
|
||||
for (Matches::iterator j = matches.begin(); j != matches.end(); ++j) {
|
||||
DrvName drvName(j->first.name);
|
||||
int d = 1;
|
||||
|
||||
Newest::iterator k = newest.find(drvName.name);
|
||||
|
||||
if (k != newest.end()) {
|
||||
int d = compareVersions(drvName.version, DrvName(k->second.first.name).version);
|
||||
if (d > 0) newest[drvName.name] = *j;
|
||||
else if (d == 0) multiple.insert(j->first.name);
|
||||
} else
|
||||
d = comparePriorities(state, j->first, k->second.first);
|
||||
if (d == 0)
|
||||
d = compareVersions(drvName.version, DrvName(k->second.first.name).version);
|
||||
}
|
||||
|
||||
if (d > 0) {
|
||||
newest[drvName.name] = *j;
|
||||
multiple.erase(j->first.name);
|
||||
} else if (d == 0) {
|
||||
multiple.insert(j->first.name);
|
||||
}
|
||||
}
|
||||
|
||||
matches.clear();
|
||||
|
|
@ -712,9 +733,10 @@ static void upgradeDerivations(Globals & globals,
|
|||
if (meta["keep"] == "true") continue;
|
||||
|
||||
/* Find the derivation in the input Nix expression with the
|
||||
same name and satisfying the version constraints specified
|
||||
same name that satisfies the version constraints specified
|
||||
by upgradeType. If there are multiple matches, take the
|
||||
one with highest version. */
|
||||
one with the highest priority. If there are still multiple
|
||||
matches, take the one with the highest version. */
|
||||
DrvInfos::iterator bestElem = availElems.end();
|
||||
DrvName bestName;
|
||||
for (DrvInfos::iterator j = availElems.begin();
|
||||
|
|
@ -722,16 +744,19 @@ static void upgradeDerivations(Globals & globals,
|
|||
{
|
||||
DrvName newName(j->name);
|
||||
if (newName.name == drvName.name) {
|
||||
int d = compareVersions(drvName.version, newName.version);
|
||||
int d = comparePriorities(globals.state, *i, *j);
|
||||
if (d == 0) d = compareVersions(drvName.version, newName.version);
|
||||
if (upgradeType == utLt && d < 0 ||
|
||||
upgradeType == utLeq && d <= 0 ||
|
||||
upgradeType == utEq && d == 0 ||
|
||||
upgradeType == utAlways)
|
||||
{
|
||||
if ((bestElem == availElems.end() ||
|
||||
compareVersions(
|
||||
bestName.version, newName.version) < 0))
|
||||
{
|
||||
int d2 = -1;
|
||||
if (bestElem != availElems.end()) {
|
||||
d2 = comparePriorities(globals.state, *bestElem, *j);
|
||||
if (d2 == 0) d2 = compareVersions(bestName.version, newName.version);
|
||||
}
|
||||
if (d2 < 0) {
|
||||
bestElem = j;
|
||||
bestName = newName;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue