diff --git a/src/cli.rs b/src/cli.rs index c334ee5c..f92b654a 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -129,7 +129,7 @@ impl Args { let mut cargo_args = vec![]; let mut subcommand: Option = None; - let mut manifest_path = None; + let mut manifest_path: Option = None; let mut color = None; let mut package = vec![]; diff --git a/src/context.rs b/src/context.rs index a6c8c275..3c259022 100644 --- a/src/context.rs +++ b/src/context.rs @@ -47,7 +47,8 @@ impl Context { // if `--remove-dev-deps` flag is off, restore manifest file. let restore = restore::Manager::new(!args.remove_dev_deps); - let metadata = Metadata::new(&args, &cargo, cargo_version, &restore)?; + let metadata = + Metadata::new(args.manifest_path.as_deref(), &cargo, cargo_version, &restore)?; if metadata.cargo_version < 41 && args.include_deps_features { bail!("--include-deps-features requires Cargo 1.41 or later"); } diff --git a/src/manifest.rs b/src/manifest.rs index 0fd4487d..2f474b05 100644 --- a/src/manifest.rs +++ b/src/manifest.rs @@ -1,16 +1,8 @@ -use std::{ - collections::BTreeMap, - path::{Path, PathBuf}, -}; +use std::{collections::BTreeMap, path::Path}; use anyhow::{bail, format_err, Context as _, Result}; -use crate::{ - context::Context, - fs, - metadata::{self, Metadata}, - term, -}; +use crate::{context::Context, fs, metadata::Metadata, term}; type ParseResult = Result; @@ -115,7 +107,7 @@ pub(crate) fn with(cx: &Context, f: impl FnOnce() -> Result<()>) -> Result<()> { let mut private_crates = vec![]; for id in &cx.metadata.workspace_members { let package = cx.packages(id); - let manifest_path = &package.manifest_path; + let manifest_path = &*package.manifest_path; let is_root = manifest_path == root_manifest; if is_root { root_id = Some(id); @@ -171,13 +163,13 @@ pub(crate) fn with(cx: &Context, f: impl FnOnce() -> Result<()>) -> Result<()> { if term::verbose() { info!("removing private crates from {}", manifest_path.display()); } - remove_private_crates(&mut doc, &cx.metadata, &private_crates)?; + remove_private_crates(&mut doc, workspace_root, &private_crates)?; } restore_handles.push(cx.restore.register(orig, manifest_path)); fs::write(manifest_path, doc.to_string())?; } if restore_lockfile { - let lockfile = &cx.metadata.workspace_root.join("Cargo.lock"); + let lockfile = &workspace_root.join("Cargo.lock"); if lockfile.exists() { restore_handles.push(cx.restore.register(fs::read_to_string(lockfile)?, lockfile)); } @@ -210,8 +202,8 @@ fn remove_dev_deps(doc: &mut toml_edit::Document) { fn remove_private_crates( doc: &mut toml_edit::Document, - metadata: &metadata::Metadata, - private_crates: &[&PathBuf], + workspace_root: &Path, + private_crates: &[&Path], ) -> Result<()> { let table = doc.as_table_mut(); if let Some(workspace) = table.get_mut("workspace").and_then(toml_edit::Item::as_table_like_mut) @@ -221,7 +213,7 @@ fn remove_private_crates( let mut i = 0; while i < members.len() { if let Some(member) = members.get(i).and_then(toml_edit::Value::as_str) { - let manifest_path = metadata.workspace_root.join(member).join("Cargo.toml"); + let manifest_path = workspace_root.join(member).join("Cargo.toml"); if private_crates .iter() .find_map(|p| { diff --git a/src/metadata.rs b/src/metadata.rs index f6ac0df1..56e432d7 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -14,7 +14,7 @@ use std::{ use anyhow::{format_err, Context as _, Result}; use serde_json::{Map, Value}; -use crate::{cargo, cli::Args, fs, restore, term}; +use crate::{cargo, fs, restore, term}; type Object = Map; type ParseResult = Result; @@ -47,7 +47,7 @@ pub(crate) struct Metadata { impl Metadata { pub(crate) fn new( - args: &Args, + manifest_path: Option<&str>, cargo: &OsStr, mut cargo_version: u32, restore: &restore::Manager, @@ -57,7 +57,7 @@ impl Metadata { let mut cmd; let json = if stable_cargo_version > cargo_version { cmd = cmd!(cargo, "metadata", "--format-version=1", "--no-deps"); - if let Some(manifest_path) = &args.manifest_path { + if let Some(manifest_path) = manifest_path { cmd.arg("--manifest-path"); cmd.arg(manifest_path); } @@ -67,7 +67,7 @@ impl Metadata { Path::new(no_deps["workspace_root"].as_str().unwrap()).join("Cargo.lock"); if !lockfile.exists() { let mut cmd = cmd!(cargo, "generate-lockfile"); - if let Some(manifest_path) = &args.manifest_path { + if let Some(manifest_path) = manifest_path { cmd.arg("--manifest-path"); cmd.arg(manifest_path); } @@ -79,7 +79,7 @@ impl Metadata { // a dependency that requires newer cargo features, `cargo metadata` // with older cargo may fail. cmd = cmd!("cargo", "+stable", "metadata", "--format-version=1"); - if let Some(manifest_path) = &args.manifest_path { + if let Some(manifest_path) = manifest_path { cmd.arg("--manifest-path"); cmd.arg(manifest_path); } @@ -94,7 +94,7 @@ impl Metadata { Err(_e) => { // If failed, try again with the version of cargo we will actually use. cmd = cmd!(cargo, "metadata", "--format-version=1"); - if let Some(manifest_path) = &args.manifest_path { + if let Some(manifest_path) = manifest_path { cmd.arg("--manifest-path"); cmd.arg(manifest_path); } @@ -103,7 +103,7 @@ impl Metadata { } } else { cmd = cmd!(cargo, "metadata", "--format-version=1"); - if let Some(manifest_path) = &args.manifest_path { + if let Some(manifest_path) = manifest_path { cmd.arg("--manifest-path"); cmd.arg(manifest_path); } @@ -252,7 +252,6 @@ pub(crate) struct Package { /// The minimum supported Rust version of this package. /// /// This is always `None` if running with a version of Cargo older than 1.58. - #[allow(dead_code)] pub(crate) rust_version: Option, } diff --git a/src/rustup.rs b/src/rustup.rs index 284e4342..9577bbf6 100644 --- a/src/rustup.rs +++ b/src/rustup.rs @@ -41,7 +41,11 @@ pub(crate) fn version_range( let start = match split.next().unwrap() { "" => { let mut rust_version = None; + // TODO: we should only check members we actually run command. for id in cx.workspace_members() { + if cx.ignore_private && cx.is_private(id) { + continue; + } let v = cx.rust_version(id); if v.is_none() || v == rust_version { // no-op @@ -53,7 +57,7 @@ pub(crate) fn version_range( } match rust_version { Some(v) => v.parse()?, - None => bail!("no rust-version field in Cargo.toml is specified"), + None => bail!("no rust-version field in any Cargo.toml is specified"), } } s => s.parse()?,