/// Resolves the dependencies based on the output of ldd on the binary.
Resolves the dependencies based on the output of ldd on the binary.
Resolves the dependencies based on the output of ldd on the binary .
pub fn resolve(path: &Path, architecture: &str, listener: &dyn Listener) -> CDResult<Vec<String>> {
    let dependencies = {
        let output = Command::new("ldd")
            .arg(path)
            .output()
            .map_err(|e| CargoDebError::CommandFailed(e, "ldd"))?;
        if !output.status.success() {
            return Err(CargoDebError::CommandError("ldd", path.display().to_string(), output.stderr));
        }
        String::from_utf8(output.stdout).expect("utf8")
    };
    // Create an iterator of unique dependencies
    let dependencies: HashSet<_> = dependencies.lines()
        // We only want the third field on each line, which contains the filepath of the library.
        .map(|line| line.split_whitespace().nth(2))
        .filter_map(|x| x)
        // If the field exists and starts with '/', we have found a filepath.
        .filter(|x| x.starts_with('/'))
        // Obtain the names of the packages.
        .filter_map(|path_str| {
            get_package_name_with_fallback(path_str)
                .map_err(|err| {
                    listener.warning(format!(
                        "{} (skip this auto dep for {})",
                        err,
                        path.display()
                    ));
                    err
                })
                .ok()
        })
        // only collect unique packages.
        .collect();
    Ok(dependencies.into_par_iter().map(|package| {
        // There can be multiple arch-specific versions of a package
        match get_version(&format!("{}:{}", package, architecture)) {
            Ok(version) => {
                format!("{} (>= {})", package, version)
            },
            Err(e) => {
                listener.warning(format!("Can't get version of {}: {}", package, e));
                package
            },
        }
    }).collect())
}
pub fn resolve ( path : & Path , architecture : & str , listener : & dyn Listener ) -> CDResult < Vec < String > > { let dependencies = { let output = Command :: new ( " " ) . arg ( path ) . output ( ) . map_err ( | e | CargoDebError :: CommandFailed ( e , " " ) ) ? ; if ! output . status . success ( ) { return Err ( CargoDebError :: CommandError ( " " , path . display ( ) . to_string ( ) , output . stderr ) ) ; } String :: from_utf8 ( output . stdout ) . expect ( " " ) } ; // Create an iterator of unique dependencies let dependencies : HashSet < _ > = dependencies . lines ( ) // We only want the third field on each line, which contains the filepath of the library. . map ( | line | line . split_whitespace ( ) . nth ( 2 ) ) . filter_map ( | x | x ) // If the field exists and starts with '/', we have found a filepath. . filter ( | x | x . starts_with ( '/' ) ) // Obtain the names of the packages. . filter_map ( | path_str | { get_package_name_with_fallback ( path_str ) . map_err ( | err | { listener . warning ( format ! ( " " err path display ( ) ) ) ; err } ) . ok ( ) } ) // only collect unique packages. . collect ( ) ; Ok ( dependencies . into_par_iter ( ) . map ( | package | { // There can be multiple arch-specific versions of a package match get_version ( & format ! ( " " package architecture ) ) { Ok ( version ) => { format ! ( " " package version ) } , Err ( e ) => { listener . warning ( format ! ( " " package e ) ) ; package } , } } ) . collect ( ) ) }
Resolves the dependencies based on the output of ldd on the binary.
Resolves the dependencies based on the output of ldd on the binary .
path
&Path
architecture
&str
listener
&dyn Listener