From 785cb3a75476033ba6eec2fef334d47d8e64388a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 22 Nov 2019 16:06:44 +0100 Subject: refactor(tvix): getEnv(): Return std::optional This allows distinguishing between an empty value and no value. Patch ported from upstream at https://github.com/NixOS/nix/commit/ba87b08f8529e4d9f8c58d8c625152058ceadb75 Change-Id: I061cc8e16b1a7a0341adfc3b0edca1c0c51d5c97 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1884 Tested-by: BuildkiteCI Reviewed-by: kanepyork --- third_party/nix/src/libexpr/eval.cc | 8 ++++---- third_party/nix/src/libexpr/primops.cc | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'third_party/nix/src/libexpr') diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index b735495f2132..28ae46bdfd8c 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -287,11 +287,11 @@ EvalState::EvalState(const Strings& _searchPath, const ref& store) staticBaseEnv(false, nullptr) { expr::InitGC(); - countCalls = getEnv("NIX_COUNT_CALLS", "0") != "0"; + countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0"; /* Initialise the Nix expression search path. */ if (!evalSettings.pureEval) { - Strings paths = parseNixPath(getEnv("NIX_PATH", "")); + Strings paths = parseNixPath(getEnv("NIX_PATH").value_or("")); for (auto& i : _searchPath) { addToSearchPath(i); } @@ -1644,7 +1644,7 @@ bool EvalState::eqValues(Value& v1, Value& v2) { } void EvalState::printStats() { - bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0"; + bool showStats = getEnv("NIX_SHOW_STATS").value_or("0") != "0"; struct rusage buf; getrusage(RUSAGE_SELF, &buf); @@ -1658,7 +1658,7 @@ void EvalState::printStats() { nrAttrsets * sizeof(Bindings) + nrAttrsInAttrsets * sizeof(Attr); if (showStats) { - auto outPath = getEnv("NIX_SHOW_STATS_PATH", "-"); + auto outPath = getEnv("NIX_SHOW_STATS_PATH").value_or("-"); std::fstream fs; if (outPath != "-") { fs.open(outPath, std::fstream::out); diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 04a44311a259..dd8a509df32d 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -413,7 +413,7 @@ static void prim_getEnv(EvalState& state, const Pos& pos, Value** args, std::string name = state.forceStringNoCtx(*args[0], pos); mkString(v, evalSettings.restrictEval || evalSettings.pureEval ? "" - : getEnv(name)); + : getEnv(name).value_or("")); } /* Evaluate the first argument, then return the second argument. */ -- cgit 1.4.1