resolve dependencies recursively

This commit is contained in:
🪞👃🪞 2025-02-21 23:49:44 +02:00
parent da39ae3aab
commit a6511a5ed2

View file

@ -63,13 +63,16 @@ impl Rebuilder {
} }
fn load (&mut self, path: &impl AsRef<Path>, recurse: bool) -> Usually<()> { 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()));
if self.visited.contains(&path) {
return Ok(())
}
self.visited.insert(path.clone()); self.visited.insert(path.clone());
let dll = Arc::new(Dll::new(&Arc::new(PathBuf::from(path.as_ref())), true)?); let dll = Arc::new(Dll::new(&Arc::new(PathBuf::from(path.as_ref())), false)?);
self.dlls.insert(dll.name.clone(), dll.clone()); self.dlls.insert(dll.name.clone(), dll.clone());
if recurse { if recurse {
for dep in dll.deps_by_library.keys() { for dep in dll.deps_by_library.keys() {
if let Some(dep) = self.find(dep, true)? { if let Some(dep) = self.find(dep, false)? {
println!("{dep:?}"); self.load(&dep, recurse)?;
} else { } else {
panic!("not found: {dep:?}"); panic!("not found: {dep:?}");
} }
@ -82,9 +85,12 @@ impl Rebuilder {
let mut path = base.as_ref().clone(); let mut path = base.as_ref().clone();
path.push(name.to_lowercase()); path.push(name.to_lowercase());
if verbose { if verbose {
println!("looking for {name} at {path:?}"); println!("# looking for {name} at {path:?}");
} }
if std::fs::exists(&path)? { if std::fs::exists(&path)? {
if verbose {
println!("# found {name} at {path:?}");
}
return Ok(Some(canonicalize(&path)?)) return Ok(Some(canonicalize(&path)?))
} }
} }
@ -124,7 +130,7 @@ impl Dll {
Some(&deps_by_address), Some(&deps_by_address),
&mut calls_by_source, &mut calls_by_source,
&mut calls_by_target, &mut calls_by_target,
true false
)?; )?;
Ok(Self { Ok(Self {
name: name.clone(), name: name.clone(),
@ -357,7 +363,6 @@ fn main () -> Usually<()> {
println!("(search {path:?})") println!("(search {path:?})")
} }
if let Some(path) = rebuilder.find(path.to_str().expect("path must be unicode"), false)? { if let Some(path) = rebuilder.find(path.to_str().expect("path must be unicode"), false)? {
let mut rebuilder = Rebuilder::default();
rebuilder.load(&path, true)?; rebuilder.load(&path, true)?;
} else { } else {
panic!("Could not find: {path:?}") panic!("Could not find: {path:?}")