* Rewrote nix-build in Perl, since sh is just too limited (turns out

that arrays are a bash extension, so it didn't work on FreeBSD).
  Also fixes NIX-8 (readlink(1) dependency).
This commit is contained in:
Eelco Dolstra 2006-03-03 14:15:02 +00:00
parent 78d84f5631
commit 2d54312f87

View file

@ -1,78 +1,87 @@
#! @shell@ -e #! @perl@ -w -I@libexecdir@/nix
nixExpr=$1 use strict;
extraArgs=
extraInstArgs=
addDrvLink=0
addOutLink=1
trap 'rm -f ./.nix-build-tmp-*' EXIT my $addDrvLink = 0;
my $addOutLink = 1;
my @instArgs = ();
my @buildArgs = ();
my @exprs = ();
# Process the arguments. END {
args=("$@") foreach my $fn (glob ".nix-build-tmp-*") {
for ((i = 0; i < ${#args[*]}; )); do unlink $fn;
arg=${args[$i]} }
i=$((i + 1)) }
case "$arg" in
--help) sub intHandler {
echo "syntax: $0 [NIX-EXPR...]" >&2 exit 1;
exit 0 }
;;
--add-drv-link) $SIG{'INT'} = 'intHandler';
addDrvLink=1
;;
--no-link)
addOutLink=0
;;
--attr|-A) for (my $n = 0; $n < scalar @ARGV; $n++) {
arg2=${args[$i]} my $arg = $ARGV[$n];
i=$((i + 1))
extraInstArgs="$extraInstArgs $arg $arg2"
;;
-*) if ($arg eq "--help") {
extraArgs="$extraArgs $arg" print STDERR "Usage: nix-build [OPTION]... [FILE]...\n";
;; exit 0;
}
*) elsif ($arg eq "--add-drv-link") {
exprs="$exprs $arg" $addDrvLink = 1;
;; }
esac
done
if test -z "$exprs"; then elsif ($arg eq "--no-out-link" or $arg eq "--no-link") {
exprs="./default.nix" $addOutLink = 1;
fi }
# Process the specified Nix expressions. elsif ($arg eq "--attr" or $arg eq "-A") {
for i in $exprs; do $n++;
die "$0: `--attr' requires an argument\n" unless $n < scalar @ARGV;
push @instArgs, ("--attr", $ARGV[$n]);
}
# Instantiate the Nix expression. elsif (substr($arg, 0, 1) eq "-") {
prefix= push @buildArgs, $arg;
if test "$addDrvLink" = 0; then prefix=.nix-build-tmp-; fi }
storeExprs=$(@bindir@/nix-instantiate \
--add-root ./${prefix}derivation --indirect \
$extraInstArgs "$i")
for j in $storeExprs; do else {
echo "store expression is $(readlink "$j")" >&2 push @exprs, $arg;
done }
}
# Build the resulting store derivation. @exprs = ("./default.nix") if scalar @exprs == 0;
prefix=
if test "$addOutLink" = 0; then prefix=.nix-build-tmp-; fi
outPaths=$(@bindir@/nix-store \
--add-root ./${prefix}result --indirect \
-rv $extraArgs $storeExprs)
for j in $outPaths; do
echo "$(readlink "$j")" foreach my $expr (@exprs) {
done
done # Instantiate.
my $prefix = "";
$prefix = ".nix-build-tmp-" if !$addDrvLink;
my $drvPaths = `@bindir@/nix-instantiate --add-root ./${prefix}derivation --indirect @instArgs "$expr"`;
my @drvPaths = split ' ', $drvPaths;
foreach my $drvPath (@drvPaths) {
my $target = readlink $drvPath;
print STDERR "store derivation is $target\n";
}
# Build.
$prefix = "";
$prefix = ".nix-build-tmp-" if !$addOutLink;
my $outPaths = `@bindir@/nix-store --add-root ./${prefix}result --indirect -rv @buildArgs @drvPaths`;
my @outPaths = split ' ', $outPaths;
foreach my $outPath (@outPaths) {
my $target = readlink $outPath;
print "$target\n";
}
}