diff options
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 25 |
1 files changed, 18 insertions, 7 deletions
@@ -23,7 +23,9 @@ use audit::audit_package; use license::{normalize_license, split_spdx_license}; use metadata::EbuildConfig; -pub fn gen_ebuild_data(manifest_path: Option<&Path>, audit: bool) -> Result<EbuildConfig> { +pub fn gen_ebuild_data( manifest_path: Option<&Path> + , package_name: Option<&str> + , audit: bool ) -> Result<EbuildConfig> { let mut cmd = MetadataCommand::new(); cmd.features(CargoOpt::AllFeatures); @@ -41,10 +43,19 @@ pub fn gen_ebuild_data(manifest_path: Option<&Path>, audit: bool) -> Result<Ebui .as_ref() .ok_or_else(|| format_err!("cargo metadata did not resolve the depend graph"))?; - let root = resolve - .root - .as_ref() - .ok_or_else(|| format_err!("cargo metadata failed to resolve the root package"))?; + let root = + if let Some(pkg_name) = package_name { + let found_package = + metadata.packages.iter().find(|&p| { + p.name == pkg_name + }).ok_or_else(|| format_err!("cargo metadata contains no specified package"))?; + &found_package.id + } else { + resolve + .root + .as_ref() + .ok_or_else(|| format_err!("cargo metadata failed to resolve the root package"))? + }; if audit { audit_package(metadata.workspace_root.as_ref(), manifest_path)?; @@ -54,7 +65,7 @@ pub fn gen_ebuild_data(manifest_path: Option<&Path>, audit: bool) -> Result<Ebui let mut crates = Vec::new(); let mut root_pkg = None; - for pkg in metadata.packages { + for pkg in &metadata.packages { if &pkg.id == root { root_pkg = Some(pkg.clone()); } @@ -79,7 +90,7 @@ pub fn gen_ebuild_data(manifest_path: Option<&Path>, audit: bool) -> Result<Ebui println!("WARNING: {} uses a license-file, not handled", pkg.name); } - if let Some(src) = pkg.source { + if let Some(src) = &pkg.source { // Check if the crate is available at crates.io if src.is_crates_io() { crates.push(format!("\t{}-{}\n", pkg.name, pkg.version)); |