diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-03-03T14·15+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2006-03-03T14·15+0000 |
commit | 2d54312f876c4810db4c3c0006bace686db4948b (patch) | |
tree | e53904c102e4f708fa7000c10d33c8201dc97180 /scripts/nix-build.in | |
parent | 78d84f5631eb1d0e4b665dbaacbbb1669ba899f7 (diff) |
* 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).
Diffstat (limited to 'scripts/nix-build.in')
-rw-r--r-- | scripts/nix-build.in | 165 |
1 files changed, 87 insertions, 78 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in index 5c02f765dc3c..25662a74213f 100644 --- a/scripts/nix-build.in +++ b/scripts/nix-build.in @@ -1,78 +1,87 @@ -#! @shell@ -e - -nixExpr=$1 - -extraArgs= -extraInstArgs= -addDrvLink=0 -addOutLink=1 - - -trap 'rm -f ./.nix-build-tmp-*' EXIT - - -# Process the arguments. -args=("$@") -for ((i = 0; i < ${#args[*]}; )); do - arg=${args[$i]} - i=$((i + 1)) - case "$arg" in - - --help) - echo "syntax: $0 [NIX-EXPR...]" >&2 - exit 0 - ;; - - --add-drv-link) - addDrvLink=1 - ;; - - --no-link) - addOutLink=0 - ;; - - --attr|-A) - arg2=${args[$i]} - i=$((i + 1)) - extraInstArgs="$extraInstArgs $arg $arg2" - ;; - - -*) - extraArgs="$extraArgs $arg" - ;; - - *) - exprs="$exprs $arg" - ;; - esac -done - -if test -z "$exprs"; then - exprs="./default.nix" -fi - -# Process the specified Nix expressions. -for i in $exprs; do - - # Instantiate the Nix expression. - prefix= - 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 - echo "store expression is $(readlink "$j")" >&2 - done - - # Build the resulting store derivation. - 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")" - done -done +#! @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"; + } + +} |