From 2a3f4110c54a10ebee67403a699cb8f951fca858 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 13 Jan 2012 23:35:07 +0000 Subject: * nix-build: put the temporary derivation symlink in a temporary directory rather than the current directory. * nix-build: --drv-link now implies --add-drv-link. --- doc/manual/manual.xml | 10 ++-------- doc/manual/nix-build.xml | 30 ++++++++++++++---------------- scripts/nix-build.in | 37 +++++++++---------------------------- 3 files changed, 25 insertions(+), 52 deletions(-) diff --git a/doc/manual/manual.xml b/doc/manual/manual.xml index 090a92ce6b3e..95f80686008d 100644 --- a/doc/manual/manual.xml +++ b/doc/manual/manual.xml @@ -21,17 +21,11 @@ - 2004 - 2005 - 2006 - 2007 - 2008 - 2009 - 2010 + 2004-2012 Eelco Dolstra - August 2010 + January 2012 diff --git a/doc/manual/nix-build.xml b/doc/manual/nix-build.xml index 23c0b23041c6..465635f67125 100644 --- a/doc/manual/nix-build.xml +++ b/doc/manual/nix-build.xml @@ -28,8 +28,8 @@ attrPath - drvlink + @@ -83,24 +83,23 @@ except for and / - + drvlink - Add a symlink in the current directory to the - store derivation produced by nix-instantiate. - The symlink is called derivation (which is - numbered in the case of multiple derivations). The derivation is + Add a symlink named + drvlink to the store derivation + produced by nix-instantiate. The derivation is a root of the garbage collector until the symlink is deleted or - renamed. - + renamed. If there are multiple derivations, numbers are suffixed + to drvlink to distinguish between + them. + - drvlink + - Change the name of the symlink to the derivation - created when is used from - derivation to - drvlink. - + Shorthand for + ./derivation. + @@ -116,8 +115,7 @@ except for and / outlink Change the name of the symlink to the output path - created unless is used from - result to + created from result to outlink. diff --git a/scripts/nix-build.in b/scripts/nix-build.in index a4615e4bdb72..5cbcd113966f 100755 --- a/scripts/nix-build.in +++ b/scripts/nix-build.in @@ -2,14 +2,9 @@ use strict; use Nix::Config; +use File::Temp qw(tempdir); -my $addDrvLink = 0; -my $addOutLink = 1; - -my $outLink; -my $drvLink; - my $dryRun = 0; my $verbose = 0; @@ -18,17 +13,14 @@ my @buildArgs = (); my @exprs = (); -END { - foreach my $fn (glob ".nix-build-tmp-*") { - unlink $fn; - } -} +my $tmpDir = tempdir("nix-build.XXXXXX", CLEANUP => 1, TMPDIR => 1) + or die "cannot create a temporary directory"; -sub intHandler { - exit 1; -} +my $outLink = "./result"; +my $drvLink = "$tmpDir/derivation"; -$SIG{'INT'} = 'intHandler'; +# Ensure that the $tmpDir is deleted. +$SIG{'INT'} = sub { exit 1 }; for (my $n = 0; $n < scalar @ARGV; $n++) { @@ -56,11 +48,11 @@ EOF } elsif ($arg eq "--add-drv-link") { - $addDrvLink = 1; + $drvLink = "./derivation"; } elsif ($arg eq "--no-out-link" or $arg eq "--no-link") { - $addOutLink = 0; + $outLink = "$tmpDir/result"; } elsif ($arg eq "--drv-link") { @@ -139,17 +131,6 @@ EOF @exprs = ("./default.nix") if scalar @exprs == 0; -if (!defined $drvLink) { - $drvLink = "derivation"; - $drvLink = ".nix-build-tmp-" . $drvLink if !$addDrvLink; -} - -if (!defined $outLink) { - $outLink = "result"; - $outLink = ".nix-build-tmp-" . $outLink if !$addOutLink; -} - - foreach my $expr (@exprs) { # Instantiate. -- cgit 1.4.1