From 0b8a967acac26b527ebedfff6658117f63f7c861 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Mon, 10 Oct 2022 00:03:17 -0400 Subject: feat(tvix/eval): Implement builtins.pathExists Change-Id: Ife8a690e9036868964771893ab29a9ae3a2d2365 Reviewed-on: https://cl.tvl.fyi/c/depot/+/6919 Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/builtins/impure.rs | 13 +++++++------ tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp | 1 + tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix | 2 ++ 3 files changed, 10 insertions(+), 6 deletions(-) create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp create mode 100644 tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix diff --git a/tvix/eval/src/builtins/impure.rs b/tvix/eval/src/builtins/impure.rs index 32653b665c..5cf3ca4287 100644 --- a/tvix/eval/src/builtins/impure.rs +++ b/tvix/eval/src/builtins/impure.rs @@ -15,10 +15,11 @@ use crate::{ }; fn impure_builtins() -> Vec { - vec![Builtin::new( - "readDir", - &[true], - |args: Vec, vm: &mut VM| { + vec![ + Builtin::new("pathExists", &[true], |args: Vec, vm: &mut VM| { + Ok(super::coerce_value_to_path(&args[0], vm)?.exists().into()) + }), + Builtin::new("readDir", &[true], |args: Vec, vm: &mut VM| { let path = super::coerce_value_to_path(&args[0], vm)?; let mk_err = |err: io::Error| ErrorKind::IO { path: Some(path.clone()), @@ -50,8 +51,8 @@ fn impure_builtins() -> Vec { ); } Ok(Value::attrs(NixAttrs::from_map(res))) - }, - )] + }), + ] } /// Return all impure builtins, that is all builtins which may perform I/O diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp new file mode 100644 index 0000000000..27ba77ddaf --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.exp @@ -0,0 +1 @@ +true diff --git a/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix new file mode 100644 index 0000000000..ab3d036940 --- /dev/null +++ b/tvix/eval/src/tests/tvix_tests/eval-okay-pathexists.nix @@ -0,0 +1,2 @@ +builtins.pathExists ./lib.nix +&& !builtins.pathExists ./bla.nix -- cgit 1.4.1