For example, instead of doing
#include "nix/store-config.hh"
#include "nix/derived-path.hh"
Now do
#include "nix/store/config.hh"
#include "nix/store/derived-path.hh"
This was originally planned in the issue, and also recent requested by
Eelco.
Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.
Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!
Progress on #7876
(cherry picked from commit cc24766fa6)
69 lines
2.0 KiB
C++
69 lines
2.0 KiB
C++
#include "nix_api_store.h"
|
|
#include "nix_api_store_internal.h"
|
|
#include "nix_api_util.h"
|
|
#include "nix_api_util_internal.h"
|
|
#include "nix_api_expr.h"
|
|
#include "nix_api_expr_internal.h"
|
|
#include "nix_api_value.h"
|
|
#include "nix_api_external.h"
|
|
|
|
#include "nix/expr/tests/nix_api_expr.hh"
|
|
#include "nix/util/tests/string_callback.hh"
|
|
|
|
#include <gtest/gtest.h>
|
|
|
|
namespace nixC {
|
|
|
|
class MyExternalValueDesc : public NixCExternalValueDesc
|
|
{
|
|
public:
|
|
MyExternalValueDesc(int x)
|
|
: _x(x)
|
|
{
|
|
print = print_function;
|
|
showType = show_type_function;
|
|
typeOf = type_of_function;
|
|
}
|
|
|
|
private:
|
|
int _x;
|
|
static void print_function(void * self, nix_printer * printer) {}
|
|
|
|
static void show_type_function(void * self, nix_string_return * res) {}
|
|
|
|
static void type_of_function(void * self, nix_string_return * res)
|
|
{
|
|
MyExternalValueDesc * obj = static_cast<MyExternalValueDesc *>(self);
|
|
|
|
std::string type_string = "nix-external<MyExternalValueDesc( ";
|
|
type_string += std::to_string(obj->_x);
|
|
type_string += " )>";
|
|
res->str = &*type_string.begin();
|
|
}
|
|
};
|
|
|
|
TEST_F(nix_api_expr_test, nix_expr_eval_external)
|
|
{
|
|
MyExternalValueDesc * external = new MyExternalValueDesc(42);
|
|
ExternalValue * val = nix_create_external_value(ctx, external, external);
|
|
nix_init_external(ctx, value, val);
|
|
|
|
EvalState * stateResult = nix_state_create(nullptr, nullptr, store);
|
|
nix_value * valueResult = nix_alloc_value(nullptr, stateResult);
|
|
|
|
EvalState * stateFn = nix_state_create(nullptr, nullptr, store);
|
|
nix_value * valueFn = nix_alloc_value(nullptr, stateFn);
|
|
|
|
nix_expr_eval_from_string(nullptr, state, "builtins.typeOf", ".", valueFn);
|
|
|
|
ASSERT_EQ(NIX_TYPE_EXTERNAL, nix_get_type(nullptr, value));
|
|
|
|
nix_value_call(ctx, state, valueFn, value, valueResult);
|
|
|
|
std::string string_value;
|
|
nix_get_string(nullptr, valueResult, OBSERVE_STRING(string_value));
|
|
ASSERT_STREQ("nix-external<MyExternalValueDesc( 42 )>", string_value.c_str());
|
|
}
|
|
|
|
}
|