get rid of Workspace::current() usage in cargo_{compile,doc}
authorRalf Jung <post@ralfj.de>
Thu, 14 Sep 2017 14:52:42 +0000 (16:52 +0200)
committerRalf Jung <post@ralfj.de>
Thu, 14 Sep 2017 14:52:42 +0000 (16:52 +0200)
src/cargo/core/workspace.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_doc.rs

index 1bbcec5905d757894272b4c52dafbd08c1d31bda..87c0ec1bee4c547288e28f0fc64c4ec7831758f8 100644 (file)
@@ -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()
         )
     }
 
index 894d2a7a24da5adc14ab95c5519e2133e241b58a..6717e309880ec21317961769c03c13bb11de6c9b 100644 (file)
@@ -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::<CargoResult<Vec<_>>>()?
             }
@@ -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::<CargoResult<Vec<_>>>()?;
+    for p in to_builds.iter() {
+        p.manifest().print_teapot(ws.config());
+    }
 
     let mut general_targets = Vec::new();
     let mut package_targets = Vec::new();
index f02ec220704eac0e71ce5f4e33338aaef0f5f769..4d8c8797b6222e64bd163d6c30c8bad70435b300 100644 (file)
@@ -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();