try to canonicalize to absolute path in current_dir(), use it in setting LoadContext directories (#821)
This commit is contained in:
@@ -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 =
|
||||
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user