From 4c63f18dcc5d70261b4ac845ab055747772b4129 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Wed, 16 May 2007 10:16:10 +0000 Subject: [PATCH] added state options and state locations into drv --- src/libexpr/primops.cc | 62 +++++++++++++++++++++++++++++--- src/libstore/derivations-ast.def | 6 +++- src/libstore/derivations.cc | 26 +++++++++++--- src/libstore/derivations.hh | 26 +++++++++++--- src/libutil/aterm.cc | 12 +++++++ src/libutil/aterm.hh | 1 + src/libutil/types.hh | 1 + 7 files changed, 120 insertions(+), 14 deletions(-) diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 7addb0235..6d6cd4d21 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -393,9 +393,9 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args) //state vars bool enableState = false; + bool disableState = false; string shareState = "none"; string syncState = "all"; - StringSet dirs; for (ATermMap::const_iterator i = attrs.begin(); i != attrs.end(); ++i) { string key = aterm2String(i->key); @@ -424,10 +424,61 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args) } //state variables - else if(key == "dirs") { } + else if(key == "stateDirs") { + + enableState = true; + + value = evalExpr(state, value); + + ATermList list = evalList(state, value); + + printMsg(lvlError, format("DIRS `%1%'") % value); + printMsg(lvlError, format("DIRS `%1%'") % list); + + for (ATermIterator j(list); j; ++j){ + + Expr v = evalExpr(state, *j); + printMsg(lvlError, format("DIRS2 `%1%'") % v); + + ATermMap stateDirattrs; + queryAllAttrs(evalExpr(state, v), stateDirattrs, true); + + DerivationStateOutputDir dir = DerivationStateOutputDir(); + + for (ATermMap::const_iterator k = stateDirattrs.begin(); k != stateDirattrs.end(); ++k) { + + string statekey = aterm2String(k->key); + ATerm statevalue; + Expr statepos; + ATerm staterhs = k->value; + if (!matchAttrRHS(staterhs, statevalue, statepos)) abort(); + startNest(nest, lvlVomit, format("processing statedir attribute `%1%'") % statekey); + try { + string s = coerceToString(state, statevalue, context, true); + printMsg(lvlError, format("DIRS4 `%1%'") % s); + if (statekey == "dir") { dir.path = s; } + else if (statekey == "type") { dir.type = s; } + else if (statekey == "interval") { dir.interval = s; } + else throw EvalError(format("invalid subattirbute `%1%' for attribute dirs") % statekey); + } + catch (Error & e) { + e.addPrefix(format("while evaluating the state derivation attribute `%1%' at %2%:\n") % key % showPos(statepos)); + e.addPrefix(format("while instantiating the derivation named `%1%' at %2%:\n") % drvName % showPos(posDrvName)); + throw; + } + } + + drv.stateOutputDirs[dir.path] = dir; + + //Expr e = queryAttr(v, "dir"); + //printMsg(lvlError, format("DIRS3 `%1%'") % e); + + } + + } else if(key == "shareState") { string s = coerceToString(state, value, context, true); shareState = s; } else if(key == "synchronization") { string s = coerceToString(state, value, context, true); syncState = s; } - else if(key == "enableState") { bool b = evalBool(state, value); enableState = b; } + else if(key == "enableState") { bool b = evalBool(state, value); disableState = true; } /* All other attributes are passed to the builder through the environment. */ @@ -521,7 +572,10 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args) /* Add the state path based on the outPath */ //hash h = .... drv.env["statepath"] = outPath; - drv.stateOutputs["statepath"] = DerivationStateOutput(outPath, outputHashAlgo, outputHash, enableState, shareState, syncState, dirs); + string enableStateS = "false"; + if(enableState && disableState == false) + enableStateS = "true"; + drv.stateOutputs["stateOptions"] = DerivationStateOutput(outPath, outputHashAlgo, outputHash, enableStateS, shareState, syncState); /* Write the resulting term into the Nix store directory. */ Path drvPath = writeDerivation(drv, drvName); diff --git a/src/libstore/derivations-ast.def b/src/libstore/derivations-ast.def index 574529ae7..e8e2d283a 100644 --- a/src/libstore/derivations-ast.def +++ b/src/libstore/derivations-ast.def @@ -1,10 +1,14 @@ init initDerivationsHelpers -Derive | ATermList ATermList ATermList string string ATermList ATermList | ATerm | +#wouter added 2 ATermList + +Derive | ATermList ATermList ATermList ATermList ATermList string string ATermList ATermList | ATerm | | string string | ATerm | EnvBinding | | string ATermList | ATerm | DerivationInput | | string string string string | ATerm | DerivationOutput | +| string string string string string string string | ATerm | DerivationStateOutput | +| string string string string | ATerm | DerivationStateOutputDir | Closure | ATermList ATermList | ATerm | OldClosure | | string ATermList | ATerm | OldClosureElem | diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 74e8c233a..fb595d636 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -65,10 +65,10 @@ void throwBadDrv(ATerm t) Derivation parseDerivation(ATerm t) { Derivation drv; - ATermList outs, stateOuts, inDrvs, inSrcs, args, bnds; + ATermList outs, stateOuts, stateOutDirs, inDrvs, inSrcs, args, bnds; ATerm builder, platform; - if (!matchDerive(t, outs, stateOuts, inDrvs, inSrcs, platform, builder, args, bnds)) + if (!matchDerive(t, outs, stateOuts, stateOutDirs, inDrvs, inSrcs, platform, builder, args, bnds)) throwBadDrv(t); for (ATermIterator i(outs); i; ++i) { @@ -132,11 +132,28 @@ ATerm unparseDerivation(const Derivation & drv) ATermList stateOutputs = ATempty; for (DerivationStateOutputs::const_reverse_iterator i = drv.stateOutputs.rbegin(); i != drv.stateOutputs.rend(); ++i) stateOutputs = ATinsert(stateOutputs, - makeDerivationOutput( + makeDerivationStateOutput( toATerm(i->first), toATerm(i->second.statepath), toATerm(i->second.hashAlgo), - toATerm(i->second.hash))); + toATerm(i->second.hash), + toATerm(i->second.enabled), + toATerm(i->second.shared), + toATerm(i->second.synchronization) + )); + + ATermList stateOutputDirs = ATempty; + for (DerivationStateOutputDirs::const_reverse_iterator i = drv.stateOutputDirs.rbegin(); i != drv.stateOutputDirs.rend(); ++i) + stateOutputDirs = ATinsert(stateOutputDirs, + makeDerivationStateOutputDir( + toATerm(i->first), + toATerm(i->second.path), + toATerm(i->second.type), + toATerm(i->second.interval) + )); + + //toATermList(i->second.dirs) + ATermList inDrvs = ATempty; for (DerivationInputs::const_reverse_iterator i = drv.inputDrvs.rbegin(); @@ -162,6 +179,7 @@ ATerm unparseDerivation(const Derivation & drv) return makeDerive( outputs, stateOutputs, + stateOutputDirs, inDrvs, toATermList(drv.inputSrcs), toATerm(drv.platform), diff --git a/src/libstore/derivations.hh b/src/libstore/derivations.hh index 46b852ad8..a4d0e24b1 100644 --- a/src/libstore/derivations.hh +++ b/src/libstore/derivations.hh @@ -38,14 +38,13 @@ struct DerivationStateOutput Path statepath; string hashAlgo; string hash; - bool enabled; + string enabled; string shared; string synchronization; - StringSet dirs; DerivationStateOutput() { } - DerivationStateOutput(Path statepath, string hashAlgo, string hash, bool enabled, string shared, string synchronization, StringSet dirs) + DerivationStateOutput(Path statepath, string hashAlgo, string hash, string enabled, string shared, string synchronization) { this->statepath = statepath; this->hashAlgo = hashAlgo; @@ -53,14 +52,30 @@ struct DerivationStateOutput this->enabled = enabled; this->shared = shared; this->synchronization = synchronization; - this->dirs = dirs; + } +}; + +struct DerivationStateOutputDir +{ + string path; + string type; + string interval; + DerivationStateOutputDir() + { + } + DerivationStateOutputDir(string path, string type, string interval) + { + this->path = path; + this->type = type; + this->interval = interval; } }; - typedef std::map DerivationOutputs; typedef std::map DerivationStateOutputs; +typedef std::map DerivationStateOutputDirs; + /* For inputs that are sub-derivations, we specify exactly which output IDs we are interested in. */ @@ -71,6 +86,7 @@ struct Derivation { DerivationOutputs outputs; /* keyed on symbolic IDs */ DerivationStateOutputs stateOutputs; /* */ + DerivationStateOutputDirs stateOutputDirs; /* */ DerivationInputs inputDrvs; /* inputs that are sub-derivations */ PathSet inputSrcs; /* inputs that are sources */ string platform; diff --git a/src/libutil/aterm.cc b/src/libutil/aterm.cc index 90a8e212e..fedbcb808 100644 --- a/src/libutil/aterm.cc +++ b/src/libutil/aterm.cc @@ -51,3 +51,15 @@ ATermList nix::toATermList(const StringSet & ss) l = ATinsert(l, toATerm(*i)); return l; } + +ATermList nix::toATermList(const SetStringSet & sss) +{ + ATermList l = ATempty; + for (SetStringSet::const_reverse_iterator i = sss.rbegin(); i != sss.rend(); ++i){ + StringSet ss = *i; + for (StringSet::const_reverse_iterator j = ss.rbegin(); j != ss.rend(); ++j){ + l = ATinsert(l, toATerm(*j)); + } + } + return l; +} diff --git a/src/libutil/aterm.hh b/src/libutil/aterm.hh index b1cbc3b6d..c1b1123d1 100644 --- a/src/libutil/aterm.hh +++ b/src/libutil/aterm.hh @@ -44,6 +44,7 @@ ATerm toATerm(const char * s); ATerm toATerm(const string & s); ATermList toATermList(const StringSet & ss); +ATermList toATermList(const SetStringSet & sss); } diff --git a/src/libutil/types.hh b/src/libutil/types.hh index 513aae039..0ea6990e8 100644 --- a/src/libutil/types.hh +++ b/src/libutil/types.hh @@ -48,6 +48,7 @@ public: typedef list Strings; typedef set StringSet; +typedef set SetStringSet; /* Paths are just strings. */