From 8e1a99026887ee836a68ae3e238fb0f2e1562447 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 10 May 2023 20:47:25 -0400 Subject: [PATCH] Expose `mkOutputString` as method of `EvalState` --- src/libexpr/eval.cc | 21 +++++++++++++++++++++ src/libexpr/eval.hh | 33 +++++++++++++++++++++++++++++---- src/libexpr/primops.cc | 27 +-------------------------- 3 files changed, 51 insertions(+), 30 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 0b4243670..679f46153 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1047,6 +1047,27 @@ void EvalState::mkStorePathString(const StorePath & p, Value & v) } +void EvalState::mkOutputString( + Value & value, + const StorePath & drvPath, + const std::string outputName, + std::optional optOutputPath) +{ + value.mkString( + optOutputPath + ? store->printStorePath(*std::move(optOutputPath)) + /* Downstream we would substitute this for an actual path once + we build the floating CA derivation */ + : downstreamPlaceholder(*store, drvPath, outputName), + NixStringContext { + NixStringContextElem::Built { + .drvPath = drvPath, + .output = outputName, + } + }); +} + + /* Create a thunk for the delayed computation of the given expression in the given environment. But if the expression is a variable, then look it up right away. This significantly reduces the number diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index bb3ac2b22..3b2164a19 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -576,12 +576,37 @@ public: void mkThunk_(Value & v, Expr * expr); void mkPos(Value & v, PosIdx pos); - /* Create a string representing a store path. - - The string is the printed store path with a context containing a single - `Opaque` element of that store path. */ + /** + * Create a string representing a store path. + * + * The string is the printed store path with a context containing a single + * `NixStringContextElem::Opaque` element of that store path. + */ void mkStorePathString(const StorePath & storePath, Value & v); + /** + * Create a string representing a `DerivedPath::Built`. + * + * The string is the printed store path with a context containing a single + * `NixStringContextElem::Built` element of the drv path and output name. + * + * @param value Value we are settings + * + * @param drvPath Path the drv whose output we are making a string for + * + * @param outputName Name of the output + * + * @param optOutputPath Optional output path for that string. Must + * be passed if and only if output store object is input-addressed. + * Will be printed to form string if passed, otherwise a placeholder + * will be used (see `downstreamPlaceholder()`). + */ + void mkOutputString( + Value & value, + const StorePath & drvPath, + const std::string outputName, + std::optional optOutputPath); + void concatLists(Value & v, size_t nrLists, Value * * lists, const PosIdx pos, std::string_view errorCtx); /** diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 336d756a0..6fbd66389 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -129,30 +129,6 @@ static SourcePath realisePath(EvalState & state, const PosIdx pos, Value & v, co } } -/** - * Inverse of one of the `EvalState::coerceToDerivedPath()` cases. - */ -static void mkOutputString( - EvalState & state, - Value & value, - const StorePath & drvPath, - const std::string outputName, - std::optional optOutputPath) -{ - value.mkString( - optOutputPath - ? state.store->printStorePath(*std::move(optOutputPath)) - /* Downstream we would substitute this for an actual path once - we build the floating CA derivation */ - : downstreamPlaceholder(*state.store, drvPath, outputName), - NixStringContext { - NixStringContextElem::Built { - .drvPath = drvPath, - .output = outputName, - } - }); -} - /** * Add and attribute to the given attribute map from the output name to * the output path, or a placeholder. @@ -173,8 +149,7 @@ static void mkOutputString( const StorePath & drvPath, const std::pair & o) { - mkOutputString( - state, + state.mkOutputString( attrs.alloc(o.first), drvPath, o.first,