aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.hh
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2021-03-10 04:22:56 +0000
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-08-14 08:44:50 -0400
commite7c39ff00b81dfdc48ebe7f41847db84ba779676 (patch)
treeaa32fd11345e50e45500df107bd3af3a8d7b975d /src/libexpr/eval.hh
parenta04720e68ce45943ce0eae3d477f9d554b0d63a4 (diff)
Rework evaluator `SingleDerivedPath` infra
`EvalState::mkSingleDerivedPathString` previously contained its own inverse (printing, rather than parsing) in order to validate what was parsed. Now that is pulled out into its own separate function: `EvalState::coerceToSingleDerivedPath`. In additional that pulled out logic is deduplicated with `EvalState::mkOutputString` via `EvalState::mkOutputStringRaw`, which is itself deduplicated (and generalized) with `DownstreamPlaceholder::mkOutputStringRaw`. All these changes make the unit tests simpler. (We would ideally write more unit tests for `mkSingleDerivedPathString` `coerceToSingleDerivedPath` directly, but we cannot yet do that because the IO in reading the store path won't work when the dummy store cannot hold anything. Someday we'll have a proper in-memory store which will work for this.) Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
Diffstat (limited to 'src/libexpr/eval.hh')
-rw-r--r--src/libexpr/eval.hh53
1 files changed, 39 insertions, 14 deletions
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 662c123b9..0c3eb6505 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -668,37 +668,46 @@ public:
/**
* 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.
+ * 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`.
+ * Create a string representing a `SingleDerivedPath::Built`.
*
- * The string is the printed store path with a context containing a single
- * `NixStringContextElem::Built` element of the drv path and output name.
+ * 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 b the drv whose output we are making a string for, and the
+ * output
*
- * @param outputName Name of the output
- *
- * @param optStaticOutputPath 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`).
+ * @param optStaticOutputPath Optional output path for that string.
+ * Must be passed if and only if output store object is
+ * input-addressed or fixed output. Will be printed to form string
+ * if passed, otherwise a placeholder will be used (see
+ * `DownstreamPlaceholder`).
*
* @param xpSettings Stop-gap to avoid globals during unit tests.
*/
void mkOutputString(
Value & value,
- const StorePath & drvPath,
- const std::string outputName,
+ const SingleDerivedPath::Built & b,
std::optional<StorePath> optStaticOutputPath,
const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
+ /**
+ * Create a string representing a `SingleDerivedPath`.
+ *
+ * A combination of `mkStorePathString` and `mkOutputString`.
+ */
+ void mkSingleDerivedPathString(
+ const SingleDerivedPath & p,
+ Value & v);
+
void concatLists(Value & v, size_t nrLists, Value * * lists, const PosIdx pos, std::string_view errorCtx);
/**
@@ -714,6 +723,22 @@ public:
private:
+ /**
+ * Like `mkOutputString` but just creates a raw string, not an
+ * string Value, which would also have a string context.
+ */
+ std::string mkOutputStringRaw(
+ const SingleDerivedPath::Built & b,
+ std::optional<StorePath> optStaticOutputPath,
+ const ExperimentalFeatureSettings & xpSettings = experimentalFeatureSettings);
+
+ /**
+ * Like `mkSingleDerivedPathStringRaw` but just creates a raw string
+ * Value, which would also have a string context.
+ */
+ std::string mkSingleDerivedPathStringRaw(
+ const SingleDerivedPath & p);
+
unsigned long nrEnvs = 0;
unsigned long nrValuesInEnvs = 0;
unsigned long nrValues = 0;