From f9b33f12cbd5cb6509d12b43b32b54167bcb3a17 Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Tue, 28 Mar 2023 15:39:52 -0500 Subject: [PATCH] fix more complex workspaces with hot reloading --- .../src/hot_reload/hot_reloading_file_map.rs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/packages/rsx/src/hot_reload/hot_reloading_file_map.rs b/packages/rsx/src/hot_reload/hot_reloading_file_map.rs index 2f0cc5246..0393142b4 100644 --- a/packages/rsx/src/hot_reload/hot_reloading_file_map.rs +++ b/packages/rsx/src/hot_reload/hot_reloading_file_map.rs @@ -29,7 +29,7 @@ pub struct FileMapBuildResult { pub struct FileMap { pub map: HashMap>)>, - in_workspace: HashMap, + in_workspace: HashMap>, phantom: std::marker::PhantomData, } @@ -112,11 +112,8 @@ impl FileMap { ) { // if the file!() macro is invoked in a workspace, the path is relative to the workspace root, otherwise it's relative to the crate root // we need to check if the file is in a workspace or not and strip the prefix accordingly - let prefix = if in_workspace { - crate_dir.parent().ok_or(io::Error::new( - io::ErrorKind::Other, - "Could not load workspace", - ))? + let prefix = if let Some(workspace) = &in_workspace { + workspace } else { crate_dir }; @@ -173,9 +170,9 @@ impl FileMap { Ok(UpdateResult::NeedsRebuild) } - fn child_in_workspace(&mut self, crate_dir: &Path) -> io::Result { + fn child_in_workspace(&mut self, crate_dir: &Path) -> io::Result> { if let Some(in_workspace) = self.in_workspace.get(crate_dir) { - Ok(*in_workspace) + Ok(in_workspace.clone()) } else { let mut cmd = Cmd::new(); let manafest_path = crate_dir.join("Cargo.toml"); @@ -186,9 +183,10 @@ impl FileMap { .map_err(|err| io::Error::new(io::ErrorKind::Other, err))?; let in_workspace = metadata.workspace_root != crate_dir; + let workspace_path = in_workspace.then(|| metadata.workspace_root.into()); self.in_workspace - .insert(crate_dir.to_path_buf(), in_workspace); - Ok(in_workspace) + .insert(crate_dir.to_path_buf(), workspace_path.clone()); + Ok(workspace_path) } } }