mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Add and use run_linked
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user