fix(tvix/eval): src/compiler: ensure root_dir is absolute
Cppnix immediately absolutizes pathnames at parse time; if you write `./foo`, it is immediately converted to `$(pwd)/foo` and manipulated as an absolute path at all times. To avoid having to introduce filesystem access operations in the implementation of otherwise-pure builtins, let's guarantee that the `root_dir` of the VM is always an absolute path. Signed-off-by: Adam Joseph <adam@westernsemico.com> Change-Id: I7cbbae2cba4b2716ff3f5ff7c9ce0ad529358c8a Reviewed-on: https://cl.tvl.fyi/c/depot/+/6995 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
25336fc47b
commit
78d3d9150b
1 changed files with 16 additions and 8 deletions
|
@ -112,14 +112,21 @@ impl<'observer> Compiler<'observer> {
|
||||||
observer: &'observer mut dyn CompilerObserver,
|
observer: &'observer mut dyn CompilerObserver,
|
||||||
) -> EvalResult<Self> {
|
) -> EvalResult<Self> {
|
||||||
let mut root_dir = match location {
|
let mut root_dir = match location {
|
||||||
Some(dir) => Ok(dir),
|
Some(dir) if dir.is_absolute() => Ok(dir),
|
||||||
None => std::env::current_dir().map_err(|e| Error {
|
_ => {
|
||||||
|
let current_dir = std::env::current_dir().map_err(|e| Error {
|
||||||
kind: ErrorKind::PathResolution(format!(
|
kind: ErrorKind::PathResolution(format!(
|
||||||
"could not determine current directory: {}",
|
"could not determine current directory: {}",
|
||||||
e
|
e
|
||||||
)),
|
)),
|
||||||
span: file.span,
|
span: file.span,
|
||||||
}),
|
})?;
|
||||||
|
if let Some(dir) = location {
|
||||||
|
Ok(current_dir.join(dir))
|
||||||
|
} else {
|
||||||
|
Ok(current_dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
// If the path passed from the caller points to a file, the
|
// If the path passed from the caller points to a file, the
|
||||||
|
@ -131,6 +138,7 @@ impl<'observer> Compiler<'observer> {
|
||||||
|
|
||||||
let globals = globals.borrow();
|
let globals = globals.borrow();
|
||||||
|
|
||||||
|
debug_assert!(root_dir.is_absolute());
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
root_dir,
|
root_dir,
|
||||||
file,
|
file,
|
||||||
|
|
Loading…
Add table
Reference in a new issue