Skip to content

Commit

Permalink
log all ifd
Browse files Browse the repository at this point in the history
  • Loading branch information
cleverca22 committed Apr 14, 2020
1 parent 512753f commit 595971e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
5 changes: 4 additions & 1 deletion src/libexpr/eval.hh
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public:
/* Print statistics. */
void printStats();

void realiseContext(const PathSet & context);
void realiseContext(const PathSet & context, const Pos &pos, const string reason);

private:

Expand Down Expand Up @@ -369,6 +369,9 @@ struct EvalSettings : Config

Setting<bool> traceFunctionCalls{this, false, "trace-function-calls",
"Emit log messages for each function entry and exit at the 'vomit' log level (-vvvv)."};

Setting<bool> logAllIFD{this, false, "log-all-ifd",
"Emit log messages for all IFD at 'info' log level"};
};

extern EvalSettings evalSettings;
Expand Down
19 changes: 11 additions & 8 deletions src/libexpr/primops.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::pair<string, string> decodeContext(const string & s)
InvalidPathError::InvalidPathError(const Path & path) :
EvalError("path '%s' is not valid", path), path(path) {}

void EvalState::realiseContext(const PathSet & context)
void EvalState::realiseContext(const PathSet & context, const Pos &pos, const string reason)
{
std::vector<StorePathWithOutputs> drvs;

Expand All @@ -56,6 +56,9 @@ void EvalState::realiseContext(const PathSet & context)
throw InvalidPathError(store->printStorePath(ctx));
if (!decoded.second.empty() && ctx.isDerivation()) {
drvs.push_back(StorePathWithOutputs{ctx.clone(), {decoded.second}});
if (evalSettings.logAllIFD) {
printInfo(format("%1% importing from derivation %2% via %3%") % pos % decoded.first % reason);
}

/* Add the output of this derivation to the allowed
paths. */
Expand Down Expand Up @@ -91,7 +94,7 @@ static void prim_scopedImport(EvalState & state, const Pos & pos, Value * * args
Path path = state.coerceToPath(pos, *args[1], context);

try {
state.realiseContext(context);
state.realiseContext(context, pos, "scopedImport");
} catch (InvalidPathError & e) {
throw EvalError(format("cannot import '%1%', since path '%2%' is not valid, at %3%")
% path % e.path % pos);
Expand Down Expand Up @@ -168,7 +171,7 @@ void prim_importNative(EvalState & state, const Pos & pos, Value * * args, Value
Path path = state.coerceToPath(pos, *args[0], context);

try {
state.realiseContext(context);
state.realiseContext(context, pos, "importNative");
} catch (InvalidPathError & e) {
throw EvalError(format("cannot import '%1%', since path '%2%' is not valid, at %3%")
% path % e.path % pos);
Expand Down Expand Up @@ -215,7 +218,7 @@ void prim_exec(EvalState & state, const Pos & pos, Value * * args, Value & v)
commandArgs.emplace_back(state.coerceToString(pos, *elems[i], context, false, false));
}
try {
state.realiseContext(context);
state.realiseContext(context, pos, "exec");
} catch (InvalidPathError & e) {
throw EvalError(format("cannot execute '%1%', since path '%2%' is not valid, at %3%")
% program % e.path % pos);
Expand Down Expand Up @@ -831,7 +834,7 @@ static void prim_pathExists(EvalState & state, const Pos & pos, Value * * args,
PathSet context;
Path path = state.coerceToPath(pos, *args[0], context);
try {
state.realiseContext(context);
state.realiseContext(context, pos, "pathExists");
} catch (InvalidPathError & e) {
throw EvalError(format(
"cannot check the existence of '%1%', since path '%2%' is not valid, at %3%")
Expand Down Expand Up @@ -876,7 +879,7 @@ static void prim_readFile(EvalState & state, const Pos & pos, Value * * args, Va
PathSet context;
Path path = state.coerceToPath(pos, *args[0], context);
try {
state.realiseContext(context);
state.realiseContext(context, pos, "readFile");
} catch (InvalidPathError & e) {
throw EvalError(format("cannot read '%1%', since path '%2%' is not valid, at %3%")
% path % e.path % pos);
Expand Down Expand Up @@ -913,7 +916,7 @@ static void prim_findFile(EvalState & state, const Pos & pos, Value * * args, Va
string path = state.coerceToString(pos, *i->value, context, false, false);

try {
state.realiseContext(context);
state.realiseContext(context, pos, "findFile");
} catch (InvalidPathError & e) {
throw EvalError(format("cannot find '%1%', since path '%2%' is not valid, at %3%")
% path % e.path % pos);
Expand Down Expand Up @@ -947,7 +950,7 @@ static void prim_readDir(EvalState & state, const Pos & pos, Value * * args, Val
PathSet ctx;
Path path = state.coerceToPath(pos, *args[0], ctx);
try {
state.realiseContext(ctx);
state.realiseContext(ctx, pos, "readDir");
} catch (InvalidPathError & e) {
throw EvalError(format("cannot read '%1%', since path '%2%' is not valid, at %3%")
% path % e.path % pos);
Expand Down

0 comments on commit 595971e

Please sign in to comment.