mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-24 18:39:50 -04:00
DEV: More Windows file path handling fixes.
This commit is contained in:
parent
ad97dfca57
commit
db9b7aef43
@ -576,8 +576,9 @@ impl ModuleDef {
|
|||||||
|
|
||||||
pub fn imports_to_absolute(&mut self, base: PathBuf) {
|
pub fn imports_to_absolute(&mut self, base: PathBuf) {
|
||||||
let rewrite_import = |e: &mut Expression| {
|
let rewrite_import = |e: &mut Expression| {
|
||||||
|
let main_separator = format!("{}", std::path::MAIN_SEPARATOR);
|
||||||
if let Expression::Include(ref mut def) = e {
|
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() {
|
if path.is_relative() {
|
||||||
def.path.fragment = base
|
def.path.fragment = base
|
||||||
.join(path)
|
.join(path)
|
||||||
@ -588,9 +589,9 @@ impl ModuleDef {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Expression::Import(ref mut def) = e {
|
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.
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
if path.is_relative() {
|
if path.is_relative() {
|
||||||
|
@ -120,7 +120,17 @@ impl Builtins {
|
|||||||
} else {
|
} else {
|
||||||
normalized = path;
|
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<P, BP>(
|
fn find_file<P, BP>(
|
||||||
@ -176,9 +186,9 @@ impl Builtins {
|
|||||||
if let Some((val, path_pos)) = path {
|
if let Some((val, path_pos)) = path {
|
||||||
if let &Value::P(Str(ref path)) = val.as_ref() {
|
if let &Value::P(Str(ref path)) = val.as_ref() {
|
||||||
// TODO(jwall): A bit hacky we should probably change import stacks to be pathbufs.
|
// 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
|
// 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) {
|
if let Some(val) = env.borrow().get_cached_path_val(&path) {
|
||||||
stack.push((val, path_pos));
|
stack.push((val, path_pos));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user