Add and use run_linked

This commit is contained in:
Andrew Morris
2023-03-28 16:25:30 +11:00
parent 683fd182fa
commit aaf89e2cab
10 changed files with 367 additions and 81 deletions

View File

@@ -16,7 +16,7 @@ enum DependencyReason {
ImportedBy(ResolvedPath),
}
#[derive(Clone)]
#[derive(Clone, Debug)]
struct Dependency {
path: ResolvedPath,
reason: DependencyReason,
@@ -94,7 +94,9 @@ where
module: compiler_output.module,
};
for imported_path in get_imported_paths(&path_and_module) {
let imported_paths = get_imported_paths(&path_and_module);
for imported_path in imported_paths {
if gm.modules.contains_key(&imported_path) {
continue;
}

View File

@@ -5,6 +5,12 @@ pub struct ResolvedPath {
pub path: String,
}
impl ResolvedPath {
pub fn from(path: String) -> Self {
Self { path }
}
}
impl std::fmt::Display for ResolvedPath {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.path)
@@ -16,12 +22,31 @@ pub fn resolve_path(importer_path: &ResolvedPath, path: &String) -> ResolvedPath
let parent = importer_path_buf.parent().unwrap_or_else(|| Path::new("/"));
ResolvedPath {
path: parent
.join(path)
.canonicalize()
.expect("Failed to canonicalize path")
path: normalize_path(parent.join(path))
.to_str()
.expect("Failed to convert path to string")
.to_string(),
}
}
fn normalize_path(path_buf: PathBuf) -> PathBuf {
let mut dir_stack = Vec::new();
for component in path_buf.components() {
match component {
std::path::Component::ParentDir => {
// TODO: Error if we're at the root dir
dir_stack.pop();
}
std::path::Component::CurDir => {}
_ => {
dir_stack.push(component);
}
}
}
let mut path_buf = PathBuf::new();
path_buf.extend(dir_stack);
path_buf
}