diff options
author | John Ericson <John.Ericson@Obsidian.Systems> | 2023-12-01 13:53:13 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-01 13:53:13 -0500 |
commit | 211b6e18556e03829ae7bba38c7272af2900a2e8 (patch) | |
tree | bfcfef3efeb73cb0c3c6d812280191d03bda1233 /tests/functional/test-libstoreconsumer | |
parent | 72425212657d795dc215b334b7c8c8cd36d06b72 (diff) | |
parent | f7f37035c81fa825a4dfc2df1ad2589013ac6380 (diff) |
Merge pull request #9517 from NixOS/2.18-flatten-tests
[Backport 2.18-maintanence] Backport test source layout reorgs
Diffstat (limited to 'tests/functional/test-libstoreconsumer')
-rw-r--r-- | tests/functional/test-libstoreconsumer/README.md | 6 | ||||
-rw-r--r-- | tests/functional/test-libstoreconsumer/local.mk | 15 | ||||
-rw-r--r-- | tests/functional/test-libstoreconsumer/main.cc | 45 |
3 files changed, 66 insertions, 0 deletions
diff --git a/tests/functional/test-libstoreconsumer/README.md b/tests/functional/test-libstoreconsumer/README.md new file mode 100644 index 000000000..ded69850f --- /dev/null +++ b/tests/functional/test-libstoreconsumer/README.md @@ -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. diff --git a/tests/functional/test-libstoreconsumer/local.mk b/tests/functional/test-libstoreconsumer/local.mk new file mode 100644 index 000000000..edc140723 --- /dev/null +++ b/tests/functional/test-libstoreconsumer/local.mk @@ -0,0 +1,15 @@ +programs += test-libstoreconsumer + +test-libstoreconsumer_DIR := $(d) + +# do not install +test-libstoreconsumer_INSTALL_DIR := + +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) diff --git a/tests/functional/test-libstoreconsumer/main.cc b/tests/functional/test-libstoreconsumer/main.cc new file mode 100644 index 000000000..c61489af6 --- /dev/null +++ b/tests/functional/test-libstoreconsumer/main.cc @@ -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 = makeConstantStorePathRef(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; + } +} |