From 682af715d638fc3dd3d52d92b2279cd303c73922 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 14 Sep 2017 16:52:42 +0200 Subject: [PATCH] get rid of Workspace::current() usage in cargo_{compile,doc} --- src/cargo/core/workspace.rs | 9 +++++++-- src/cargo/ops/cargo_compile.rs | 17 +++++++++++------ src/cargo/ops/cargo_doc.rs | 4 ++-- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/cargo/core/workspace.rs b/src/cargo/core/workspace.rs index 1bbcec5905d..87c0ec1bee4 100644 --- a/src/cargo/core/workspace.rs +++ b/src/cargo/core/workspace.rs @@ -122,6 +122,10 @@ impl<'cfg> Workspace<'cfg> { Ok(ws) } + pub fn current_manifest(&self) -> &Path { + &self.current_manifest + } + /// Creates a "temporary workspace" from one package which only contains /// that package. /// @@ -169,8 +173,9 @@ impl<'cfg> Workspace<'cfg> { /// indicating that something else should be passed. pub fn current(&self) -> CargoResult<&Package> { self.current_opt().ok_or_else(|| - format!("manifest path `{}` contains no package: The manifest is virtual, \ - and the workspace has no members.", self.current_manifest.display()).into() + format!("manifest path `{}` is a virtual manifest, but this \ + command requires running against an actual package in \ + this workspace", self.current_manifest.display()).into() ) } diff --git a/src/cargo/ops/cargo_compile.rs b/src/cargo/ops/cargo_compile.rs index 894d2a7a24d..6717e309880 100644 --- a/src/cargo/ops/cargo_compile.rs +++ b/src/cargo/ops/cargo_compile.rs @@ -143,6 +143,12 @@ impl<'a> Packages<'a> { .filter(|p| opt_out.iter().position(|x| *x == p.name()).is_none()) .collect() } + Packages::Packages(packages) if packages.is_empty() => { + ws.current_opt() + .map(Package::package_id) + .map(PackageIdSpec::from_package_id) + .into_iter().collect() + } Packages::Packages(packages) => { packages.iter().map(|p| PackageIdSpec::parse(&p)).collect::>>()? } @@ -231,17 +237,16 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>, pkgids.push(p.query(resolve_with_overrides.iter())?); } } else { - let root_package = ws.current()?; - root_package.manifest().print_teapot(ws.config()); - let all_features = resolve_all_features(&resolve_with_overrides, - root_package.package_id()); - generate_targets(root_package, profiles, mode, filter, &all_features, release)?; - pkgids.push(root_package.package_id()); + return Err(format!("manifest path `{}` contains no package: The manifest is virtual, \ + and the workspace has no members.", ws.current_manifest().display()).into()); }; let to_builds = pkgids.iter().map(|id| { packages.get(id) }).collect::>>()?; + for p in to_builds.iter() { + p.manifest().print_teapot(ws.config()); + } let mut general_targets = Vec::new(); let mut package_targets = Vec::new(); diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index f02ec220704..4d8c8797b62 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -28,8 +28,8 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> { pkgs.push(packages.get(p.query(resolve_with_overrides.iter())?)?); } } else { - let root_package = ws.current()?; - pkgs.push(root_package); + return Err(format!("manifest path `{}` contains no package: The manifest is virtual, \ + and the workspace has no members.", ws.current_manifest().display()).into()); }; let mut lib_names = HashSet::new();