mirror of
https://github.com/zaphar/ucg.git
synced 2025-07-25 18:49:50 -04:00
DEV: Canonicalize is never the right thing on windows.
This commit is contained in:
parent
acffc6d5da
commit
6f714e6583
@ -568,9 +568,12 @@ impl ModuleDef {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn imports_to_absolute(&mut self, base: PathBuf) {
|
pub fn imports_to_absolute(&mut self, base: PathBuf) {
|
||||||
|
&base;
|
||||||
let rewrite_import = |e: &mut Expression| {
|
let rewrite_import = |e: &mut Expression| {
|
||||||
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);
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
if path.is_relative() {
|
if path.is_relative() {
|
||||||
def.path.fragment = base
|
def.path.fragment = base
|
||||||
.join(path)
|
.join(path)
|
||||||
@ -580,12 +583,21 @@ impl ModuleDef {
|
|||||||
.to_string();
|
.to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
if path.is_relative() {
|
||||||
|
def.path.fragment = dbg!(base.join(path).to_string_lossy().to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
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 = dbg!(PathBuf::from(&def.path.fragment));
|
||||||
// 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("std/") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
if path.is_relative() {
|
if path.is_relative() {
|
||||||
def.path.fragment = base
|
def.path.fragment = base
|
||||||
.join(path)
|
.join(path)
|
||||||
@ -595,6 +607,13 @@ impl ModuleDef {
|
|||||||
.to_string();
|
.to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
if path.is_relative() {
|
||||||
|
def.path.fragment = base.join(path).to_string_lossy().to_string();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
let mut walker = walk::AstWalker::new().with_expr_handler(&rewrite_import);
|
let mut walker = walk::AstWalker::new().with_expr_handler(&rewrite_import);
|
||||||
for stmt in self.statements.iter_mut() {
|
for stmt in self.statements.iter_mut() {
|
||||||
|
@ -381,6 +381,12 @@ where
|
|||||||
} else {
|
} else {
|
||||||
normalized = path;
|
normalized = path;
|
||||||
}
|
}
|
||||||
|
#[cfg(windows)]
|
||||||
|
{
|
||||||
|
Ok(normalized)
|
||||||
|
}
|
||||||
|
#[cfg(not(windows))]
|
||||||
|
{
|
||||||
match normalized.canonicalize() {
|
match normalized.canonicalize() {
|
||||||
Ok(p) => Ok(p),
|
Ok(p) => Ok(p),
|
||||||
Err(e) => Err(error::BuildError::new(
|
Err(e) => Err(error::BuildError::new(
|
||||||
@ -391,6 +397,7 @@ where
|
|||||||
.to_boxed()),
|
.to_boxed()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn eval_import(&self, def: &ImportDef) -> Result<Rc<Val>, Box<dyn Error>> {
|
fn eval_import(&self, def: &ImportDef) -> Result<Rc<Val>, Box<dyn Error>> {
|
||||||
// Look for a std file first.
|
// Look for a std file first.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user