diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/libstore/build.cc | 8 | ||||
-rw-r--r-- | src/libstore/derivations.cc | 17 | ||||
-rw-r--r-- | src/libstore/derivations.hh | 9 | ||||
-rw-r--r-- | src/libstore/misc.cc | 11 | ||||
-rw-r--r-- | src/libutil/util.cc | 14 | ||||
-rw-r--r-- | src/libutil/util.hh | 1 | ||||
-rw-r--r-- | src/nix-instantiate/nix-instantiate.cc | 16 | ||||
-rw-r--r-- | src/nix-store/nix-store.cc | 20 |
8 files changed, 82 insertions, 14 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 9e0db9ee7f0a..5e5cd6b23bb9 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -3197,11 +3197,13 @@ void LocalStore::buildPaths(const PathSet & drvPaths, bool repair) Worker worker(*this); Goals goals; - foreach (PathSet::const_iterator, i, drvPaths) - if (isDerivation(*i)) - goals.insert(worker.makeDerivationGoal(*i, repair)); + foreach (PathSet::const_iterator, i, drvPaths) { + DrvPathWithOutputs i2 = parseDrvPathWithOutputs(*i); + if (isDerivation(i2.first)) + goals.insert(worker.makeDerivationGoal(i2.first, repair)); else goals.insert(worker.makeSubstitutionGoal(*i, repair)); + } worker.run(goals); diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index e0a4f43c0bb8..1551ae28a81a 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -252,4 +252,21 @@ Hash hashDerivationModulo(StoreAPI & store, Derivation drv) } +DrvPathWithOutputs parseDrvPathWithOutputs(const string & s) +{ + size_t n = s.find("!"); + return n == s.npos + ? DrvPathWithOutputs(s, std::set<string>()) + : DrvPathWithOutputs(string(s, 0, n), tokenizeString<std::set<string> >(string(s, n + 1), ",")); +} + + +Path makeDrvPathWithOutputs(const Path & drvPath, std::set<string> outputs) +{ + return outputs.empty() + ? drvPath + : drvPath + "!" + concatStringsSep(",", outputs); +} + + } diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 7d38e60c0fe6..6b7c3e6ab189 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -79,4 +79,13 @@ typedef std::map<Path, Hash> DrvHashes; extern DrvHashes drvHashes; +/* Split a string specifying a derivation and a set of outputs + (/nix/store/hash-foo!out1,out2,...) into the derivation path and + the outputs. */ +typedef std::pair<string, std::set<string> > DrvPathWithOutputs; +DrvPathWithOutputs parseDrvPathWithOutputs(const string & s); + +Path makeDrvPathWithOutputs(const Path & drvPath, std::set<string> outputs); + + } diff --git a/src/libstore/misc.cc b/src/libstore/misc.cc index 3ce300e30678..dacd1d3d7474 100644 --- a/src/libstore/misc.cc +++ b/src/libstore/misc.cc @@ -82,20 +82,23 @@ void queryMissing(StoreAPI & store, const PathSet & targets, if (done.find(*i) != done.end()) continue; done.insert(*i); - if (isDerivation(*i)) { - if (!store.isValidPath(*i)) { + DrvPathWithOutputs i2 = parseDrvPathWithOutputs(*i); + + if (isDerivation(i2.first)) { + if (!store.isValidPath(i2.first)) { // FIXME: we could try to substitute p. unknown.insert(*i); continue; } - Derivation drv = derivationFromPath(store, *i); + Derivation drv = derivationFromPath(store, i2.first); PathSet invalid; + // FIXME: only fetch the desired outputs foreach (DerivationOutputs::iterator, j, drv.outputs) if (!store.isValidPath(j->second.path)) invalid.insert(j->second.path); if (invalid.empty()) continue; - todoDrv.insert(*i); + todoDrv.insert(i2.first); if (settings.useSubstitutes) query.insert(invalid.begin(), invalid.end()); } diff --git a/src/libutil/util.cc b/src/libutil/util.cc index e208701cea8a..1308eac31293 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -997,13 +997,14 @@ template<class C> C tokenizeString(const string & s, const string & separators) string::size_type end = s.find_first_of(separators, pos + 1); if (end == string::npos) end = s.size(); string token(s, pos, end - pos); - result.push_back(token); + result.insert(result.end(), token); pos = s.find_first_not_of(separators, end); } return result; } template Strings tokenizeString(const string & s, const string & separators); +template StringSet tokenizeString(const string & s, const string & separators); template vector<string> tokenizeString(const string & s, const string & separators); @@ -1018,6 +1019,17 @@ string concatStringsSep(const string & sep, const Strings & ss) } +string concatStringsSep(const string & sep, const StringSet & ss) +{ + string s; + foreach (StringSet::const_iterator, i, ss) { + if (s.size() != 0) s += sep; + s += *i; + } + return s; +} + + string chomp(const string & s) { size_t i = s.find_last_not_of(" \n\r\t"); diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 87b63f6e998a..746b2dd5859f 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -293,6 +293,7 @@ template<class C> C tokenizeString(const string & s, const string & separators = /* Concatenate the given strings with a separator between the elements. */ string concatStringsSep(const string & sep, const Strings & ss); +string concatStringsSep(const string & sep, const StringSet & ss); /* Remove trailing whitespace from a string. */ diff --git a/src/nix-instantiate/nix-instantiate.cc b/src/nix-instantiate/nix-instantiate.cc index ab0c8cf28bdf..a5053c32376d 100644 --- a/src/nix-instantiate/nix-instantiate.cc +++ b/src/nix-instantiate/nix-instantiate.cc @@ -8,6 +8,7 @@ #include "util.hh" #include "store-api.hh" #include "common-opts.hh" +#include "misc.hh" #include <map> #include <iostream> @@ -59,6 +60,19 @@ void processExpr(EvalState & state, const Strings & attrPaths, getDerivations(state, v, "", autoArgs, drvs, false); foreach (DrvInfos::iterator, i, drvs) { Path drvPath = i->queryDrvPath(state); + + /* What output do we want? */ + Path outPath = i->queryOutPath(state); + Derivation drv = derivationFromPath(*store, drvPath); + string outputName; + foreach (DerivationOutputs::iterator, i, drv.outputs) + if (i->second.path == outPath) { + outputName = i->first; + break; + } + if (outputName == "") + throw Error(format("derivation `%1%' does not have an output `%2%'") % drvPath % outPath); + if (gcRoot == "") printGCWarning(); else { @@ -66,7 +80,7 @@ void processExpr(EvalState & state, const Strings & attrPaths, if (++rootNr > 1) rootName += "-" + int2String(rootNr); drvPath = addPermRoot(*store, drvPath, rootName, indirectRoot); } - std::cout << format("%1%\n") % drvPath; + std::cout << format("%1%%2%\n") % drvPath % (outputName != "out" ? "!" + outputName : ""); } } } diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index e973beda9f0f..c0da37d251da 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -60,13 +60,21 @@ static Path useDeriver(Path path) other paths it means ensure their validity. */ static PathSet realisePath(const Path & path, bool build = true) { - if (isDerivation(path)) { + DrvPathWithOutputs p = parseDrvPathWithOutputs(path); + + if (isDerivation(p.first)) { if (build) store->buildPaths(singleton<PathSet>(path)); - Derivation drv = derivationFromPath(*store, path); + Derivation drv = derivationFromPath(*store, p.first); rootNr++; + if (p.second.empty()) + foreach (DerivationOutputs::iterator, i, drv.outputs) p.second.insert(i->first); + PathSet outputs; - foreach (DerivationOutputs::iterator, i, drv.outputs) { + foreach (StringSet::iterator, j, p.second) { + DerivationOutputs::iterator i = drv.outputs.find(*j); + if (i == drv.outputs.end()) + throw Error(format("derivation `%1%' does not have an output named `%2%'") % p.first % *j); Path outPath = i->second.path; if (gcRoot == "") printGCWarning(); @@ -103,8 +111,10 @@ static void opRealise(Strings opFlags, Strings opArgs) else throw UsageError(format("unknown flag `%1%'") % *i); Paths paths; - foreach (Strings::iterator, i, opArgs) - paths.push_back(followLinksToStorePath(*i)); + foreach (Strings::iterator, i, opArgs) { + DrvPathWithOutputs p = parseDrvPathWithOutputs(*i); + paths.push_back(makeDrvPathWithOutputs(followLinksToStorePath(p.first), p.second)); + } unsigned long long downloadSize, narSize; PathSet willBuild, willSubstitute, unknown; |