summary refs log tree commit diff
path: root/pkgs/build-support/kernel/paths-from-graph.pl
blob: 9a199a2b304478537462f41c7ad7c8fb67c5864d (plain) (blame)
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
# Parses a /nix/store/*-closure file and prints
# various information.
# By default, the nodes in the graph are printed to stdout.
# If the environment variable printManifest is set,
# then the graph is written as a manifest.
# If printRegistration is set, then the graph is written
# as a registration file for a manifest is written
# in the `nix-store --load-db' format.

use strict;
use File::Basename;

my %storePaths;
my %refs;

# Each argument on the command line is a graph file.
# The graph file contains line-triples and a variable
# number of references:
# <store-path>
# <deriver>
# <count>
# <ref-#1>
# ...
# <ref-#count>
foreach my $graph (@ARGV) {
    open GRAPH, "<$graph" or die;

    while (<GRAPH>) {
        chomp;
        my $storePath = "$_";
        $storePaths{$storePath} = 1;

        my $deriver = <GRAPH>; chomp $deriver;
        my $count = <GRAPH>; chomp $count;

        my @refs = ();
        for (my $i = 0; $i < $count; ++$i) {
            my $ref = <GRAPH>; chomp $ref;
            push @refs, $ref;
        }
        $refs{$storePath} = \@refs;
        
    }
    
    close GRAPH;
}


if ($ENV{"printManifest"} eq "1") {
    print "version {\n";
    print "  ManifestVersion: 3\n";
    print "}\n";

    foreach my $storePath (sort (keys %storePaths)) {
        my $base = basename $storePath;
        print "localPath {\n";
        print "  StorePath: $storePath\n";
        print "  CopyFrom: /tmp/inst-store/$base\n";
        print "  References: ";
        foreach my $ref (@{$refs{$storePath}}) {
            print "$ref ";
        }
        print "\n";
        print "}\n";
    }
}

elsif ($ENV{"printRegistration"} eq "1") {
    # This is the format used by `nix-store --register-validity
    # --hash-given' / `nix-store --load-db'.
    foreach my $storePath (sort (keys %storePaths)) {
        print "$storePath\n";
        print "0000000000000000000000000000000000000000000000000000000000000000\n"; # !!! fix
        print "0\n"; # !!! fix	
        print "\n"; # don't care about preserving the deriver
        print scalar(@{$refs{$storePath}}), "\n";
        foreach my $ref (@{$refs{$storePath}}) {
            print "$ref\n";
        }
    }
}

else {
    foreach my $storePath (sort (keys %storePaths)) {
        print "$storePath\n";
    }
}