mirror of
https://github.com/voltrevo/ValueScript.git
synced 2026-04-18 03:00:27 -04:00
Link modules for vstc compile (almost works)
This commit is contained in:
27
valuescript_compiler/src/resolve_path.rs
Normal file
27
valuescript_compiler/src/resolve_path.rs
Normal file
@@ -0,0 +1,27 @@
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct ResolvedPath {
|
||||
pub path: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for ResolvedPath {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.path)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn resolve_path(importer_path: &ResolvedPath, path: &String) -> ResolvedPath {
|
||||
let importer_path_buf = PathBuf::from(&importer_path.path);
|
||||
let parent = importer_path_buf.parent().unwrap_or_else(|| Path::new("/"));
|
||||
|
||||
ResolvedPath {
|
||||
path: parent
|
||||
.join(path)
|
||||
.canonicalize()
|
||||
.expect("Failed to canonicalize path")
|
||||
.to_str()
|
||||
.expect("Failed to convert path to string")
|
||||
.to_string(),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user