diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 5379cc8..1b725d6 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -576,8 +576,9 @@ impl ModuleDef { pub fn imports_to_absolute(&mut self, base: PathBuf) { let rewrite_import = |e: &mut Expression| { + let main_separator = format!("{}", std::path::MAIN_SEPARATOR); if let Expression::Include(ref mut def) = e { - let path = PathBuf::from(&def.path.fragment); + let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator)); if path.is_relative() { def.path.fragment = base .join(path) @@ -588,9 +589,9 @@ impl ModuleDef { } } if let Expression::Import(ref mut def) = e { - let path = PathBuf::from(&def.path.fragment); + let path = PathBuf::from(&def.path.fragment.replace("/", &main_separator).replace("\\", &main_separator)); // std/ paths are special and do not get made into absolute paths. - if path.starts_with("std/") { + if path.starts_with(format!("std{}", main_separator)) { return; } if path.is_relative() { diff --git a/src/build/opcode/runtime.rs b/src/build/opcode/runtime.rs index c4a4449..8ae844d 100644 --- a/src/build/opcode/runtime.rs +++ b/src/build/opcode/runtime.rs @@ -120,7 +120,17 @@ impl Builtins { } else { normalized = path; } - Ok(normalized.canonicalize()?) + // The canonicalize method on windows is not what we want so we'll + // do something a little different on windows that we would do on + // other Operating Systems. + #[cfg(target_os="windows")] + { + Ok(dbg!(normalized)) + } + #[cfg(not(target_os="windows"))] + { + Ok(dbg!(normalized.canonicalize()?)) + } } fn find_file
( @@ -176,9 +186,9 @@ impl Builtins { if let Some((val, path_pos)) = path { if let &Value::P(Str(ref path)) = val.as_ref() { // TODO(jwall): A bit hacky we should probably change import stacks to be pathbufs. - let normalized = decorate_error!(path_pos => self.normalize_path(base_path, false, path))?; + let normalized = decorate_error!(path_pos => self.normalize_path(base_path, false, dbg!(path)))?; // first we chack the cache - let path = normalized.to_string_lossy().to_string(); + let path = dbg!(normalized.to_string_lossy().to_string()); if let Some(val) = env.borrow().get_cached_path_val(&path) { stack.push((val, path_pos)); return Ok(());