mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 10:46:42 +01:00
fix search paths
This commit is contained in:
parent
41a130bce0
commit
da39ae3aab
1 changed files with 53 additions and 21 deletions
|
|
@ -6,12 +6,14 @@ mod link;
|
|||
mod bang;
|
||||
pub(crate) use self::util::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Default)]
|
||||
struct Rebuilder {
|
||||
/// Paths visited
|
||||
paths: BTreeSet<Arc<PathBuf>>,
|
||||
/// Search paths
|
||||
paths: BTreeSet<Arc<PathBuf>>,
|
||||
/// All DLLs in scope
|
||||
dlls: BTreeMap<Arc<str>, Arc<Dll>>,
|
||||
dlls: BTreeMap<Arc<str>, Arc<Dll>>,
|
||||
/// Paths visited
|
||||
visited: BTreeSet<Arc<PathBuf>>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
@ -53,13 +55,40 @@ struct Call {
|
|||
}
|
||||
|
||||
impl Rebuilder {
|
||||
fn new (path: &impl AsRef<Path>) -> Usually<Self> {
|
||||
let mut build = Self { paths: Default::default(), dlls: Default::default() };
|
||||
fn new (paths: &[impl AsRef<Path>]) -> Self {
|
||||
Self {
|
||||
paths: paths.iter().map(|x|Arc::new(x.as_ref().into())).collect(),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
fn load (&mut self, path: &impl AsRef<Path>, recurse: bool) -> Usually<()> {
|
||||
let path: Arc<PathBuf> = Arc::from(PathBuf::from(path.as_ref()));
|
||||
build.paths.insert(path.clone());
|
||||
let dll = Dll::new(&Arc::new(PathBuf::from(path.as_ref())), true)?;
|
||||
build.dlls.insert(dll.name.clone(), dll);
|
||||
Ok(build)
|
||||
self.visited.insert(path.clone());
|
||||
let dll = Arc::new(Dll::new(&Arc::new(PathBuf::from(path.as_ref())), true)?);
|
||||
self.dlls.insert(dll.name.clone(), dll.clone());
|
||||
if recurse {
|
||||
for dep in dll.deps_by_library.keys() {
|
||||
if let Some(dep) = self.find(dep, true)? {
|
||||
println!("{dep:?}");
|
||||
} else {
|
||||
panic!("not found: {dep:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn find (&self, name: &str, verbose: bool) -> Usually<Option<PathBuf>> {
|
||||
for base in self.paths.iter() {
|
||||
let mut path = base.as_ref().clone();
|
||||
path.push(name.to_lowercase());
|
||||
if verbose {
|
||||
println!("looking for {name} at {path:?}");
|
||||
}
|
||||
if std::fs::exists(&path)? {
|
||||
return Ok(Some(canonicalize(&path)?))
|
||||
}
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,7 +96,7 @@ impl Dll {
|
|||
fn new (
|
||||
path: &Arc<PathBuf>,
|
||||
verbose: bool
|
||||
) -> Usually<Arc<Self>> {
|
||||
) -> Usually<Self> {
|
||||
println!("\n(load {BOLD}{path:?}{RESET})");
|
||||
let name = path.file_name().expect("no file name");
|
||||
let name: Arc<str> = name.to_str().map(Arc::from).expect("non-unicode filename");
|
||||
|
|
@ -97,7 +126,7 @@ impl Dll {
|
|||
&mut calls_by_target,
|
||||
true
|
||||
)?;
|
||||
Ok(Arc::new(Self {
|
||||
Ok(Self {
|
||||
name: name.clone(),
|
||||
path: path.clone(),
|
||||
bang,
|
||||
|
|
@ -107,7 +136,7 @@ impl Dll {
|
|||
deps_by_address: deps_by_address.clone(),
|
||||
calls_by_source,
|
||||
calls_by_target,
|
||||
}))
|
||||
})
|
||||
}
|
||||
fn deps (
|
||||
pe: &VecPE,
|
||||
|
|
@ -315,18 +344,21 @@ fn main () -> Usually<()> {
|
|||
let matches = command!()
|
||||
.arg(arg!([path] "Path to VST DLL").value_parser(value_parser!(PathBuf)))
|
||||
.arg(arg!(-i --inspect "Show info, don't run").required(false))
|
||||
//.arg(arg!(-s --stub <VALUE> "Provide stub import").required(false))
|
||||
//.arg(arg!(-s --stub <VALUE> "Provide a stub import").required(false))
|
||||
.get_matches();
|
||||
if let Some(path) = matches.get_one::<PathBuf>("path") {
|
||||
let mut vestal = Vestal::default();
|
||||
vestal.search_paths.push(std::env::current_dir()?);
|
||||
vestal.search_paths.push("/home/user/Lab/Cosmo/wineprefix/drive_c/windows/system32".into());
|
||||
for path in vestal.search_paths.iter() {
|
||||
let mut rebuilder = Rebuilder::new(&[
|
||||
std::env::current_dir()?,
|
||||
canonicalize(path.clone().parent().expect("invalid parent path"))?,
|
||||
"/home/user/Lab/Cosmo/wineprefix/drive_c/windows/system32".into(),
|
||||
]);
|
||||
println!();
|
||||
for path in rebuilder.paths.iter() {
|
||||
println!("(search {path:?})")
|
||||
}
|
||||
if let Some(path) = vestal.resolve(path.to_str().expect("path must be unicode"))? {
|
||||
let rebuilder = Rebuilder::new(&path)?;
|
||||
//vestal.enter(&path)?;
|
||||
if let Some(path) = rebuilder.find(path.to_str().expect("path must be unicode"), false)? {
|
||||
let mut rebuilder = Rebuilder::default();
|
||||
rebuilder.load(&path, true)?;
|
||||
} else {
|
||||
panic!("Could not find: {path:?}")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue