Skip to content

Commit

Permalink
get rid of Workspace::current() usage in cargo_{compile,doc}
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 14, 2017
1 parent 56274af commit 682af71
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
9 changes: 7 additions & 2 deletions src/cargo/core/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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()
)
}

Expand Down
17 changes: 11 additions & 6 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_>>>()?
}
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/cargo/ops/cargo_doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 682af71

Please sign in to comment.