feat(tvix/eval): builtins.storeDir
Returns the store directory through EvalIO::store_dir. Note that this is _optional_ in Tvix, as an evaluation can occur in a context where there simply is no store directory. In those contexts, `builtins.storeDir` returns `null` in Tvix. This would only happen in contexts like Tvixbolt (or completely unrelated use-cases) in practice. Co-Authored-By: Vincent Ambo <tazjin@tvl.su> Change-Id: I5a752c7e89b2f75bd7efb082dbfa5b25e3b1ff3b Reviewed-on: https://cl.tvl.fyi/c/depot/+/7452 Autosubmit: Adam Joseph <adam@westernsemico.com> Tested-by: BuildkiteCI Reviewed-by: grfn <grfn@gws.fyi>
This commit is contained in:
		
							parent
							
								
									4cb9ada0df
								
							
						
					
					
						commit
						947a56c4b6
					
				
					 2 changed files with 17 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -4,7 +4,7 @@ use smol_str::SmolStr;
 | 
			
		|||
use std::{
 | 
			
		||||
    collections::BTreeMap,
 | 
			
		||||
    env,
 | 
			
		||||
    rc::Weak,
 | 
			
		||||
    rc::{Rc, Weak},
 | 
			
		||||
    time::{SystemTime, UNIX_EPOCH},
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -74,6 +74,16 @@ pub(super) fn builtins() -> BTreeMap<&'static str, Value> {
 | 
			
		|||
        .map(|b| (b.name(), Value::Builtin(b)))
 | 
			
		||||
        .collect();
 | 
			
		||||
 | 
			
		||||
    map.insert(
 | 
			
		||||
        "storeDir",
 | 
			
		||||
        Value::Thunk(Thunk::new_suspended_native(Rc::new(Box::new(
 | 
			
		||||
            |vm: &mut VM| match vm.io().store_dir() {
 | 
			
		||||
                None => Ok(Value::Null),
 | 
			
		||||
                Some(dir) => Ok(Value::String(dir.into())),
 | 
			
		||||
            },
 | 
			
		||||
        )))),
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    // currentTime pins the time at which evaluation was started
 | 
			
		||||
    {
 | 
			
		||||
        let seconds = match SystemTime::now().duration_since(UNIX_EPOCH) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue