mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 12:06:01 +01:00
libexpr-c: Add nix_string_realise
This commit is contained in:
parent
62f8d8c9a9
commit
02c41aba5b
7 changed files with 235 additions and 10 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include "config.hh"
|
||||
#include "eval.hh"
|
||||
#include "globals.hh"
|
||||
#include "path.hh"
|
||||
#include "primops.hh"
|
||||
#include "value.hh"
|
||||
|
||||
|
|
@ -9,7 +10,9 @@
|
|||
#include "nix_api_expr_internal.h"
|
||||
#include "nix_api_util.h"
|
||||
#include "nix_api_util_internal.h"
|
||||
#include "nix_api_store_internal.h"
|
||||
#include "nix_api_value.h"
|
||||
#include "value/context.hh"
|
||||
|
||||
#ifdef HAVE_BOEHMGC
|
||||
# include "gc/gc.h"
|
||||
|
|
@ -528,3 +531,55 @@ void nix_bindings_builder_free(BindingsBuilder * bb)
|
|||
delete (nix::BindingsBuilder *) bb;
|
||||
#endif
|
||||
}
|
||||
|
||||
nix_realised_string * nix_string_realise(nix_c_context * context, EvalState * state, Value * value, bool isIFD)
|
||||
{
|
||||
if (context)
|
||||
context->last_err_code = NIX_OK;
|
||||
try {
|
||||
auto &v = check_value_not_null(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);
|
||||
|
||||
// Convert to the C API StorePath type and convert to vector for index-based access
|
||||
std::vector<StorePath> vec;
|
||||
for (auto &sp : storePaths) {
|
||||
vec.push_back(StorePath{sp});
|
||||
}
|
||||
|
||||
return new nix_realised_string {
|
||||
.str = s,
|
||||
.storePaths = vec
|
||||
};
|
||||
}
|
||||
NIXC_CATCH_ERRS_NULL
|
||||
}
|
||||
|
||||
void nix_realised_string_free(nix_realised_string * s)
|
||||
{
|
||||
delete s;
|
||||
}
|
||||
|
||||
size_t nix_realised_string_get_buffer_size(nix_realised_string * s)
|
||||
{
|
||||
return s->str.size();
|
||||
}
|
||||
|
||||
const char * nix_realised_string_get_buffer_start(nix_realised_string * s)
|
||||
{
|
||||
return s->str.data();
|
||||
}
|
||||
|
||||
size_t nix_realised_string_get_store_path_count(nix_realised_string * s)
|
||||
{
|
||||
return s->storePaths.size();
|
||||
}
|
||||
|
||||
const StorePath * nix_realised_string_get_store_path(nix_realised_string * s, size_t i)
|
||||
{
|
||||
return &s->storePaths[i];
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue