at 16.09-beta 87 lines 2.3 kB view raw
1# Parses a /nix/store/*-closure file and prints 2# various information. 3# By default, the nodes in the graph are printed to stdout. 4# If the environment variable printManifest is set, 5# then the graph is written as a manifest. 6# If printRegistration is set, then the graph is written 7# as a registration file for a manifest is written 8# in the `nix-store --load-db' format. 9 10use strict; 11use File::Basename; 12 13my %storePaths; 14my %refs; 15 16# Each argument on the command line is a graph file. 17# The graph file contains line-triples and a variable 18# number of references: 19# <store-path> 20# <deriver> 21# <count> 22# <ref-#1> 23# ... 24# <ref-#count> 25foreach my $graph (@ARGV) { 26 open GRAPH, "<$graph" or die; 27 28 while (<GRAPH>) { 29 chomp; 30 my $storePath = "$_"; 31 $storePaths{$storePath} = 1; 32 33 my $deriver = <GRAPH>; chomp $deriver; 34 my $count = <GRAPH>; chomp $count; 35 36 my @refs = (); 37 for (my $i = 0; $i < $count; ++$i) { 38 my $ref = <GRAPH>; chomp $ref; 39 push @refs, $ref; 40 } 41 $refs{$storePath} = \@refs; 42 43 } 44 45 close GRAPH; 46} 47 48 49if ($ENV{"printManifest"} eq "1") { 50 print "version {\n"; 51 print " ManifestVersion: 3\n"; 52 print "}\n"; 53 54 foreach my $storePath (sort (keys %storePaths)) { 55 my $base = basename $storePath; 56 print "localPath {\n"; 57 print " StorePath: $storePath\n"; 58 print " CopyFrom: /tmp/inst-store/$base\n"; 59 print " References: "; 60 foreach my $ref (@{$refs{$storePath}}) { 61 print "$ref "; 62 } 63 print "\n"; 64 print "}\n"; 65 } 66} 67 68elsif ($ENV{"printRegistration"} eq "1") { 69 # This is the format used by `nix-store --register-validity 70 # --hash-given' / `nix-store --load-db'. 71 foreach my $storePath (sort (keys %storePaths)) { 72 print "$storePath\n"; 73 print "0000000000000000000000000000000000000000000000000000000000000000\n"; # !!! fix 74 print "0\n"; # !!! fix 75 print "\n"; # don't care about preserving the deriver 76 print scalar(@{$refs{$storePath}}), "\n"; 77 foreach my $ref (@{$refs{$storePath}}) { 78 print "$ref\n"; 79 } 80 } 81} 82 83else { 84 foreach my $storePath (sort (keys %storePaths)) { 85 print "$storePath\n"; 86 } 87}