aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-05-10 19:07:33 -0400
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-05-15 09:03:37 -0400
commit0a9afce3b9191d71347a572a89e90167ba50c854 (patch)
tree1f5a0072e1fa343b5619c873d3306b682e2fcc14
parent9550c3862fb4bb021b977b47b5e710c0cdf6c74e (diff)
Split `mkOutputString` in two
This well help us with some unit testing
-rw-r--r--src/libexpr/primops.cc59
1 files changed, 38 insertions, 21 deletions
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 017aa25d1..336d756a0 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -129,41 +129,58 @@ static SourcePath realisePath(EvalState & state, const PosIdx pos, Value & v, co
}
}
-/* Add and attribute to the given attribute map from the output name to
- the output path, or a placeholder.
-
- Where possible the path is used, but for floating CA derivations we
- may not know it. For sake of determinism we always assume we don't
- and instead put in a place holder. In either case, however, the
- string context will contain the drv path and output name, so
- downstream derivations will have the proper dependency, and in
- addition, before building, the placeholder will be rewritten to be
- the actual path.
-
- The 'drv' and 'drvPath' outputs must correspond. */
+/**
+ * Inverse of one of the `EvalState::coerceToDerivedPath()` cases.
+ */
static void mkOutputString(
EvalState & state,
- BindingsBuilder & attrs,
+ Value & value,
const StorePath & drvPath,
- const std::pair<std::string, DerivationOutput> & o)
+ const std::string outputName,
+ std::optional<StorePath> optOutputPath)
{
- auto optOutputPath = o.second.path(*state.store, Derivation::nameFromPath(drvPath), o.first);
- attrs.alloc(o.first).mkString(
+ value.mkString(
optOutputPath
- ? state.store->printStorePath(*optOutputPath)
+ ? state.store->printStorePath(*std::move(optOutputPath))
/* Downstream we would substitute this for an actual path once
we build the floating CA derivation */
- /* FIXME: we need to depend on the basic derivation, not
- derivation */
- : downstreamPlaceholder(*state.store, drvPath, o.first),
+ : downstreamPlaceholder(*state.store, drvPath, outputName),
NixStringContext {
NixStringContextElem::Built {
.drvPath = drvPath,
- .output = o.first,
+ .output = outputName,
}
});
}
+/**
+ * Add and attribute to the given attribute map from the output name to
+ * the output path, or a placeholder.
+ *
+ * Where possible the path is used, but for floating CA derivations we
+ * may not know it. For sake of determinism we always assume we don't
+ * and instead put in a place holder. In either case, however, the
+ * string context will contain the drv path and output name, so
+ * downstream derivations will have the proper dependency, and in
+ * addition, before building, the placeholder will be rewritten to be
+ * the actual path.
+ *
+ * The 'drv' and 'drvPath' outputs must correspond.
+ */
+static void mkOutputString(
+ EvalState & state,
+ BindingsBuilder & attrs,
+ const StorePath & drvPath,
+ const std::pair<std::string, DerivationOutput> & o)
+{
+ mkOutputString(
+ state,
+ attrs.alloc(o.first),
+ drvPath,
+ o.first,
+ o.second.path(*state.store, Derivation::nameFromPath(drvPath), o.first));
+}
+
/* Load and evaluate an expression from path specified by the
argument. */
static void import(EvalState & state, const PosIdx pos, Value & vPath, Value * vScope, Value & v)