about summary refs log tree commit diff
path: root/pkgs/games/build-support/build-sandbox/src/nix-query.cc
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2017-11-30 06:42:49 +0100
committeraszlig <aszlig@nix.build>2017-11-30 08:33:59 +0100
commit38d3fe573f4d0ad2115eaca71a0b8f67fd01a580 (patch)
treed09bf338919056089be3b59194fa7b647794b15b /pkgs/games/build-support/build-sandbox/src/nix-query.cc
parent28ac40c9d9e1c9afc63c19646f223b28b7ed3bc8 (diff)
build-sandbox: Move to top-level build-support
This is not only useful for packaging games, so let's make it available
from the vuizvui scope, so we can use it from other packages as well.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/games/build-support/build-sandbox/src/nix-query.cc')
-rw-r--r--pkgs/games/build-support/build-sandbox/src/nix-query.cc118
1 files changed, 0 insertions, 118 deletions
diff --git a/pkgs/games/build-support/build-sandbox/src/nix-query.cc b/pkgs/games/build-support/build-sandbox/src/nix-query.cc
deleted file mode 100644
index 71208693..00000000
--- a/pkgs/games/build-support/build-sandbox/src/nix-query.cc
+++ /dev/null
@@ -1,118 +0,0 @@
-#include <iostream>
-
-#if NIX_VERSION >= 112
-#include <nix/config.h>
-#endif
-#include <nix/util.hh>
-#include <nix/local-store.hh>
-#include <nix/store-api.hh>
-
-#if NIX_VERSION < 112
-#include <nix/misc.hh>
-#include <nix/globals.hh>
-#endif
-
-using namespace nix;
-
-struct query_state {
-#if NIX_VERSION >= 112
-    std::shared_ptr<Store> store;
-#else
-    std::shared_ptr<StoreAPI> store;
-#endif
-    PathSet paths;
-    PathSet::iterator iter;
-};
-
-static Path get_store_path(query_state *qs, Path path)
-{
-    Path canonicalized = canonPath(path, true);
-#if NIX_VERSION >= 112
-    return qs->store->toStorePath(canonicalized);
-#else
-    return toStorePath(canonicalized);
-#endif
-}
-
-static Path get_ancestor(query_state *qs, Path path)
-{
-    size_t pos = 0;
-    std::string tmp;
-
-    while (pos != std::string::npos) {
-        if ((pos = path.find('/', pos + 1)) != std::string::npos) {
-            Path current = path.substr(0, pos);
-
-            if (!isLink(current))
-                continue;
-
-            try {
-                current = get_store_path(qs, current);
-            } catch (...) {
-                continue;
-            }
-
-            return current;
-        }
-    }
-
-    return get_store_path(qs, path);
-}
-
-extern "C" {
-    struct query_state *new_query(void)
-    {
-        query_state *initial = new query_state();
-#if NIX_VERSION >= 112
-        initial->store = openStore();
-#else
-        settings.processEnvironment();
-        settings.loadConfFile();
-        initial->store = openStore(false);
-#endif
-        return initial;
-    }
-
-    void free_query(query_state *qs)
-    {
-        delete qs;
-    }
-
-    bool query_requisites(query_state *qs, const char *path)
-    {
-        Path query(path);
-
-        try {
-            query = get_ancestor(qs, query);
-
-#if NIX_VERSION >= 112
-            qs->store->computeFSClosure(
-                qs->store->followLinksToStorePath(query),
-                qs->paths, false, true
-            );
-#else
-            computeFSClosure(
-                *qs->store, followLinksToStorePath(query),
-                qs->paths, false, true
-            );
-#endif
-        } catch (Error &e) {
-            std::cerr << "Error while querying requisites for "
-                      << query << ": " << e.what()
-                      << std::endl;
-            return false;
-        }
-
-        qs->iter = qs->paths.begin();
-
-        return true;
-    }
-
-    const char *next_query_result(query_state *qs)
-    {
-        if (qs->iter == qs->paths.end())
-            return NULL;
-
-        return (qs->iter++)->c_str();
-    }
-}