forked from lix-project/lix
* New primop `unsafeDiscardStringContext' to get rid of string
contexts. Needed to prevent unnecessary dependencies when building the NixOS manual.
This commit is contained in:
parent
895c953817
commit
7d0f6aed59
|
@ -942,6 +942,14 @@ static Expr prim_stringLength(EvalState & state, const ATermVector & args)
|
|||
}
|
||||
|
||||
|
||||
static Expr prim_unsafeDiscardStringContext(EvalState & state, const ATermVector & args)
|
||||
{
|
||||
PathSet context;
|
||||
string s = coerceToString(state, args[0], context);
|
||||
return makeStr(s, PathSet());
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************
|
||||
* Primop registration
|
||||
*************************************************************/
|
||||
|
@ -1009,6 +1017,8 @@ void EvalState::addPrimOps()
|
|||
addPrimOp("toString", 1, prim_toString);
|
||||
addPrimOp("__substring", 3, prim_substring);
|
||||
addPrimOp("__stringLength", 1, prim_stringLength);
|
||||
addPrimOp("__unsafeDiscardStringContext", 1, prim_unsafeDiscardStringContext);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
1
tests/lang/eval-okay-context.exp
Normal file
1
tests/lang/eval-okay-context.exp
Normal file
|
@ -0,0 +1 @@
|
|||
Str("foo eval-okay-context.nix bar",[])
|
6
tests/lang/eval-okay-context.nix
Normal file
6
tests/lang/eval-okay-context.nix
Normal file
|
@ -0,0 +1,6 @@
|
|||
let s = "foo ${builtins.substring 33 100 (baseNameOf ./eval-okay-context.nix)} bar";
|
||||
in
|
||||
if s == "foo eval-okay-context.nix bar"
|
||||
then abort "context not discarded"
|
||||
else builtins.unsafeDiscardStringContext s
|
||||
|
Loading…
Reference in a new issue