diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 25 | ||||
-rw-r--r-- | src/main.rs | 8 |
2 files changed, 25 insertions, 8 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)); diff --git a/src/main.rs b/src/main.rs index 1072094..edffb18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,6 +23,10 @@ struct Args { /// Path to Cargo.toml. manifest_path: Option<PathBuf>, + #[structopt(name = "PACKAGE", long = "package-name")] + /// Desired package name from cargo workspace + package_name: Option<String>, + #[structopt(name = "TEMPLATE", long = "template-path", short)] /// Non-standard template template_path: Option<PathBuf>, @@ -49,7 +53,9 @@ fn main() -> Result<()> { let Opt::Ebuild(opt) = Opt::from_args(); // compute the data from the package that the build needs - let ebuild_data = gen_ebuild_data(opt.manifest_path.as_deref(), !opt.noaudit)?; + let ebuild_data = gen_ebuild_data( opt.manifest_path.as_deref() + , opt.package_name.as_deref() + , !opt.noaudit )?; let ebuild_path = format!("{}-{}.ebuild", ebuild_data.name, ebuild_data.version); write_ebuild(ebuild_data, ebuild_path.as_ref(), opt.template_path.as_deref())?; |