mirror of
https://codeberg.org/unspeaker/vestal.git
synced 2025-12-06 12:56:41 +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;
|
mod bang;
|
||||||
pub(crate) use self::util::*;
|
pub(crate) use self::util::*;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
struct Rebuilder {
|
struct Rebuilder {
|
||||||
/// Paths visited
|
/// Search paths
|
||||||
paths: BTreeSet<Arc<PathBuf>>,
|
paths: BTreeSet<Arc<PathBuf>>,
|
||||||
/// All DLLs in scope
|
/// All DLLs in scope
|
||||||
dlls: BTreeMap<Arc<str>, Arc<Dll>>,
|
dlls: BTreeMap<Arc<str>, Arc<Dll>>,
|
||||||
|
/// Paths visited
|
||||||
|
visited: BTreeSet<Arc<PathBuf>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
|
@ -53,13 +55,40 @@ struct Call {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Rebuilder {
|
impl Rebuilder {
|
||||||
fn new (path: &impl AsRef<Path>) -> Usually<Self> {
|
fn new (paths: &[impl AsRef<Path>]) -> Self {
|
||||||
let mut build = Self { paths: Default::default(), dlls: Default::default() };
|
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()));
|
let path: Arc<PathBuf> = Arc::from(PathBuf::from(path.as_ref()));
|
||||||
build.paths.insert(path.clone());
|
self.visited.insert(path.clone());
|
||||||
let dll = Dll::new(&Arc::new(PathBuf::from(path.as_ref())), true)?;
|
let dll = Arc::new(Dll::new(&Arc::new(PathBuf::from(path.as_ref())), true)?);
|
||||||
build.dlls.insert(dll.name.clone(), dll);
|
self.dlls.insert(dll.name.clone(), dll.clone());
|
||||||
Ok(build)
|
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 (
|
fn new (
|
||||||
path: &Arc<PathBuf>,
|
path: &Arc<PathBuf>,
|
||||||
verbose: bool
|
verbose: bool
|
||||||
) -> Usually<Arc<Self>> {
|
) -> Usually<Self> {
|
||||||
println!("\n(load {BOLD}{path:?}{RESET})");
|
println!("\n(load {BOLD}{path:?}{RESET})");
|
||||||
let name = path.file_name().expect("no file name");
|
let name = path.file_name().expect("no file name");
|
||||||
let name: Arc<str> = name.to_str().map(Arc::from).expect("non-unicode filename");
|
let name: Arc<str> = name.to_str().map(Arc::from).expect("non-unicode filename");
|
||||||
|
|
@ -97,7 +126,7 @@ impl Dll {
|
||||||
&mut calls_by_target,
|
&mut calls_by_target,
|
||||||
true
|
true
|
||||||
)?;
|
)?;
|
||||||
Ok(Arc::new(Self {
|
Ok(Self {
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
path: path.clone(),
|
path: path.clone(),
|
||||||
bang,
|
bang,
|
||||||
|
|
@ -107,7 +136,7 @@ impl Dll {
|
||||||
deps_by_address: deps_by_address.clone(),
|
deps_by_address: deps_by_address.clone(),
|
||||||
calls_by_source,
|
calls_by_source,
|
||||||
calls_by_target,
|
calls_by_target,
|
||||||
}))
|
})
|
||||||
}
|
}
|
||||||
fn deps (
|
fn deps (
|
||||||
pe: &VecPE,
|
pe: &VecPE,
|
||||||
|
|
@ -315,18 +344,21 @@ fn main () -> Usually<()> {
|
||||||
let matches = command!()
|
let matches = command!()
|
||||||
.arg(arg!([path] "Path to VST DLL").value_parser(value_parser!(PathBuf)))
|
.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!(-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();
|
.get_matches();
|
||||||
if let Some(path) = matches.get_one::<PathBuf>("path") {
|
if let Some(path) = matches.get_one::<PathBuf>("path") {
|
||||||
let mut vestal = Vestal::default();
|
let mut rebuilder = Rebuilder::new(&[
|
||||||
vestal.search_paths.push(std::env::current_dir()?);
|
std::env::current_dir()?,
|
||||||
vestal.search_paths.push("/home/user/Lab/Cosmo/wineprefix/drive_c/windows/system32".into());
|
canonicalize(path.clone().parent().expect("invalid parent path"))?,
|
||||||
for path in vestal.search_paths.iter() {
|
"/home/user/Lab/Cosmo/wineprefix/drive_c/windows/system32".into(),
|
||||||
|
]);
|
||||||
|
println!();
|
||||||
|
for path in rebuilder.paths.iter() {
|
||||||
println!("(search {path:?})")
|
println!("(search {path:?})")
|
||||||
}
|
}
|
||||||
if let Some(path) = vestal.resolve(path.to_str().expect("path must be unicode"))? {
|
if let Some(path) = rebuilder.find(path.to_str().expect("path must be unicode"), false)? {
|
||||||
let rebuilder = Rebuilder::new(&path)?;
|
let mut rebuilder = Rebuilder::default();
|
||||||
//vestal.enter(&path)?;
|
rebuilder.load(&path, true)?;
|
||||||
} else {
|
} else {
|
||||||
panic!("Could not find: {path:?}")
|
panic!("Could not find: {path:?}")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue