about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-24T20·58-0400
committerEelco Dolstra <eelco.dolstra@logicblox.com>2012-08-24T20·58-0400
commita9e6752bbd888ab8fbc1cda6e4d539b2858c4cef (patch)
tree6d5ac4f9e784b91fe4382293eb84684038990dc1
parent4aa1e5c55484ac02d28883292ee5c5806f5e4664 (diff)
Include the output name in the GC root link
Output names are now appended to resulting GC symlinks, e.g. by
nix-build.  For backwards compatibility, if the output is named "out",
nothing is appended.  E.g. doing "nix-build -A foo" on a derivation
that produces outputs "out", "bin" and "dev" will produce symlinks
"./result", "./result-bin" and "./result-dev", respectively.
-rwxr-xr-xscripts/nix-build.in12
-rw-r--r--src/libmain/shared.cc10
-rw-r--r--src/libmain/shared.hh1
-rw-r--r--src/nix-instantiate/nix-instantiate.cc8
-rw-r--r--src/nix-store/nix-store.cc10
5 files changed, 18 insertions, 23 deletions
diff --git a/scripts/nix-build.in b/scripts/nix-build.in
index afe0679a47d3..3ca3a1aafa6f 100755
--- a/scripts/nix-build.in
+++ b/scripts/nix-build.in
@@ -46,7 +46,7 @@ Flags:
   --no-out-link: do not create the `result' symlink
   --out-link / -o NAME: create symlink NAME instead of `result'
   --attr / -A ATTR: select a specific attribute from the Nix expression
-  
+
   --run-env: build dependencies of the specified derivation, then start a
       shell with the environment of the derivation
   --command: command to run with `--run-env'
@@ -114,7 +114,7 @@ EOF
         push @buildArgs, "--dry-run";
         $dryRun = 1;
     }
-    
+
     elsif ($arg eq "--show-trace") {
         push @instArgs, $arg;
     }
@@ -122,22 +122,22 @@ EOF
     elsif ($arg eq "-") {
         @exprs = ("-");
     }
-    
+
     elsif ($arg eq "--verbose" or substr($arg, 0, 2) eq "-v") {
         push @buildArgs, $arg;
         push @instArgs, $arg;
         $verbose = 1;
     }
-    
+
     elsif ($arg eq "--quiet") {
         push @buildArgs, $arg;
         push @instArgs, $arg;
     }
-    
+
     elsif ($arg eq "--run-env") {
         $runEnv = 1;
     }
-    
+
     elsif ($arg eq "--command") {
         $n++;
         die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index d39816586404..026db4173af0 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -33,16 +33,6 @@ static void sigintHandler(int signo)
 }
 
 
-Path makeRootName(const Path & gcRoot, int & counter)
-{
-    counter++;
-    if (counter == 1)
-        return gcRoot;
-    else
-        return (format("%1%-%2%") % gcRoot % counter).str();
-}
-
-
 void printGCWarning()
 {
     static bool haveWarned = false;
diff --git a/src/libmain/shared.hh b/src/libmain/shared.hh
index 7849e10e3641..c69879a12356 100644
--- a/src/libmain/shared.hh
+++ b/src/libmain/shared.hh
@@ -26,7 +26,6 @@ MakeError(UsageError, nix::Error);
 class StoreAPI;
 
 /* Ugh.  No better place to put this. */
-Path makeRootName(const Path & gcRoot, int & counter);
 void printGCWarning();
 
 void printMissing(StoreAPI & store, const PathSet & paths);
diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc
index d86c9fc84572..bca65d0728f5 100644
--- a/src/nix-instantiate/nix-instantiate.cc
+++ b/src/nix-instantiate/nix-instantiate.cc
@@ -64,9 +64,11 @@ void processExpr(EvalState & state, const Strings & attrPaths,
                     Path drvPath = i->queryDrvPath(state);
                     if (gcRoot == "")
                         printGCWarning();
-                    else
-                        drvPath = addPermRoot(*store, drvPath,
-                            makeRootName(gcRoot, rootNr), indirectRoot);
+                    else {
+                        Path rootName = gcRoot;
+                        if (++rootNr > 1) rootName += "-" + int2String(rootNr);
+                        drvPath = addPermRoot(*store, drvPath, rootName, indirectRoot);
+                    }
                     std::cout << format("%1%\n") % drvPath;
                 }
             }
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index c182dbe49c7a..d7b998faebb7 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -64,15 +64,19 @@ static PathSet realisePath(const Path & path)
     if (isDerivation(path)) {
         store->buildPaths(singleton<PathSet>(path));
         Derivation drv = derivationFromPath(*store, path);
+        rootNr++;
 
         PathSet outputs;
         foreach (DerivationOutputs::iterator, i, drv.outputs) {
             Path outPath = i->second.path;
             if (gcRoot == "")
                 printGCWarning();
-            else
-                outPath = addPermRoot(*store, outPath,
-                    makeRootName(gcRoot, rootNr), indirectRoot);
+            else {
+                Path rootName = gcRoot;
+                if (rootNr > 1) rootName += "-" + int2String(rootNr);
+                if (i->first != "out") rootName += "-" + i->first;
+                outPath = addPermRoot(*store, outPath, rootName, indirectRoot);
+            }
             outputs.insert(outPath);
         }
         return outputs;