diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-03-24T12·49+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-03-24T12·49+0000 |
commit | 2dc84e556911407fe75e1ceb6a9fe34ed21725db (patch) | |
tree | 1d4bf6ac3ac1f4dadd94bb46c071ca18cb482bfb /src/nix-instantiate.in | |
parent | 9d2f128252ea9dc9b706bec2bfdaa35600190385 (diff) |
* Descriptors now have a "system" field specifying the platform that
the build or run action should be perfomed on. This ensures that descriptors have different hashes on different platforms.
Diffstat (limited to 'src/nix-instantiate.in')
-rwxr-xr-x | src/nix-instantiate.in | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/nix-instantiate.in b/src/nix-instantiate.in new file mode 100755 index 000000000000..e501a2c0836c --- /dev/null +++ b/src/nix-instantiate.in @@ -0,0 +1,89 @@ +#! /usr/bin/perl -w + +use strict; +use FileHandle; +use File::Spec; + +my $system = "@SYSTEM@"; + +my $outdir = File::Spec->rel2abs($ARGV[0]); +my $netdir = File::Spec->rel2abs($ARGV[1]); + +my %donetmpls = (); + +sub fetchFile { + my $loc = shift; + + if ($loc =~ /^([+\w\d\.\/-]+)$/) { + return $1; + } elsif ($loc =~ /^url\((.*)\)$/) { + my $url = $1; + $url =~ /\/([^\/]+)$/ || die "invalid url $url"; + my $fn = "$netdir/$1"; + if (! -f $fn) { + print "fetching $url...\n"; + system "cd $netdir; wget --quiet -N $url"; + if ($? != 0) { + unlink($fn); + die; + } + } + return $fn; + } else { + die "invalid file specified $loc"; + } +} + +sub convert { + my $descr = shift; + + if (defined $donetmpls{$descr}) { + return $donetmpls{$descr}; + } + + my ($x, $dir, $fn) = File::Spec->splitpath($descr); + + print "$descr\n"; + + my $IN = new FileHandle; + my $OUT = new FileHandle; + my $outfile = "$outdir/$fn"; + open $IN, "< $descr" or die "cannot open $descr"; + open $OUT, "> $outfile" or die "cannot create $outfile"; + + print $OUT "system : $system\n"; + + while (<$IN>) { + chomp; + + if (/^(\w+)\s*=\s*([^\#\s]*)\s*(\#.*)?$/) { + my ($name, $loc) = ($1, $2); + my $file = fetchFile($loc); + $file = File::Spec->rel2abs($file, $dir); + my $out = `md5sum $file`; + die unless ($? == 0); + $out =~ /^([0-9a-f]+)\s/; + my $hash = $1; + print $OUT "$name = $hash\n"; + } elsif (/^(\w+)\s*<-\s*([+\w\d\.\/-]+)\s*(\#.*)?$/) { + my $name = $1; + my $file = $2; + $file = File::Spec->rel2abs($file, $dir); + $file = convert($file); + my $out = `md5sum $file`; + die unless ($? == 0); + $out =~ /^([0-9a-f]+)\s/; + my $hash = $1; + print $OUT "$name <- $hash\n"; + } else { + print $OUT "$_\n"; + } + } + + $donetmpls{$descr} = $outfile; + return $outfile; +} + +for (my $i = 2; $i < scalar @ARGV; $i++) { + convert(File::Spec->rel2abs($ARGV[$i])); +} |