FIX: The in memory asset cache should no longer canonicalize.

The pseudo relative paths for std libraries won't work with them.
This commit is contained in:
Jeremy Wall 2019-01-13 22:05:20 -06:00
parent 17a9882f40
commit 38fc521e3e
2 changed files with 4 additions and 8 deletions

View File

@ -51,18 +51,15 @@ impl MemoryCache {
impl Cache for MemoryCache { impl Cache for MemoryCache {
fn has_path(&self, path: &PathBuf) -> Result<bool> { fn has_path(&self, path: &PathBuf) -> Result<bool> {
let new_path = path.canonicalize()?; Ok(self.map.contains_key(path))
Ok(self.map.contains_key(&new_path))
} }
fn get(&self, path: &PathBuf) -> Result<Option<Rc<Val>>> { fn get(&self, path: &PathBuf) -> Result<Option<Rc<Val>>> {
let new_path = path.canonicalize()?; Ok(self.map.get(path).map(|v| v.clone()))
Ok(self.map.get(&new_path).map(|v| v.clone()))
} }
fn stash(&mut self, path: PathBuf, asset: Rc<Val>) -> Result<()> { fn stash(&mut self, path: PathBuf, asset: Rc<Val>) -> Result<()> {
let new_path = path.canonicalize()?; self.map.insert(path, asset);
self.map.insert(new_path, asset);
Ok(()) Ok(())
} }
} }

View File

@ -384,7 +384,6 @@ impl<'a> FileBuilder<'a> {
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.
if def.path.fragment.starts_with("std/") { if def.path.fragment.starts_with("std/") {
eprintln!("Processing std lib path: {}", def.path.fragment);
if self.std.contains_key(&def.path.fragment) { if self.std.contains_key(&def.path.fragment) {
// Okay then this is a stdlib and it's special. // Okay then this is a stdlib and it's special.
// Introduce a scope so the above borrow is dropped before we modify // Introduce a scope so the above borrow is dropped before we modify
@ -395,7 +394,7 @@ impl<'a> FileBuilder<'a> {
let result = match maybe_asset { let result = match maybe_asset {
Some(v) => v.clone(), Some(v) => v.clone(),
None => { None => {
let mut b = self.clone_builder(&def.path.fragment); let mut b = self.clone_builder(self.file.clone());
b.eval_string(self.std.get(&def.path.fragment).unwrap())?; b.eval_string(self.std.get(&def.path.fragment).unwrap())?;
b.get_outputs_as_val() b.get_outputs_as_val()
} }