nix-instantiate: Fix read-only evaluation

This commit is contained in:
Eelco Dolstra 2012-11-26 17:39:09 +01:00
parent 8d8d47abd2
commit 408a7bfac1
5 changed files with 17 additions and 10 deletions

View file

@ -138,6 +138,7 @@ EvalState::EvalState()
, sName(symbols.create("name")) , sName(symbols.create("name"))
, sSystem(symbols.create("system")) , sSystem(symbols.create("system"))
, sOverrides(symbols.create("__overrides")) , sOverrides(symbols.create("__overrides"))
, sOutputName(symbols.create("outputName"))
, baseEnv(allocEnv(128)) , baseEnv(allocEnv(128))
, baseEnvDispl(0) , baseEnvDispl(0)
, staticBaseEnv(false, 0) , staticBaseEnv(false, 0)

View file

@ -93,7 +93,7 @@ public:
SymbolTable symbols; SymbolTable symbols;
const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName, const Symbol sWith, sOutPath, sDrvPath, sType, sMeta, sName,
sSystem, sOverrides; sSystem, sOverrides, sOutputName;
/* If set, force copying files to the Nix store even if they /* If set, force copying files to the Nix store even if they
already exist there. */ already exist there. */

View file

@ -28,6 +28,17 @@ string DrvInfo::queryOutPath(EvalState & state) const
} }
string DrvInfo::queryOutputName(EvalState & state) const
{
if (outputName == "" && attrs) {
Bindings::iterator i = attrs->find(state.sOutputName);
PathSet context;
(string &) outputName = i != attrs->end() ? state.coerceToString(*i->value, context) : "";
}
return outputName;
}
MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const MetaInfo DrvInfo::queryMetaInfo(EvalState & state) const
{ {
if (metaInfoRead) return meta; if (metaInfoRead) return meta;

View file

@ -28,6 +28,7 @@ struct DrvInfo
private: private:
string drvPath; string drvPath;
string outPath; string outPath;
string outputName;
bool metaInfoRead; bool metaInfoRead;
MetaInfo meta; MetaInfo meta;
@ -46,6 +47,7 @@ public:
string queryDrvPath(EvalState & state) const; string queryDrvPath(EvalState & state) const;
string queryOutPath(EvalState & state) const; string queryOutPath(EvalState & state) const;
string queryOutputName(EvalState & state) const;
MetaInfo queryMetaInfo(EvalState & state) const; MetaInfo queryMetaInfo(EvalState & state) const;
MetaValue queryMetaInfo(EvalState & state, const string & name) const; MetaValue queryMetaInfo(EvalState & state, const string & name) const;

View file

@ -62,16 +62,9 @@ void processExpr(EvalState & state, const Strings & attrPaths,
Path drvPath = i->queryDrvPath(state); Path drvPath = i->queryDrvPath(state);
/* What output do we want? */ /* What output do we want? */
Path outPath = i->queryOutPath(state); string outputName = i->queryOutputName(state);
Derivation drv = derivationFromPath(*store, drvPath);
string outputName;
foreach (DerivationOutputs::iterator, i, drv.outputs)
if (i->second.path == outPath) {
outputName = i->first;
break;
}
if (outputName == "") if (outputName == "")
throw Error(format("derivation `%1%' does not have an output `%2%'") % drvPath % outPath); throw Error(format("derivation `%1%' lacks an `outputName' attribute ") % drvPath);
if (gcRoot == "") if (gcRoot == "")
printGCWarning(); printGCWarning();