aboutsummaryrefslogtreecommitdiff
path: root/nix/libstore/misc.cc
blob: d4e6d1b4afc43699110b2475bd3c771df263068f (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "misc.hh"
#include "store-api.hh"
#include "local-store.hh"
#include "globals.hh"


namespace nix {


Derivation derivationFromPath(StoreAPI & store, const Path & drvPath)
{
    assertStorePath(drvPath);
    store.ensurePath(drvPath);
    return readDerivation(drvPath);
}


void computeFSClosure(StoreAPI & store, const Path & path,
    PathSet & paths, bool flipDirection, bool includeOutputs, bool includeDerivers)
{
    if (paths.find(path) != paths.end()) return;
    paths.insert(path);

    PathSet edges;

    if (flipDirection) {
        store.queryReferrers(path, edges);

        if (includeOutputs) {
            PathSet derivers = store.queryValidDerivers(path);
            foreach (PathSet::iterator, i, derivers)
                edges.insert(*i);
        }

        if (includeDerivers && isDerivation(path)) {
            PathSet outputs = store.queryDerivationOutputs(path);
            foreach (PathSet::iterator, i, outputs)
                if (store.isValidPath(*i) && store.queryDeriver(*i) == path)
                    edges.insert(*i);
        }

    } else {
        store.queryReferences(path, edges);

        if (includeOutputs && isDerivation(path)) {
            PathSet outputs = store.queryDerivationOutputs(path);
            foreach (PathSet::iterator, i, outputs)
                if (store.isValidPath(*i)) edges.insert(*i);
        }

        if (includeDerivers) {
            Path deriver = store.queryDeriver(path);
            if (store.isValidPath(deriver)) edges.insert(deriver);
        }
    }

    foreach (PathSet::iterator, i, edges)
        computeFSClosure(store, *i, paths, flipDirection, includeOutputs, includeDerivers);
}


static void dfsVisit(StoreAPI & store, const PathSet & paths,
    const Path & path, PathSet & visited, Paths & sorted,
    PathSet & parents)
{
    if (parents.find(path) != parents.end())
        throw BuildError(format("cycle detected in the references of `%1%'") % path);

    if (visited.find(path) != visited.end()) return;
    visited.insert(path);
    parents.insert(path);

    PathSet references;
    if (store.isValidPath(path))
        store.queryReferences(path, references);

    foreach (PathSet::iterator, i, references)
        /* Don't traverse into paths that don't exist.  That can
           happen due to substitutes for non-existent paths. */
        if (*i != path && paths.find(*i) != paths.end())
            dfsVisit(store, paths, *i, visited, sorted, parents);

    sorted.push_front(path);
    parents.erase(path);
}


Paths topoSortPaths(StoreAPI & store, const PathSet & paths)
{
    Paths sorted;
    PathSet visited, parents;
    foreach (PathSet::const_iterator, i, paths)
        dfsVisit(store, paths, *i, visited, sorted, parents);
    return sorted;
}


}
d>Arun Isaac 2020-10-12gnu: rust-percent-encoding-2.1: Remove minor version from variable name....* gnu/packages/crates-io.scm (rust-percent-encoding-2.1): Rename to rust-percent-encoding-2. Arun Isaac 2020-10-12gnu: rust-url-2.1: Remove minor version from variable name....* gnu/packages/crates-io.scm (rust-url-2.1): Rename to rust-url-2. Arun Isaac 2020-10-12gnu: rust-thiserror-1.0: Remove minor version from variable name....* gnu/packages/crates-io.scm (rust-thiserror-1.0): Rename to rust-thiserror-1. Arun Isaac 2020-08-04gnu: rust-proc-macro2: Don't include minor version in variable name....* gnu/packages/crates-io.scm (rust-proc-macro2-1.0): Rename to... (rust-proc-macro2-1): ...this. * gnu/packages/rust-apps.scm (rust-cbindgen): Fixup dependency list. * gnu/packages/sequoia.scm (sequoia): Likewise. Jakub Kądziołka 2020-06-23gnu: sequoia: Update to 0.17.0....* gnu/packages/sequoia.scm (sequoia): Update to 0.17.0. [cargo-inputs]: Add rust-structopt-0.3. [phases](unpin-deps): New phase. Jakub Kądziołka 2020-06-22gnu: sequoia: Fix typos....* gnu/packages/sequoia.scm (sequoia)[arguments]: Move unquote next to the expression it applies to. Efraim Flashner 2020-06-22gnu: rust-regex-1.3: Rename to rust-regex-1....* gnu/packages/crates-io.scm (rust-regex-1.3): Rename to rust-regex-1. (rust-ansi-term-0.12, rust-bindgen-0.52, rust-bindgen-0.51, rust-bindgen-0.50, rust-bindgen-0.37, rust-bindgen-0.49, rust-clap-2, rust-compiletest-rs-0.3, rust-console-0.9, rust-console-0.7, rust-docopt-1.1, rust-env-logger-0.7, rust-env-logger-0.6, rust-env-logger-0.5, rust-gimli-0.18, rust-globset-0.4, rust-grep-cli-0.1, rust-grep-matcher-0.1, rust-grep-regex-0.1, rust-grep-searcher-0.1, rust-ignore-0.4, rust-lalrpop-0.17, rust-lalrpop-util-0.17, rust-locale-config-0.3, rust-localeconfig-0.2, rust-nom-5, rust-nom-4.2, rust-once-cell-1.2, rust-proptest-0.9, rust-proptest-0.8, rust-pulldown-cmark-0.4, rust-regex-automata-0.1, rust-rusqlite-0.19, rust-scan-fmt-0.2, rust-syn-1.0, rust-syn-0.15, rust-ucd-parse-0.1, rust-version-sync-0.8) [arguments]: Adjust accordingly. * gnu/packages/gnome.scm (librsvg-next)[arguments]: Same. * gnu/packages/rust-apps.scm (fd, ripgrep, tokei, rust-cargo-c) [arguments]: Same. * gnu/packages/sequoia.scm (sequoia)[arguments]: Same. Efraim Flashner 2020-06-22gnu: rust-tempfile-3.1: Rename to rust-tempfile-3....* gnu/packages/crates-io.scm (rust-tempfile-3.1): Rename to ... (rust-tempfile-3): .. this. (rust-cairo-rs-0.8, rust-cairo-rs-0.7, rust-cc-1.0, rust-compiletest-rs-0.3, rust-filetime-0.2, rust-gdk-pixbuf-sys-0.9, rust-gio-sys-0.9, rust-git2-0.11, rust-glib-0.9, rust-glib-0.8, rust-glib-sys-0.9, rust-gobject-sys-0.9, rust-handlebars-2.0, rust-lscolors-0.6, rust-native-tls-0.2, rust-nix-0.15, rust-nix-0.14, rust-no-panic-0.1, rust-pango-sys-0.9, rust-pangocairo-0.10, rust-proptest-0.9, rust-proptest-0.8, rust-rustdoc-stripper-0.1, rust-rustls-0.16, rust-rusty-fork-0.2, rust-sourcefile-0.1, rust-tiff-0.2, rust-tokio-0.2, rust-tokio-fs-0.1, rust-tokio-uds-0.2, rust-wayland-client-0.23, rust-wayland-client-0.21, rust-xattr-0.2) [arguments]: Adjust accordingly. * gnu/packages/rust-apps.scm (rust-cbindgen, tokei)[arguments]: Same. * gnu/packages/sequoia.scm (sequoia)[arguments]: Same. * gnu/packages/terminals.scm (alacritty)[arguments]: Same. Efraim Flashner 2020-05-11gnu: sequoia: Fix pkgconfig files....The pkgconfig files defines the wrong prefix: It is the build directory, while it should be the installation prefix. This is caused by Makefiles replacing `PREFIX` by `$(shell pwd)`. See <https://gitlab.com/sequoia-pgp/sequoia/-/issues/502> for details. * gnu/packages/sequoia.scm (sequoia)[fix-pkgconfig-file-substitutes]: New phase. Hartmut Goebel 2020-05-05gnu: Add sequoia....* gnu/packages/sequoia.scm: New file. * gnu/local.mk: Add it. Hartmut Goebel