try to canonicalize to absolute path in current_dir(), use it in setting LoadContext directories (#821)

This commit is contained in:
Mark Thom
2021-02-17 18:49:51 -07:00
parent 2a70ca375c
commit f5ad845d57
2 changed files with 11 additions and 8 deletions

View File

@@ -1606,8 +1606,6 @@ impl Machine {
pub(crate) fn load_context_directory(&mut self) { pub(crate) fn load_context_directory(&mut self) {
if let Some(load_context) = self.load_contexts.last() { if let Some(load_context) = self.load_contexts.last() {
if let Some(directory) = load_context.path.parent() { 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_str = directory.to_str().unwrap();
let directory_atom = let directory_atom =

View File

@@ -90,8 +90,16 @@ pub(super) struct LoadContext {
impl LoadContext { impl LoadContext {
#[inline] #[inline]
fn new(path: &str, stream: Stream) -> Self { 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 { LoadContext {
path: PathBuf::from(path), path: path_buf,
stream, stream,
module: clause_name!("user"), module: clause_name!("user"),
} }
@@ -111,11 +119,8 @@ pub struct Machine {
} }
#[inline] #[inline]
fn current_dir() -> std::path::PathBuf { fn current_dir() -> PathBuf {
let mut path_buf = std::path::PathBuf::from(file!()); PathBuf::from("./").canonicalize().unwrap_or(PathBuf::from("./"))
path_buf.pop();
path_buf
} }
include!(concat!(env!("OUT_DIR"), "/libraries.rs")); include!(concat!(env!("OUT_DIR"), "/libraries.rs"));