mirror of
https://github.com/NixOS/nix
synced 2025-07-08 15:13:55 +02:00
Merge pull request #8517 from hercules-ci/fix-build-hook-error-for-lib-users
Fix build hook error for libstore library users
This commit is contained in:
commit
713836112c
8 changed files with 97 additions and 1 deletions
|
@ -135,6 +135,7 @@ nix_tests = \
|
|||
flakes/show.sh \
|
||||
impure-derivations.sh \
|
||||
path-from-hash-part.sh \
|
||||
test-libstoreconsumer.sh \
|
||||
toString-path.sh
|
||||
|
||||
ifeq ($(HAVE_LIBCPUID), 1)
|
||||
|
@ -153,6 +154,7 @@ test-deps += \
|
|||
tests/common/vars-and-functions.sh \
|
||||
tests/config.nix \
|
||||
tests/ca/config.nix \
|
||||
tests/test-libstoreconsumer/test-libstoreconsumer \
|
||||
tests/dyn-drv/config.nix
|
||||
|
||||
ifeq ($(BUILD_SHARED_LIBS), 1)
|
||||
|
|
6
tests/test-libstoreconsumer.sh
Normal file
6
tests/test-libstoreconsumer.sh
Normal file
|
@ -0,0 +1,6 @@
|
|||
source common.sh
|
||||
|
||||
drv="$(nix-instantiate simple.nix)"
|
||||
cat "$drv"
|
||||
out="$(./test-libstoreconsumer/test-libstoreconsumer "$drv")"
|
||||
cat "$out/hello" | grep -F "Hello World!"
|
6
tests/test-libstoreconsumer/README.md
Normal file
6
tests/test-libstoreconsumer/README.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
A very simple C++ consumer of the libstore library.
|
||||
|
||||
- Keep it simple. Library consumers expect something simple.
|
||||
- No build hook, or any other reinvocations.
|
||||
- No more global state than necessary.
|
12
tests/test-libstoreconsumer/local.mk
Normal file
12
tests/test-libstoreconsumer/local.mk
Normal file
|
@ -0,0 +1,12 @@
|
|||
programs += test-libstoreconsumer
|
||||
|
||||
test-libstoreconsumer_DIR := $(d)
|
||||
|
||||
test-libstoreconsumer_SOURCES := \
|
||||
$(wildcard $(d)/*.cc) \
|
||||
|
||||
test-libstoreconsumer_CXXFLAGS += -I src/libutil -I src/libstore
|
||||
|
||||
test-libstoreconsumer_LIBS = libstore libutil
|
||||
|
||||
test-libstoreconsumer_LDFLAGS = -pthread $(SODIUM_LIBS) $(EDITLINE_LIBS) $(BOOST_LDFLAGS) $(LOWDOWN_LIBS)
|
45
tests/test-libstoreconsumer/main.cc
Normal file
45
tests/test-libstoreconsumer/main.cc
Normal file
|
@ -0,0 +1,45 @@
|
|||
#include "globals.hh"
|
||||
#include "store-api.hh"
|
||||
#include "build-result.hh"
|
||||
#include <iostream>
|
||||
|
||||
using namespace nix;
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
try {
|
||||
if (argc != 2) {
|
||||
std::cerr << "Usage: " << argv[0] << " store/path/to/something.drv\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::string drvPath = argv[1];
|
||||
|
||||
initLibStore();
|
||||
|
||||
auto store = nix::openStore();
|
||||
|
||||
// build the derivation
|
||||
|
||||
std::vector<DerivedPath> paths {
|
||||
DerivedPath::Built {
|
||||
.drvPath = store->parseStorePath(drvPath),
|
||||
.outputs = OutputsSpec::Names{"out"}
|
||||
}
|
||||
};
|
||||
|
||||
const auto results = store->buildPathsWithResults(paths, bmNormal, store);
|
||||
|
||||
for (const auto & result : results) {
|
||||
for (const auto & [outputName, realisation] : result.builtOutputs) {
|
||||
std::cout << store->printStorePath(realisation.outPath) << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
} catch (const std::exception & e) {
|
||||
std::cerr << "Error: " << e.what() << "\n";
|
||||
return 1;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue