-
-
Notifications
You must be signed in to change notification settings - Fork 2k
libexpr-c: expose essential evaluator functions for derivation tree inspection #15842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e657658
libexpr-c: expose `nix_get_derivation` and `nix_value_auto_call_funct…
NotAShelf 9f2bd6c
libexpr-c: document eval helpers without C++ internals; add tests
NotAShelf a17e200
libexpr-c: deduplicate value validation helpers into internal header
NotAShelf 8818381
libexpr-c: force and validate auto-call arguments
NotAShelf c0a0ce1
libexpr-c: correct and simplify eval helper API docs
NotAShelf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| #include "nix/expr/eval.hh" | ||
| #include "nix/expr/get-drvs.hh" | ||
|
|
||
| #include "nix_api_expr.h" | ||
| #include "nix_api_expr_internal.h" | ||
| #include "nix_api_store.h" | ||
| #include "nix_api_store_internal.h" | ||
| #include "nix_api_util.h" | ||
| #include "nix_api_util_internal.h" | ||
|
|
||
| static const nix::Bindings * get_bindings_or_null(nix_value * autoArgs) | ||
| { | ||
| if (!autoArgs) { | ||
| return nullptr; | ||
| } | ||
| auto & v = check_value_in(autoArgs); | ||
| if (v.type() == nix::nAttrs) { | ||
| return v.attrs(); | ||
| } | ||
| return nullptr; | ||
| } | ||
|
|
||
| extern "C" { | ||
|
|
||
| StorePath * | ||
| nix_get_derivation(nix_c_context * context, EvalState * state, nix_value * value, bool ignoreAssertionFailures) | ||
| { | ||
| if (context) | ||
| context->last_err_code = NIX_OK; | ||
| try { | ||
| auto & v = check_value_in(value); | ||
| auto maybePkg = nix::getDerivation(state->state, v, ignoreAssertionFailures); | ||
| if (!maybePkg) { | ||
| return nullptr; | ||
| } | ||
| nix::StorePath sp = maybePkg->requireDrvPath(); | ||
| return new StorePath{std::move(sp)}; | ||
| } | ||
| NIXC_CATCH_ERRS_NULL | ||
| } | ||
|
|
||
| nix_err nix_value_auto_call_function( | ||
| nix_c_context * context, EvalState * state, nix_value * auto_args, nix_value * fn_val, nix_value * result) | ||
| { | ||
| if (context) | ||
| context->last_err_code = NIX_OK; | ||
| try { | ||
| auto & fn = check_value_in(fn_val); | ||
| auto & res = *result->value; | ||
|
|
||
| const nix::Bindings * b = get_bindings_or_null(auto_args); | ||
|
NotAShelf marked this conversation as resolved.
Outdated
|
||
| if (b) { | ||
| state->state.autoCallFunction(*b, fn, res); | ||
| } else { | ||
| state->state.autoCallFunction(nix::Bindings::emptyBindings, fn, res); | ||
| } | ||
| } | ||
| NIXC_CATCH_ERRS | ||
| } | ||
|
|
||
| } // extern "C" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.