* Added a function to write manifests.

This commit is contained in:
Eelco Dolstra 2004-12-28 21:11:28 +00:00
parent 3d1b2101cc
commit 4bf58d5379
2 changed files with 86 additions and 41 deletions

View file

@ -2,6 +2,7 @@
use strict; use strict;
use POSIX qw(tmpnam); use POSIX qw(tmpnam);
use readmanifest;
my $tmpdir; my $tmpdir;
do { $tmpdir = tmpnam(); } do { $tmpdir = tmpnam(); }
@ -25,7 +26,7 @@ my $manifest_put_url = shift @ARGV;
# From the given store expressions, determine the requisite store # From the given store expressions, determine the requisite store
# paths. # paths.
my %storepaths; my %storePaths;
foreach my $storeexpr (@ARGV) { foreach my $storeexpr (@ARGV) {
die unless $storeexpr =~ /^\//; die unless $storeexpr =~ /^\//;
@ -39,12 +40,12 @@ foreach my $storeexpr (@ARGV) {
while (<PATHS>) { while (<PATHS>) {
chomp; chomp;
die "bad: $_" unless /^\//; die "bad: $_" unless /^\//;
$storepaths{$_} = ""; $storePaths{$_} = "";
} }
close PATHS; close PATHS;
} }
my @storepaths = keys %storepaths; my @storePaths = keys %storePaths;
# For each path, create a Nix expression that turns the path into # For each path, create a Nix expression that turns the path into
@ -52,14 +53,14 @@ my @storepaths = keys %storepaths;
open NIX, ">$nixfile"; open NIX, ">$nixfile";
print NIX "["; print NIX "[";
foreach my $storepath (@storepaths) { foreach my $storePath (@storePaths) {
die unless ($storepath =~ /\/[0-9a-z]{32}.*$/); die unless ($storePath =~ /\/[0-9a-z]{32}.*$/);
# Construct a Nix expression that creates a Nix archive. # Construct a Nix expression that creates a Nix archive.
my $nixexpr = my $nixexpr =
"((import @datadir@/nix/corepkgs/nar/nar.nix) " . "((import @datadir@/nix/corepkgs/nar/nar.nix) " .
# !!! $storepath should be represented as a closure # !!! $storePath should be represented as a closure
"{path = \"$storepath\"; system = \"@system@\";}) "; "{path = \"$storePath\"; system = \"@system@\";}) ";
print NIX $nixexpr; print NIX $nixexpr;
} }
@ -108,21 +109,23 @@ while (scalar @tmp > 0) {
# Create the manifest. # Create the manifest.
print STDERR "creating manifest...\n"; print STDERR "creating manifest...\n";
open MANIFEST, ">$manifest"; my %narFiles;
my %patches;
my %successors;
my @nararchives; my @nararchives;
for (my $n = 0; $n < scalar @storepaths; $n++) { for (my $n = 0; $n < scalar @storePaths; $n++) {
my $storepath = $storepaths[$n]; my $storePath = $storePaths[$n];
my $nardir = $narpaths[$n]; my $nardir = $narpaths[$n];
$storepath =~ /\/([^\/]*)$/; $storePath =~ /\/([^\/]*)$/;
my $basename = $1; my $basename = $1;
defined $basename or die; defined $basename or die;
my $narname = "$basename.nar.bz2"; my $narname = "$basename.nar.bz2";
my $narfile = "$nardir/$narname"; my $narfile = "$nardir/$narname";
(-f $narfile) or die "narfile for $storepath not found"; (-f $narfile) or die "narfile for $storePath not found";
push @nararchives, $narfile; push @nararchives, $narfile;
open MD5, "$nardir/narbz2-hash" or die "cannot open narbz2-hash"; open MD5, "$nardir/narbz2-hash" or die "cannot open narbz2-hash";
@ -137,34 +140,34 @@ for (my $n = 0; $n < scalar @storepaths; $n++) {
$narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash"; $narHash =~ /^[0-9a-z]{32}$/ or die "invalid hash";
close MD5; close MD5;
my $size = (stat $narfile)[7]; my $narbz2Size = (stat $narfile)[7];
print MANIFEST "{\n"; $narFiles{$storePath} = [
print MANIFEST " StorePath: $storepath\n"; { url => $archives_get_url/$narname
print MANIFEST " NarURL: $archives_get_url/$narname\n"; , hash => $narbz2Hash
print MANIFEST " MD5: $narbz2Hash\n"; , size => $narbz2Size
print MANIFEST " NarHash: $narHash\n"; , narHash => $narHash
print MANIFEST " Size: $size\n"; }
];
if ($storepath =~ /\.store$/) { if ($storePath =~ /\.store$/) {
open PREDS, "@bindir@/nix-store --query --predecessors $storepath |" or die "cannot run nix"; open PREDS, "@bindir@/nix-store --query --predecessors $storePath |" or die "cannot run nix";
while (<PREDS>) { while (<PREDS>) {
chomp; chomp;
die unless (/^\//); die unless (/^\//);
my $pred = $_; my $pred = $_;
# Only include predecessors that are themselves being # Only include predecessors that are themselves being
# pushed. # pushed.
if (defined $storepaths{$pred}) { if (defined $storePaths{$pred}) {
print MANIFEST " SuccOf: $pred\n"; $successors{$pred} = $storePath;
} }
} }
close PREDS; close PREDS;
} }
print MANIFEST "}\n";
} }
close MANIFEST; writeManifest $manifest, \%narFiles, \%patches, \%successors;
# Upload the archives. # Upload the archives.

View file

@ -1,5 +1,6 @@
use strict; use strict;
sub readManifest { sub readManifest {
my $manifest = shift; my $manifest = shift;
my $narFiles = shift; my $narFiles = shift;
@ -27,28 +28,22 @@ sub readManifest {
next if (/^$/); next if (/^$/);
if (!$inside) { if (!$inside) {
if (/^\{$/) {
$type = "narfile"; if (/^\s*(\w*)\s*\{$/) {
$type = $1;
$type = "narfile" if $type eq "";
$inside = 1; $inside = 1;
undef $storePath; undef $storePath;
undef $url; undef $url;
undef $hash; undef $hash;
$size = 999999999; undef $size;
@preds = (); @preds = ();
undef $narHash; undef $narHash;
}
elsif (/^patch \{$/) {
$type = "patch";
$inside = 1;
undef $url;
undef $hash;
undef $size;
undef $basePath; undef $basePath;
undef $baseHash; undef $baseHash;
undef $patchType; undef $patchType;
undef $narHash; }
}
else { die "bad line: $_"; }
} else { } else {
if (/^\}$/) { if (/^\}$/) {
@ -107,7 +102,7 @@ sub readManifest {
push @{$patchList}, push @{$patchList},
{ url => $url, hash => $hash, size => $size { url => $url, hash => $hash, size => $size
, basePath => $basePath, baseHash => $baseHash , basePath => $basePath, baseHash => $baseHash
, narHash => $narHash , narHash => $narHash, type => $patchType
}; };
} }
@ -129,7 +124,6 @@ sub readManifest {
elsif (/^\s*NarURL:\s*(\S+)\s*$/) { $url = $1; } elsif (/^\s*NarURL:\s*(\S+)\s*$/) { $url = $1; }
elsif (/^\s*MD5:\s*(\S+)\s*$/) { $hash = $1; } elsif (/^\s*MD5:\s*(\S+)\s*$/) { $hash = $1; }
else { die "bad line: $_"; }
} }
} }
@ -137,4 +131,52 @@ sub readManifest {
} }
sub writeManifest
{
my $manifest = shift;
my $narFiles = shift;
my $patches = shift;
my $successors = shift;
open MANIFEST, ">$manifest";
foreach my $storePath (keys %{$narFiles}) {
my $narFileList = $$narFiles{$storePath};
foreach my $narFile (@{$narFileList}) {
print MANIFEST "{\n";
print MANIFEST " StorePath: $storePath\n";
print MANIFEST " NarURL: $narFile->{url}\n";
print MANIFEST " MD5: $narFile->{hash}\n";
print MANIFEST " NarHash: $narFile->{narHash}\n";
print MANIFEST " Size: $narFile->{size}\n";
foreach my $p (keys %{$successors}) { # !!! quadratic
if ($$successors{$p} eq $storePath) {
print MANIFEST " SuccOf: $p\n";
}
}
print MANIFEST "}\n";
}
}
foreach my $storePath (keys %{$patches}) {
my $patchList = $$patches{$storePath};
foreach my $patch (@{$patchList}) {
print MANIFEST "patch {\n";
print MANIFEST " StorePath: $storePath\n";
print MANIFEST " NarURL: $patch->{url}\n";
print MANIFEST " MD5: $patch->{hash}\n";
print MANIFEST " NarHash: $patch->{narHash}\n";
print MANIFEST " Size: $patch->{size}\n";
print MANIFEST " BasePath: $patch->{basePath}\n";
print MANIFEST " BaseHash: $patch->{baseHash}\n";
print MANIFEST " Type: $patch->{patchType}\n";
print MANIFEST "}\n";
}
}
close MANIFEST;
}
return 1; return 1;