mirror of
https://github.com/NixOS/nix
synced 2025-06-26 20:01:15 +02:00
experimental/hash
adding primop function calculating hash of a string Signed-off-by: Marc Weber <marco-oweber@gmx.de>
This commit is contained in:
parent
8add116acd
commit
01a5ea9914
3 changed files with 33 additions and 0 deletions
|
@ -1107,6 +1107,30 @@ static void prim_unsafeDiscardOutputDependency(EvalState & state, Value * * args
|
|||
}
|
||||
|
||||
|
||||
static void prim_hash(EvalState & state, Value * * args, Value & v)
|
||||
{
|
||||
PathSet context;
|
||||
|
||||
string type = state.forceStringNoCtx(*args[0]);
|
||||
string s = state.forceStringNoCtx(*args[1]);
|
||||
|
||||
HashType ht;
|
||||
if (type == "md5"){
|
||||
ht = htMD5;
|
||||
} else if (type == "sha256"){
|
||||
ht = htSHA256;
|
||||
} else {
|
||||
throw Error(format("bad hash type `%1%'") % type);
|
||||
}
|
||||
|
||||
Hash h = hashString(ht, s);
|
||||
|
||||
string hash = printHash(h);
|
||||
|
||||
mkString(v, hash, context);
|
||||
};
|
||||
|
||||
|
||||
/*************************************************************
|
||||
* Versions
|
||||
*************************************************************/
|
||||
|
@ -1235,6 +1259,8 @@ void EvalState::createBaseEnv()
|
|||
addPrimOp("__unsafeDiscardStringContext", 1, prim_unsafeDiscardStringContext);
|
||||
addPrimOp("__unsafeDiscardOutputDependency", 1, prim_unsafeDiscardOutputDependency);
|
||||
|
||||
addPrimOp("__hash", 2, prim_hash);
|
||||
|
||||
// Versions
|
||||
addPrimOp("__parseDrvName", 1, prim_parseDrvName);
|
||||
addPrimOp("__compareVersions", 2, prim_compareVersions);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue