* Use ATerms for Nix descriptors.
This commit is contained in:
parent
ced20f187e
commit
383f9bb0f1
4 changed files with 57 additions and 34 deletions
|
@ -3,7 +3,7 @@ all: nix nix-instantiate
|
|||
SYSTEM = $(shell ./config.guess)
|
||||
|
||||
nix: nix.o md5.o
|
||||
g++ -g -o $@ $^ -ldb_cxx-4
|
||||
g++ -g -o $@ $^ -ldb_cxx-4 -lATerm
|
||||
|
||||
%.o: %.cc
|
||||
g++ -g -Wall -o $@ -c $< -DSYSTEM=\"$(SYSTEM)\"
|
||||
|
|
|
@ -59,37 +59,57 @@ sub convert {
|
|||
my $OUT = new FileHandle;
|
||||
my $tmpfile = "$outdir/$fn-tmp";
|
||||
open $IN, "< $descr" or die "cannot open $descr";
|
||||
open $OUT, "> $tmpfile" or die "cannot create $tmpfile";
|
||||
|
||||
print $OUT "system : $system\n";
|
||||
# Descr([Bind("x", Str("y")), Bind("x", File("1234")), Bind("x", Pkg("1234"))])
|
||||
# bindings alphabetisch gesorteerd
|
||||
|
||||
my %bindings;
|
||||
|
||||
while (<$IN>) {
|
||||
chomp;
|
||||
s/\s*#.*$//;
|
||||
next if (/^$/);
|
||||
|
||||
if (/^(\w+)\s*=\s*([^\#\s]*)\s*(\#.*)?$/) {
|
||||
my ($name, $loc) = ($1, $2);
|
||||
my $file = fetchFile($loc);
|
||||
$file = File::Spec->rel2abs($file, $dir);
|
||||
my $hash = hashFile($file);
|
||||
print $OUT "$name = $hash\n";
|
||||
$bindings{$name} = "File(\"$hash\")";
|
||||
} elsif (/^(\w+)\s*<-\s*([+\w\d\.\/-]+)\s*(\#.*)?$/) {
|
||||
my $name = $1;
|
||||
my $file = $2;
|
||||
$file = File::Spec->rel2abs($file, $dir);
|
||||
$file = convert($file);
|
||||
my $hash = hashFile($file);
|
||||
print $OUT "$name <- $hash\n";
|
||||
$bindings{$name} = "Pkg(\"$hash\")";
|
||||
} elsif (/^(\w+)\s*:\s*([+\w\d\.\/-]+)\s*(\#.*)?$/) {
|
||||
my $name = $1;
|
||||
my $value = $2;
|
||||
$bindings{$name} = "Str(\"$value\")";
|
||||
} else {
|
||||
print $OUT "$_\n";
|
||||
die "syntax error: $_";
|
||||
}
|
||||
}
|
||||
|
||||
close $OUT;
|
||||
close $IN;
|
||||
|
||||
$bindings{"system"} = "Str(\"$system\")";
|
||||
|
||||
open $OUT, "| baffle -wt > $tmpfile" or die "cannot create $tmpfile";
|
||||
print $OUT "Descr([";
|
||||
my $first = 1;
|
||||
foreach my $name (sort (keys %bindings)) {
|
||||
if (!$first) { print $OUT ","; };
|
||||
print $OUT "Bind(\"$name\",$bindings{$name})";
|
||||
$first = 0;
|
||||
}
|
||||
print $OUT "])";
|
||||
close $OUT;
|
||||
|
||||
my $hash = hashFile($tmpfile);
|
||||
|
||||
my $outfile = "$outdir/$hash-$fn";
|
||||
my $outfile = "$outdir/$fn-$hash";
|
||||
rename($tmpfile, $outfile) or die "cannot rename $tmpfile to $outfile";
|
||||
|
||||
$donetmpls{$descr} = $outfile;
|
||||
|
|
|
@ -6,7 +6,7 @@ my $pkglist = $ENV{"NIX_ACTIVATIONS"};
|
|||
$pkglist or die "NIX_ACTIVATIONS not set";
|
||||
my $linkdir = $ENV{"NIX_LINKS"};
|
||||
$linkdir or die "NIX_LINKS not set";
|
||||
my @dirs = ("bin", "sbin", "lib");
|
||||
my @dirs = ("bin", "sbin", "lib", "include");
|
||||
|
||||
# Figure out a generation number.
|
||||
my $nr = 1;
|
||||
|
|
53
src/nix.cc
53
src/nix.cc
|
@ -16,6 +16,10 @@
|
|||
|
||||
#include <db4/db_cxx.h>
|
||||
|
||||
extern "C" {
|
||||
#include <aterm1.h>
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
#include "md5.h"
|
||||
}
|
||||
|
@ -210,33 +214,29 @@ void readPkgDescr(const string & hash,
|
|||
if (hashFile(pkgfile) != hash)
|
||||
throw Error("file " + pkgfile + " is stale");
|
||||
|
||||
ifstream file;
|
||||
file.exceptions(ios::badbit);
|
||||
file.open(pkgfile.c_str());
|
||||
|
||||
while (!file.eof()) {
|
||||
string line;
|
||||
getline(file, line);
|
||||
ATerm term = ATreadFromNamedFile(pkgfile.c_str());
|
||||
if (!term) throw Error("cannot read aterm " + pkgfile);
|
||||
|
||||
int n = line.find('#');
|
||||
if (n >= 0) line = line.erase(n);
|
||||
ATerm bindings;
|
||||
if (!ATmatch(term, "Descr(<term>)", &bindings))
|
||||
throw Error("invalid term in " + pkgfile);
|
||||
|
||||
if ((int) line.find_first_not_of(" ") < 0) continue;
|
||||
|
||||
istringstream str(line);
|
||||
|
||||
string name, op, ref;
|
||||
str >> name >> op >> ref;
|
||||
|
||||
if (op == "<-") {
|
||||
checkHash(ref);
|
||||
pkgImports[name] = ref;
|
||||
} else if (op == "=") {
|
||||
checkHash(ref);
|
||||
fileImports[name] = ref;
|
||||
} else if (op == ":")
|
||||
arguments[name] = ref;
|
||||
else throw Error("invalid operator " + op);
|
||||
char * cname;
|
||||
ATerm value;
|
||||
while (ATmatch(bindings, "[Bind(<str>, <term>), <list>]",
|
||||
&cname, &value, &bindings))
|
||||
{
|
||||
string name(cname);
|
||||
char * arg;
|
||||
if (ATmatch(value, "Pkg(<str>)", &arg)) {
|
||||
checkHash(arg);
|
||||
pkgImports[name] = arg;
|
||||
} else if (ATmatch(value, "File(<str>)", &arg)) {
|
||||
checkHash(arg);
|
||||
fileImports[name] = arg;
|
||||
} else if (ATmatch(value, "Str(<str>)", &arg))
|
||||
arguments[name] = arg;
|
||||
else throw Error("invalid binding in " + pkgfile);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -747,6 +747,9 @@ void main2(int argc, char * * argv)
|
|||
|
||||
int main(int argc, char * * argv)
|
||||
{
|
||||
ATerm bottomOfStack;
|
||||
ATinit(argc, argv, &bottomOfStack);
|
||||
|
||||
prog = *argv++, argc--;
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue