From f5ad845d57ff6a5d180be35d9fc5f6b766e03e53 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Wed, 17 Feb 2021 18:49:51 -0700 Subject: [PATCH] try to canonicalize to absolute path in current_dir(), use it in setting LoadContext directories (#821) --- src/machine/loader.rs | 2 -- src/machine/mod.rs | 17 +++++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/machine/loader.rs b/src/machine/loader.rs index 08593238..2347fcfe 100644 --- a/src/machine/loader.rs +++ b/src/machine/loader.rs @@ -1606,8 +1606,6 @@ impl Machine { pub(crate) fn load_context_directory(&mut self) { if let Some(load_context) = self.load_contexts.last() { if let Some(directory) = load_context.path.parent() { - // canonicalize returns the absolute path of the directory. - let directory = directory.canonicalize().unwrap(); let directory_str = directory.to_str().unwrap(); let directory_atom = diff --git a/src/machine/mod.rs b/src/machine/mod.rs index b0613b74..163c82a0 100644 --- a/src/machine/mod.rs +++ b/src/machine/mod.rs @@ -90,8 +90,16 @@ pub(super) struct LoadContext { impl LoadContext { #[inline] fn new(path: &str, stream: Stream) -> Self { + let mut path_buf = PathBuf::from(path); + + if path_buf.is_relative() { + let mut current_dir = current_dir(); + current_dir.push(path_buf); + path_buf = current_dir; + } + LoadContext { - path: PathBuf::from(path), + path: path_buf, stream, module: clause_name!("user"), } @@ -111,11 +119,8 @@ pub struct Machine { } #[inline] -fn current_dir() -> std::path::PathBuf { - let mut path_buf = std::path::PathBuf::from(file!()); - - path_buf.pop(); - path_buf +fn current_dir() -> PathBuf { + PathBuf::from("./").canonicalize().unwrap_or(PathBuf::from("./")) } include!(concat!(env!("OUT_DIR"), "/libraries.rs")); -- 2.54.0