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.
This commit is contained in:
Eelco Dolstra 2012-08-24 16:58:11 -04:00
parent 4aa1e5c554
commit a9e6752bbd
5 changed files with 18 additions and 23 deletions

View file

@ -46,7 +46,7 @@ Flags:
--no-out-link: do not create the `result' symlink --no-out-link: do not create the `result' symlink
--out-link / -o NAME: create symlink NAME instead of `result' --out-link / -o NAME: create symlink NAME instead of `result'
--attr / -A ATTR: select a specific attribute from the Nix expression --attr / -A ATTR: select a specific attribute from the Nix expression
--run-env: build dependencies of the specified derivation, then start a --run-env: build dependencies of the specified derivation, then start a
shell with the environment of the derivation shell with the environment of the derivation
--command: command to run with `--run-env' --command: command to run with `--run-env'
@ -114,7 +114,7 @@ EOF
push @buildArgs, "--dry-run"; push @buildArgs, "--dry-run";
$dryRun = 1; $dryRun = 1;
} }
elsif ($arg eq "--show-trace") { elsif ($arg eq "--show-trace") {
push @instArgs, $arg; push @instArgs, $arg;
} }
@ -122,22 +122,22 @@ EOF
elsif ($arg eq "-") { elsif ($arg eq "-") {
@exprs = ("-"); @exprs = ("-");
} }
elsif ($arg eq "--verbose" or substr($arg, 0, 2) eq "-v") { elsif ($arg eq "--verbose" or substr($arg, 0, 2) eq "-v") {
push @buildArgs, $arg; push @buildArgs, $arg;
push @instArgs, $arg; push @instArgs, $arg;
$verbose = 1; $verbose = 1;
} }
elsif ($arg eq "--quiet") { elsif ($arg eq "--quiet") {
push @buildArgs, $arg; push @buildArgs, $arg;
push @instArgs, $arg; push @instArgs, $arg;
} }
elsif ($arg eq "--run-env") { elsif ($arg eq "--run-env") {
$runEnv = 1; $runEnv = 1;
} }
elsif ($arg eq "--command") { elsif ($arg eq "--command") {
$n++; $n++;
die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV; die "$0: `$arg' requires an argument\n" unless $n < scalar @ARGV;

View file

@ -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() void printGCWarning()
{ {
static bool haveWarned = false; static bool haveWarned = false;

View file

@ -26,7 +26,6 @@ MakeError(UsageError, nix::Error);
class StoreAPI; class StoreAPI;
/* Ugh. No better place to put this. */ /* Ugh. No better place to put this. */
Path makeRootName(const Path & gcRoot, int & counter);
void printGCWarning(); void printGCWarning();
void printMissing(StoreAPI & store, const PathSet & paths); void printMissing(StoreAPI & store, const PathSet & paths);

View file

@ -64,9 +64,11 @@ void processExpr(EvalState & state, const Strings & attrPaths,
Path drvPath = i->queryDrvPath(state); Path drvPath = i->queryDrvPath(state);
if (gcRoot == "") if (gcRoot == "")
printGCWarning(); printGCWarning();
else else {
drvPath = addPermRoot(*store, drvPath, Path rootName = gcRoot;
makeRootName(gcRoot, rootNr), indirectRoot); if (++rootNr > 1) rootName += "-" + int2String(rootNr);
drvPath = addPermRoot(*store, drvPath, rootName, indirectRoot);
}
std::cout << format("%1%\n") % drvPath; std::cout << format("%1%\n") % drvPath;
} }
} }

View file

@ -64,15 +64,19 @@ static PathSet realisePath(const Path & path)
if (isDerivation(path)) { if (isDerivation(path)) {
store->buildPaths(singleton<PathSet>(path)); store->buildPaths(singleton<PathSet>(path));
Derivation drv = derivationFromPath(*store, path); Derivation drv = derivationFromPath(*store, path);
rootNr++;
PathSet outputs; PathSet outputs;
foreach (DerivationOutputs::iterator, i, drv.outputs) { foreach (DerivationOutputs::iterator, i, drv.outputs) {
Path outPath = i->second.path; Path outPath = i->second.path;
if (gcRoot == "") if (gcRoot == "")
printGCWarning(); printGCWarning();
else else {
outPath = addPermRoot(*store, outPath, Path rootName = gcRoot;
makeRootName(gcRoot, rootNr), indirectRoot); if (rootNr > 1) rootName += "-" + int2String(rootNr);
if (i->first != "out") rootName += "-" + i->first;
outPath = addPermRoot(*store, outPath, rootName, indirectRoot);
}
outputs.insert(outPath); outputs.insert(outPath);
} }
return outputs; return outputs;