From 865239c7321297fd4673c37264a7683cae5517e2 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Mon, 27 Jan 2025 12:32:46 +0100 Subject: [PATCH 1/2] refactor: Extract EvalState::realiseString (cherry picked from commit 7465fbe9264e46c556b456226e8fb980fcfd7e66) # Conflicts: # src/libexpr/primops.cc --- src/libexpr-c/nix_api_value.cc | 6 +----- src/libexpr/eval.hh | 9 +++++++++ src/libexpr/primops.cc | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/libexpr-c/nix_api_value.cc b/src/libexpr-c/nix_api_value.cc index 845e87935..a005a10ff 100644 --- a/src/libexpr-c/nix_api_value.cc +++ b/src/libexpr-c/nix_api_value.cc @@ -619,12 +619,8 @@ nix_realised_string * nix_string_realise(nix_c_context * context, EvalState * st context->last_err_code = NIX_OK; try { auto & v = check_value_in(value); - nix::NixStringContext stringContext; - auto rawStr = state->state.coerceToString(nix::noPos, v, stringContext, "while realising a string").toOwned(); nix::StorePathSet storePaths; - auto rewrites = state->state.realiseContext(stringContext, &storePaths); - - auto s = nix::rewriteStrings(rawStr, rewrites); + auto s = state->state.realiseString(v, &storePaths, isIFD); // Convert to the C API StorePath type and convert to vector for index-based access std::vector vec; diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 8b3d34601..27fb336ce 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -786,6 +786,15 @@ public: */ [[nodiscard]] StringMap realiseContext(const NixStringContext & context, StorePathSet * maybePaths = nullptr, bool isIFD = true); + /** + * Realise the given string with context, and return the string with outputs instead of downstream output placeholders. + * @param[in] str the string to realise + * @param[out] paths all referenced store paths will be added to this set + * @return the realised string + * @throw EvalError if the value is not a string, path or derivation (see `coerceToString`) + */ + std::string realiseString(Value & str, StorePathSet * storePathsOutMaybe, bool isIFD = true, const PosIdx pos = noPos); + /* Call the binary path filter predicate used builtins.path etc. */ bool callPathFilter( Value * filterFun, diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 6a499c811..a0ff660a8 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -40,6 +40,25 @@ namespace nix { * Miscellaneous *************************************************************/ +<<<<<<< HEAD +======= +static inline Value * mkString(EvalState & state, const std::csub_match & match) +{ + Value * v = state.allocValue(); + v->mkString({match.first, match.second}); + return v; +} + +std::string EvalState::realiseString(Value & s, StorePathSet * storePathsOutMaybe, bool isIFD, const PosIdx pos) +{ + nix::NixStringContext stringContext; + auto rawStr = coerceToString(pos, s, stringContext, "while realising a string").toOwned(); + auto rewrites = realiseContext(stringContext, storePathsOutMaybe, isIFD); + + return nix::rewriteStrings(rawStr, rewrites); +} + +>>>>>>> 7465fbe92 (refactor: Extract EvalState::realiseString) StringMap EvalState::realiseContext(const NixStringContext & context, StorePathSet * maybePathsOut, bool isIFD) { std::vector drvs; From 0f19bfe81188974bc6bc15b320a8b82b1c90ab06 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Tue, 28 Jan 2025 09:20:56 +0100 Subject: [PATCH 2/2] Fix conflict --- src/libexpr/primops.cc | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index a0ff660a8..75597e6cb 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -40,15 +40,6 @@ namespace nix { * Miscellaneous *************************************************************/ -<<<<<<< HEAD -======= -static inline Value * mkString(EvalState & state, const std::csub_match & match) -{ - Value * v = state.allocValue(); - v->mkString({match.first, match.second}); - return v; -} - std::string EvalState::realiseString(Value & s, StorePathSet * storePathsOutMaybe, bool isIFD, const PosIdx pos) { nix::NixStringContext stringContext; @@ -58,7 +49,6 @@ std::string EvalState::realiseString(Value & s, StorePathSet * storePathsOutMayb return nix::rewriteStrings(rawStr, rewrites); } ->>>>>>> 7465fbe92 (refactor: Extract EvalState::realiseString) StringMap EvalState::realiseContext(const NixStringContext & context, StorePathSet * maybePathsOut, bool isIFD) { std::vector drvs;