diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 6587e144f..0baa1759f 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -582,6 +582,9 @@ private: /* Referenceable paths (i.e., input and output paths). */ PathSet allPaths; + /* Referenceable paths (i.e., input and output paths). */ + PathSet allStatePaths; + /* User selected for running the builder. */ UserLock buildUser; @@ -1295,8 +1298,7 @@ bool DerivationGoal::prepareBuild() running the build hook. */ /* The outputs are referenceable paths. */ - for (DerivationOutputs::iterator i = drv.outputs.begin(); - i != drv.outputs.end(); ++i) + for (DerivationOutputs::iterator i = drv.outputs.begin(); i != drv.outputs.end(); ++i) { debug(format("building path `%1%'") % i->second.path); allPaths.insert(i->second.path); @@ -1305,16 +1307,14 @@ bool DerivationGoal::prepareBuild() /* Determine the full set of input paths. */ /* First, the input derivations. */ - for (DerivationInputs::iterator i = drv.inputDrvs.begin(); - i != drv.inputDrvs.end(); ++i) + for (DerivationInputs::iterator i = drv.inputDrvs.begin(); i != drv.inputDrvs.end(); ++i) { /* Add the relevant output closures of the input derivation `*i' as input paths. Only add the closures of output paths that are specified as inputs. */ assert(store->isValidPath(i->first)); Derivation inDrv = derivationFromPath(i->first); - for (StringSet::iterator j = i->second.begin(); - j != i->second.end(); ++j) + for (StringSet::iterator j = i->second.begin(); j != i->second.end(); ++j) if (inDrv.outputs.find(*j) != inDrv.outputs.end()) computeFSClosure(inDrv.outputs[*j].path, inputPaths, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE else @@ -1324,8 +1324,7 @@ bool DerivationGoal::prepareBuild() } /* Second, the input sources. */ - for (PathSet::iterator i = drv.inputSrcs.begin(); - i != drv.inputSrcs.end(); ++i) + for (PathSet::iterator i = drv.inputSrcs.begin(); i != drv.inputSrcs.end(); ++i) computeFSClosure(*i, inputPaths, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE debug(format("added input paths %1%") % showPaths(inputPaths)); @@ -1759,7 +1758,7 @@ void DerivationGoal::computeClosure() * [scan for and state references and component references in the state path] //3,4 */ - PathSet allStatePaths; + PathSet allStatePaths2; for (PathSet::const_iterator i = allPaths.begin(); i != allPaths.end(); i++){ Path componentPath = *i; @@ -1772,7 +1771,7 @@ void DerivationGoal::computeClosure() //The we can dismiss the call to queryDeriversStatePath(...), and we only have to do registerValidPath once PathSet stateRefs = queryDeriversStatePath(txn, componentPath ,"*",getCallingUserName()); - allStatePaths = mergePathSets(stateRefs, allStatePaths); + allStatePaths2 = mergePathSets(stateRefs, allStatePaths2); } } @@ -1782,10 +1781,10 @@ void DerivationGoal::computeClosure() Path path = i->second.path; //We scan for state references in the component path - PathSet output_state_references = scanForReferences(path, allStatePaths); + PathSet output_state_references = scanForReferences(path, allStatePaths2); //debugging - for (PathSet::const_iterator i = allStatePaths.begin(); i != allStatePaths.end(); i++) + for (PathSet::const_iterator i = allStatePaths2.begin(); i != allStatePaths2.end(); i++) debug(format("all possible StatePaths: %1%") % (*i)); for (PathSet::const_iterator i = output_state_references.begin(); i != output_state_references.end(); i++) debug(format("state References scanned: %1%") % (*i)); @@ -1804,7 +1803,7 @@ void DerivationGoal::computeClosure() printMsg(lvlTalkative, format("scanning for component and state references inside `%1%'") % statePath); state_references = scanForReferences(statePath, allPaths); - state_stateReferences = scanForReferences(statePath, allStatePaths); + state_stateReferences = scanForReferences(statePath, allStatePaths2); } //Register all outputs now valid diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index f985b76d4..666e0cc74 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1549,6 +1549,7 @@ void LocalStore::storePathStateRequisitesOnly(const Path & storePath, const bool * Not used yet ......................... (should we use it .... ???) * */ +/* void getDependenciesAtBuildTime(const Transaction & txn, const Path & drvPath) { Derivation drv = derivationFromPath(drvPath); @@ -1557,21 +1558,20 @@ void getDependenciesAtBuildTime(const Transaction & txn, const Path & drvPath) //TODO THIS IS A DIRECT COPY FROM BUILD.CC WE SHOULD MERGE !!!!!!!!!!!!1!!!!!!!!!!!!! - /* The outputs are referenceable paths. */ - for (DerivationOutputs::iterator i = drv.outputs.begin(); - i != drv.outputs.end(); ++i) + // The outputs are referenceable paths. + for (DerivationOutputs::iterator i = drv.outputs.begin(); i != drv.outputs.end(); ++i) { debug(format("building path `%1%'") % i->second.path); allPaths.insert(i->second.path); } - /* First, the input derivations. */ + // First, the input derivations. for (DerivationInputs::iterator i = drv.inputDrvs.begin(); i != drv.inputDrvs.end(); ++i) { - /* Add the relevant output closures of the input derivation - `*i' as input paths. Only add the closures of output paths - that are specified as inputs. */ + // Add the relevant output closures of the input derivation + // `*i' as input paths. Only add the closures of output paths + // that are specified as inputs. assert(store->isValidPath(i->first)); Derivation inDrv = derivationFromPath(i->first); for (StringSet::iterator j = i->second.begin(); j != i->second.end(); ++j) @@ -1581,7 +1581,7 @@ void getDependenciesAtBuildTime(const Transaction & txn, const Path & drvPath) throw Error(format("derivation `%1%' requires non-existent output `%2%' from input derivation `%3%'") % drvPath % *j % i->first); } - /* Second, the input sources. */ + // Second, the input sources. for (PathSet::iterator i = drv.inputSrcs.begin(); i != drv.inputSrcs.end(); ++i) computeFSClosure(*i, inputPaths, false); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE @@ -1591,6 +1591,7 @@ void getDependenciesAtBuildTime(const Transaction & txn, const Path & drvPath) for (PathSet::iterator i = allPaths.begin(); i != allPaths.end(); ++i) printMsg(lvlError, format("ALLPATHS2: %1%") % *i); } +*/ void scanForAllReferences(const Transaction & txn, const Path & statePath) { diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index fa2b1201b..8ae19e848 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -43,13 +43,13 @@ bool isStatePath(const Path & path) void assertStorePath(const Path & path) { if (!isStorePath(path)) - throw Error(format("component path `%1%' is not in the Nix store (1)") % path); //TODO bug: this prints an empty path ... + throw Error(format("component path `%1%' is not in the Nix store") % path); } void assertStatePath(const Path & path) { if (!isStatePath(path)) - throw Error(format("state path `%1%' is not in the Nix state-store (1)") % path); //TODO bug: this prints an empty path ... + throw Error(format("state path `%1%' is not in the Nix state-store") % path); } @@ -64,6 +64,26 @@ Path toStorePath(const Path & path) return Path(path, 0, slash); } +Path toStoreOrStatePath(const Path & path) +{ + bool isStorePath = isInStore(path); + bool isStateStore = isInStateStore(path); + + if (!isStorePath && !isStateStore) + throw Error(format("path `%1%' is not in the Nix store or Nix state store") % path); + + Path::size_type slash; + if(isStorePath) + slash = path.find('/', nixStore.size() + 1); + else + slash = path.find('/', nixStoreState.size() + 1); + + if (slash == Path::npos) + return path; + else + return Path(path, 0, slash); +} + void checkStoreName(const string & name) { diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 4c4ef5c9a..0c2385b24 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -246,7 +246,7 @@ void checkStoreName(const string & name); /* Chop off the parts after the top-level store name, e.g., /nix/store/abcd-foo/bar => /nix/store/abcd-foo. */ Path toStorePath(const Path & path); - +Path toStoreOrStatePath(const Path & path); /* Constructs a unique store path name. */ Path makeStorePath(const string & type, diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index b3d6d3c48..04b6237c5 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -29,18 +29,32 @@ static Path gcRoot; static int rootNr = 0; static bool indirectRoot = false; - +//Fixes the path and checks if it is a store path , see also toStorePath static Path fixPath(Path path) { path = absPath(path); while (!isInStore(path)) { - if (!isLink(path)) break; + if (!isLink(path)) + break; string target = readLink(path); path = absPath(target, dirOf(path)); } return toStorePath(path); } +//Fixes the path and checks if it is a store or state path +static Path fixStoreOrStatePath(Path path) +{ + path = absPath(path); + while (!isInStore(path) && !isInStateStore(path)) { + if (!isLink(path)) + break; + string target = readLink(path); + path = absPath(target, dirOf(path)); + } + return toStoreOrStatePath(path); +} + static Path useDeriver(Path path) { @@ -162,10 +176,13 @@ static void opPrintFixedPath(Strings opFlags, Strings opArgs) parseHash16or32(parseHashType(hashAlgo), hash), name); } - +/* + * .....?? + */ static Path maybeUseOutput(const Path & storePath, bool useOutput, bool forceRealise) { - if (forceRealise) realisePath(storePath); + if (forceRealise) + realisePath(storePath); if (useOutput && isDerivation(storePath)) { Derivation drv = derivationFromPath(storePath); return findOutput(drv, "out"); @@ -286,7 +303,7 @@ static void opQuery(Strings opFlags, Strings opArgs) for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i) { - Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise); //TODO This hangs on state paths ... + Path path = maybeUseOutput(fixStoreOrStatePath(*i), useOutput, forceRealise); if (query == qRequisites) store->storePathRequisites(path, includeOutputs, paths, false); else if (query == qRequisitesState) store->storePathStateRequisitesOnly(path, includeOutputs, paths); else if (query == qRequisitesFull) store->storePathRequisites(path, includeOutputs, paths, true); @@ -339,7 +356,7 @@ static void opQuery(Strings opFlags, Strings opArgs) } break; - case qTree: { + case qTree: { //TODO include state path? PathSet done; for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i) @@ -347,7 +364,7 @@ static void opQuery(Strings opFlags, Strings opArgs) break; } - case qGraph: { + case qGraph: { //TOOD include state path? PathSet roots; for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i)