diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-07-22T15·15+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-07-22T15·15+0000 |
commit | e877c69d78fe75ae3531b3ed3cb4a4d7b390ccec (patch) | |
tree | 3e283c86e6d6079c84de21dcfe393acf0c5caf12 /src/fix.cc | |
parent | df648c4967af7298fe55f75c7616e39e5b5e7d37 (diff) |
* Substitutes now should produce a path with the same id as they are
substituting for (obvious, really). * For greater efficiency, nix-pull/unnar will place the output in a path that is probably the same as what is actually needed, thus preventing a path copy. * Even if a output id is given in a Fix package expression, ensure that the resulting Nix derive expression has a different id. This is because Nix expressions that are semantically equivalent (i.e., build the same result) might be different w.r.t. efficiency or divergence. It is absolutely vital for the substitute mechanism that such expressions are not used interchangeably.
Diffstat (limited to 'src/fix.cc')
-rw-r--r-- | src/fix.cc | 53 |
1 files changed, 39 insertions, 14 deletions
diff --git a/src/fix.cc b/src/fix.cc index 93cc27cfca7c..afa0167ecdc0 100644 --- a/src/fix.cc +++ b/src/fix.cc @@ -9,11 +9,13 @@ typedef ATerm Expr; typedef map<ATerm, ATerm> NormalForms; +typedef map<FSId, Hash> PkgHashes; struct EvalState { Strings searchDirs; NormalForms normalForms; + PkgHashes pkgHashes; /* normalised package hashes */ }; @@ -104,6 +106,23 @@ static Expr substExprMany(ATermList formals, ATermList args, Expr body) } +Hash hashPackage(EvalState & state, FState fs) +{ + if (fs.type == FState::fsDerive) { + for (FSIds::iterator i = fs.derive.inputs.begin(); + i != fs.derive.inputs.end(); i++) + { + PkgHashes::iterator j = state.pkgHashes.find(*i); + if (j == state.pkgHashes.end()) + throw Error(format("unknown package id %1%") % (string) *i); + *i = j->second; + } + } + debug(printTerm(unparseFState(fs))); + return hashTerm(unparseFState(fs)); +} + + static Expr evalExpr2(EvalState & state, Expr e) { char * s1; @@ -117,9 +136,10 @@ static Expr evalExpr2(EvalState & state, Expr e) return e; try { - parseFState(e); - return ATmake("FSId(<str>)", - ((string) writeTerm(e, "")).c_str()); + Hash pkgHash = hashPackage(state, parseFState(e)); + FSId pkgId = writeTerm(e, ""); + state.pkgHashes[pkgId] = pkgHash; + return ATmake("FSId(<str>)", ((string) pkgId).c_str()); } catch (...) { /* !!! catch parse errors only */ } @@ -153,10 +173,10 @@ static Expr evalExpr2(EvalState & state, Expr e) fs.slice.roots.push_back(id); fs.slice.elems.push_back(elem); - FSId termId = hashString("producer-" + (string) id - + "-" + dstPath); - writeTerm(unparseFState(fs), "", termId); - return ATmake("FSId(<str>)", ((string) termId).c_str()); + Hash pkgHash = hashPackage(state, fs); + FSId pkgId = writeTerm(unparseFState(fs), ""); + state.pkgHashes[pkgId] = pkgHash; + return ATmake("FSId(<str>)", ((string) pkgId).c_str()); } /* Packages are transformed into Derive fstate expressions. */ @@ -179,6 +199,7 @@ static Expr evalExpr2(EvalState & state, Expr e) fs.derive.platform = SYSTEM; string name; FSId outId; + bool outIdGiven = false; bnds = ATempty; for (map<string, ATerm>::iterator it = bndMap.begin(); @@ -198,7 +219,10 @@ static Expr evalExpr2(EvalState & state, Expr e) } else if (ATmatch(value, "<str>", &s1)) { if (key == "name") name = s1; - if (key == "id") outId = parseHash(s1); + if (key == "id") { + outId = parseHash(s1); + outIdGiven = true; + } fs.derive.env.push_back(StringPair(key, s1)); } else throw badTerm("invalid package argument", value); @@ -215,8 +239,7 @@ static Expr evalExpr2(EvalState & state, Expr e) /* Hash the fstate-expression with no outputs to produce a unique but deterministic path name for this package. */ - if (outId == FSId()) - outId = hashTerm(unparseFState(fs)); + if (!outIdGiven) outId = hashPackage(state, fs); string outPath = canonPath(nixStore + "/" + ((string) outId).c_str() + "-" + name); fs.derive.env.push_back(StringPair("out", outPath)); @@ -224,10 +247,12 @@ static Expr evalExpr2(EvalState & state, Expr e) debug(format("%1%: %2%") % (string) outId % name); /* Write the resulting term into the Nix store directory. */ - FSId termId = hashString("producer-" + (string) outId - + "-" + outPath); - writeTerm(unparseFState(fs), "-d-" + name, termId); - return ATmake("FSId(<str>)", ((string) termId).c_str()); + Hash pkgHash = outIdGiven + ? hashString((string) outId + outPath) + : hashPackage(state, fs); + FSId pkgId = writeTerm(unparseFState(fs), "-d-" + name); + state.pkgHashes[pkgId] = pkgHash; + return ATmake("FSId(<str>)", ((string) pkgId).c_str()); } /* BaseName primitive function. */ |