* Multiple and/or failing substitutes now work.

This commit is contained in:
Eelco Dolstra 2004-06-24 13:40:38 +00:00
parent 8052aef486
commit ec32627621
4 changed files with 54 additions and 19 deletions

View file

@ -153,6 +153,13 @@ public:
}; };
class SubstError : public Error
{
public:
SubstError(const format & f) : Error(f) { };
};
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -209,6 +216,8 @@ void commonChildInit(Pipe & logPipe)
} }
/* Convert a string list to an array of char pointers. Careful: the
string list should outlive the array. */
const char * * strings2CharPtrs(const Strings & ss) const char * * strings2CharPtrs(const Strings & ss)
{ {
const char * * arr = new const char * [ss.size() + 1]; const char * * arr = new const char * [ss.size() + 1];
@ -1202,7 +1211,7 @@ private:
Pid pid; Pid pid;
/* Lock on the store path. */ /* Lock on the store path. */
PathLocks outputLock; shared_ptr<PathLocks> outputLock;
typedef void (SubstitutionGoal::*GoalState)(); typedef void (SubstitutionGoal::*GoalState)();
GoalState state; GoalState state;
@ -1310,18 +1319,20 @@ void SubstitutionGoal::tryToRun()
/* Acquire a lock on the output path. */ /* Acquire a lock on the output path. */
PathSet lockPath; PathSet lockPath;
lockPath.insert(storePath); lockPath.insert(storePath);
outputLock.lockPaths(lockPath); outputLock = shared_ptr<PathLocks>(new PathLocks);
outputLock->lockPaths(lockPath);
/* Check again whether the path is invalid. */ /* Check again whether the path is invalid. */
if (isValidPath(storePath)) { if (isValidPath(storePath)) {
debug(format("store path `%1%' has become valid") % storePath); debug(format("store path `%1%' has become valid") % storePath);
outputLock.setDeletion(true); outputLock->setDeletion(true);
amDone(); amDone();
return; return;
} }
startNest(nest, lvlInfo, printMsg(lvlInfo,
format("substituting path `%1%'") % storePath); format("substituting path `%1%' using substituter `%2%'")
% storePath % sub.storeExpr);
/* What's the substitute program? */ /* What's the substitute program? */
StoreExpr expr = storeExprFromPath(nfSub); StoreExpr expr = storeExprFromPath(nfSub);
@ -1396,20 +1407,39 @@ void SubstitutionGoal::finished()
debug(format("substitute for `%1%' finished") % storePath); debug(format("substitute for `%1%' finished") % storePath);
/* Check the exit status. */ /* Check the exit status and the build result. */
if (!statusOk(status)) try {
throw Error(format("builder for `%1%' %2%")
% storePath % statusToString(status));
if (!pathExists(storePath)) if (!statusOk(status))
throw Error(format("substitute did not produce path `%1%'") % storePath); throw SubstError(format("builder for `%1%' %2%")
% storePath % statusToString(status));
if (!pathExists(storePath))
throw SubstError(
format("substitute did not produce path `%1%'")
% storePath);
} catch (SubstError & e) {
printMsg(lvlInfo,
format("substitution of path `%1%' using substituter `%2%' failed: %3%")
% storePath % sub.storeExpr % e.msg());
/* Try the next substitute. */
state = &SubstitutionGoal::tryNext;
worker.wakeUp(shared_from_this());
return;
}
Transaction txn; Transaction txn;
createStoreTransaction(txn); createStoreTransaction(txn);
registerValidPath(txn, storePath); registerValidPath(txn, storePath);
txn.commit(); txn.commit();
outputLock.setDeletion(true); outputLock->setDeletion(true);
printMsg(lvlChatty,
format("substitution of path `%1%' succeeded") % storePath);
amDone(); amDone();
} }

View file

@ -18,11 +18,10 @@ locking.sh: locking.nix
parallel.sh: parallel.nix parallel.sh: parallel.nix
build-hook.sh: build-hook.nix build-hook.sh: build-hook.nix
substitutes.sh: substitutes.nix substituter.nix substitutes.sh: substitutes.nix substituter.nix
substitutes2.sh: substitutes.nix substituter.nix substituter2.nix substitutes2.sh: substitutes2.nix substituter.nix substituter2.nix
#TESTS = init.sh simple.sh dependencies.sh locking.sh parallel.sh \ TESTS = init.sh simple.sh dependencies.sh locking.sh parallel.sh \
# build-hook.sh substitutes.sh substitutes2.sh build-hook.sh substitutes.sh substitutes2.sh
TESTS = init.sh substitutes2.sh
XFAIL_TESTS = XFAIL_TESTS =
@ -35,4 +34,4 @@ EXTRA_DIST = $(TESTS) \
parallel.nix.in parallel.builder.sh \ parallel.nix.in parallel.builder.sh \
build-hook.nix.in build-hook.hook.sh \ build-hook.nix.in build-hook.hook.sh \
substitutes.nix.in substituter.nix.in substituter.builder.sh \ substitutes.nix.in substituter.nix.in substituter.builder.sh \
substituter2.nix.in substituter2.builder.sh substitutes2.nix.in substituter2.nix.in substituter2.builder.sh

View file

@ -0,0 +1,6 @@
derivation {
name = "substitutes-2";
system = "@system@";
builder = "@shell@";
args = ["-e" "-x" ./simple.builder.sh];
}

View file

@ -1,5 +1,5 @@
# Instantiate. # Instantiate.
storeExpr=$($TOP/src/nix-instantiate/nix-instantiate substitutes.nix) storeExpr=$($TOP/src/nix-instantiate/nix-instantiate substitutes2.nix)
echo "store expr is $storeExpr" echo "store expr is $storeExpr"
# Find the output path. # Find the output path.
@ -19,7 +19,7 @@ regSub() {
} }
# Register a fake successor, and a substitute for it. # Register a fake successor, and a substitute for it.
suc=$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-s.store suc=$NIX_STORE_DIR/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab-s.store
regSub $suc $subExpr regSub $suc $subExpr
$TOP/src/nix-store/nix-store --successor $storeExpr $suc $TOP/src/nix-store/nix-store --successor $storeExpr $suc