Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix confusing error and docs wrt. virtual manifests #4492

Merged
merged 4 commits into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/bin/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ the current package is benchmarked. For more information on SPEC and its format,
see the `cargo help pkgid` command.

All packages in the workspace are benchmarked if the `--all` flag is supplied. The
`--all` flag may be supplied in the presence of a virtual manifest.
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.

The --jobs argument affects the building of the benchmark executable but does
not affect how many jobs are used when running the benchmarks.
Expand Down
2 changes: 1 addition & 1 deletion src/bin/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ current package is built. For more information on SPEC and its format, see the
`cargo help pkgid` command.

All packages in the workspace are built if the `--all` flag is supplied. The
`--all` flag may be supplied in the presence of a virtual manifest.
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.

Compilation can be configured via the use of profiles which are configured in
Expand Down
4 changes: 4 additions & 0 deletions src/bin/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ which indicates which package should be built. If it is not given, then the
current package is built. For more information on SPEC and its format, see the
`cargo help pkgid` command.

All packages in the workspace are checked if the `--all` flag is supplied. The
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.

Compilation can be configured via the use of profiles which are configured in
the manifest. The default profile for this command is `dev`, but passing
the --release flag will use the `release` profile instead.
Expand Down
3 changes: 2 additions & 1 deletion src/bin/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ By default the documentation for the local package and all dependencies is
built. The output is all placed in `target/doc` in rustdoc's usual format.

All packages in the workspace are documented if the `--all` flag is supplied. The
`--all` flag may be supplied in the presence of a virtual manifest.
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.

If the --package argument is given, then SPEC is a package id specification
which indicates which package should be documented. If it is not given, then the
Expand Down
3 changes: 2 additions & 1 deletion src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ current package is tested. For more information on SPEC and its format, see the
`cargo help pkgid` command.

All packages in the workspace are tested if the `--all` flag is supplied. The
`--all` flag may be supplied in the presence of a virtual manifest.
`--all` flag is automatically assumed for a virtual manifest.
Note that `--exclude` has to be specified in conjunction with the `--all` flag.

The --jobs argument affects the building of the test executable but does
not affect how many jobs are used when running the tests. The default value
Expand Down
4 changes: 4 additions & 0 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
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
6 changes: 4 additions & 2 deletions src/doc/manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -457,10 +457,12 @@ as:
```toml
[workspace]

# Optional key, inferred if not present
# Optional key, inferred from path dependencies if not present.
# Additional non-path dependencies that should be included must be given here.
# In particular, for a virtual manifest, all members have to be listed.
members = ["path/to/member1", "path/to/member2", "path/to/member3/*"]

# Optional key, empty if not present
# Optional key, empty if not present.
exclude = ["path1", "path/to/dir2"]
```

Expand Down
13 changes: 3 additions & 10 deletions tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,20 +696,13 @@ fn virtual_build_no_members() {
let p = project("foo")
.file("Cargo.toml", r#"
[workspace]
"#)
.file("bar/Cargo.toml", r#"
[project]
name = "bar"
version = "0.1.0"
authors = []
"#)
.file("bar/src/main.rs", "fn main() {}");
"#);
p.build();
assert_that(p.cargo("build"),
execs().with_status(101)
.with_stderr("\
error: manifest path `[..]` is a virtual manifest, but this command \
requires running against an actual package in this workspace
error: manifest path `[..]` contains no package: The manifest is virtual, \
and the workspace has no members.
"));
}

Expand Down