Skip to content

Commit 682af71

Browse files
committed
get rid of Workspace::current() usage in cargo_{compile,doc}
1 parent 56274af commit 682af71

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

src/cargo/core/workspace.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ impl<'cfg> Workspace<'cfg> {
122122
Ok(ws)
123123
}
124124

125+
pub fn current_manifest(&self) -> &Path {
126+
&self.current_manifest
127+
}
128+
125129
/// Creates a "temporary workspace" from one package which only contains
126130
/// that package.
127131
///
@@ -169,8 +173,9 @@ impl<'cfg> Workspace<'cfg> {
169173
/// indicating that something else should be passed.
170174
pub fn current(&self) -> CargoResult<&Package> {
171175
self.current_opt().ok_or_else(||
172-
format!("manifest path `{}` contains no package: The manifest is virtual, \
173-
and the workspace has no members.", self.current_manifest.display()).into()
176+
format!("manifest path `{}` is a virtual manifest, but this \
177+
command requires running against an actual package in \
178+
this workspace", self.current_manifest.display()).into()
174179
)
175180
}
176181

src/cargo/ops/cargo_compile.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ impl<'a> Packages<'a> {
143143
.filter(|p| opt_out.iter().position(|x| *x == p.name()).is_none())
144144
.collect()
145145
}
146+
Packages::Packages(packages) if packages.is_empty() => {
147+
ws.current_opt()
148+
.map(Package::package_id)
149+
.map(PackageIdSpec::from_package_id)
150+
.into_iter().collect()
151+
}
146152
Packages::Packages(packages) => {
147153
packages.iter().map(|p| PackageIdSpec::parse(&p)).collect::<CargoResult<Vec<_>>>()?
148154
}
@@ -231,17 +237,16 @@ pub fn compile_ws<'a>(ws: &Workspace<'a>,
231237
pkgids.push(p.query(resolve_with_overrides.iter())?);
232238
}
233239
} else {
234-
let root_package = ws.current()?;
235-
root_package.manifest().print_teapot(ws.config());
236-
let all_features = resolve_all_features(&resolve_with_overrides,
237-
root_package.package_id());
238-
generate_targets(root_package, profiles, mode, filter, &all_features, release)?;
239-
pkgids.push(root_package.package_id());
240+
return Err(format!("manifest path `{}` contains no package: The manifest is virtual, \
241+
and the workspace has no members.", ws.current_manifest().display()).into());
240242
};
241243

242244
let to_builds = pkgids.iter().map(|id| {
243245
packages.get(id)
244246
}).collect::<CargoResult<Vec<_>>>()?;
247+
for p in to_builds.iter() {
248+
p.manifest().print_teapot(ws.config());
249+
}
245250

246251
let mut general_targets = Vec::new();
247252
let mut package_targets = Vec::new();

src/cargo/ops/cargo_doc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub fn doc(ws: &Workspace, options: &DocOptions) -> CargoResult<()> {
2828
pkgs.push(packages.get(p.query(resolve_with_overrides.iter())?)?);
2929
}
3030
} else {
31-
let root_package = ws.current()?;
32-
pkgs.push(root_package);
31+
return Err(format!("manifest path `{}` contains no package: The manifest is virtual, \
32+
and the workspace has no members.", ws.current_manifest().display()).into());
3333
};
3434

3535
let mut lib_names = HashSet::new();

0 commit comments

Comments
 (0)