aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMiezhiko <Miezhiko@gmail.com>2021-09-22 15:10:28 +0400
committerGeorgy Yakovlev <gyakovlev@gentoo.org>2021-10-07 09:21:54 -0700
commit02ddf334369229a1f7aab44a8e919a954e2124c5 (patch)
tree112686604ed98dfa51fbf66ccc6fc2fd075ee4f6 /src
parentset development version to 0.4.1-dev (diff)
downloadcargo-ebuild-02ddf334369229a1f7aab44a8e919a954e2124c5.tar.gz
cargo-ebuild-02ddf334369229a1f7aab44a8e919a954e2124c5.tar.bz2
cargo-ebuild-02ddf334369229a1f7aab44a8e919a954e2124c5.zip
package-name option support, it needs for Cargo.toml without root package
Signed-off-by: Miezhiko <Miezhiko@gmail.com> Signed-off-by: Georgy Yakovlev <gyakovlev@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs25
-rw-r--r--src/main.rs8
2 files changed, 25 insertions, 8 deletions
diff --git a/src/lib.rs b/src/lib.rs
index f478bc0..94ebf71 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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())?;