nix-super/scripts/nix-build.in
Eelco Dolstra 2d54312f87 * 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).
2006-03-03 14:15:02 +00:00

87 lines
1.7 KiB
Text

#! @perl@ -w -I@libexecdir@/nix
use strict;
my $addDrvLink = 0;
my $addOutLink = 1;
my @instArgs = ();
my @buildArgs = ();
my @exprs = ();
END {
foreach my $fn (glob ".nix-build-tmp-*") {
unlink $fn;
}
}
sub intHandler {
exit 1;
}
$SIG{'INT'} = 'intHandler';
for (my $n = 0; $n < scalar @ARGV; $n++) {
my $arg = $ARGV[$n];
if ($arg eq "--help") {
print STDERR "Usage: nix-build [OPTION]... [FILE]...\n";
exit 0;
}
elsif ($arg eq "--add-drv-link") {
$addDrvLink = 1;
}
elsif ($arg eq "--no-out-link" or $arg eq "--no-link") {
$addOutLink = 1;
}
elsif ($arg eq "--attr" or $arg eq "-A") {
$n++;
die "$0: `--attr' requires an argument\n" unless $n < scalar @ARGV;
push @instArgs, ("--attr", $ARGV[$n]);
}
elsif (substr($arg, 0, 1) eq "-") {
push @buildArgs, $arg;
}
else {
push @exprs, $arg;
}
}
@exprs = ("./default.nix") if scalar @exprs == 0;
foreach my $expr (@exprs) {
# 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";
}
}