about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2003-04-01T14·00+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2003-04-01T14·00+0000
commit383f9bb0f19f76fa4cdbdfb5327d82e77212c1b6 (patch)
tree0a63999939d1a9cfc2143f08c68347f9ceb44b6b
parentced20f187e36927adc88ab628b67838f51155244 (diff)
* Use ATerms for Nix descriptors.
-rw-r--r--src/Makefile2
-rwxr-xr-xsrc/nix-instantiate.in34
-rwxr-xr-xsrc/nix-populate2
-rw-r--r--src/nix.cc53
4 files changed, 57 insertions, 34 deletions
diff --git a/src/Makefile b/src/Makefile
index 2372572758ad..3398b8f3af72 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -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)\"
diff --git a/src/nix-instantiate.in b/src/nix-instantiate.in
index 508b9eb28d07..b5093391b2d2 100755
--- a/src/nix-instantiate.in
+++ b/src/nix-instantiate.in
@@ -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;
diff --git a/src/nix-populate b/src/nix-populate
index fa70ace80674..50819d6664d4 100755
--- a/src/nix-populate
+++ b/src/nix-populate
@@ -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;
diff --git a/src/nix.cc b/src/nix.cc
index 275a37bea1fc..c9091ef7ac79 100644
--- a/src/nix.cc
+++ b/src/nix.cc
@@ -17,6 +17,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 {