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