use cargo_util::paths;
use crates_io::{self, NewCrate, NewCrateDependency, Registry};
use curl::easy::{Easy, InfoType, SslOpt, SslVersion};
-use itertools::Itertools;
use log::{log, Level};
use percent_encoding::{percent_encode, NON_ALPHANUMERIC};
use termcolor::Color::Green;
pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
let specs = opts.to_publish.to_package_id_specs(ws)?;
- let mut pkgs = ws.members_with_features(&specs, &opts.cli_features)?;
-
- if let Packages(opt_in) = &opts.to_publish {
- if ws.is_virtual() {
- bail!("can't use \"--package <SPEC>\" in virtual manifest")
- }
- let matched_packages = ws
- .members()
- .filter(|m| specs.iter().any(|spec| spec.matches(m.package_id())))
- .collect::<Vec<_>>();
- if matched_packages.is_empty() {
- bail!(
- "not found `{}` in manifest members. Check in manifest path `{}`",
- opt_in.get(0).unwrap(),
- ws.root().display()
- )
+ if let Packages(_) = &opts.to_publish {
+ if specs.len() > 1 {
+ bail!("the `-p` argument must be specified to select a single package to publish");
}
- if matched_packages.len() > 1 {
- bail!(
- "found multiple `{}` in manifest members. Check in manifest path `{}`",
- opt_in.get(0).unwrap(),
- ws.root().display()
- )
+ } else {
+ if ws.is_virtual() {
+ bail!("must use `-p` argument in virtual manifest")
}
- pkgs = pkgs
- .into_iter()
- .filter(|(m, _)| specs.iter().any(|spec| spec.matches(m.package_id())))
- .collect_vec();
}
+ let member_ids = ws.members().map(|p| p.package_id());
+ // Check that the spec matches exactly one member.
+ specs[0].query(member_ids)?;
+ let mut pkgs = ws.members_with_features(&specs, &opts.cli_features)?;
+ // Double check
+ assert_eq!(pkgs.len(), 1);
let (pkg, cli_features) = pkgs.pop().unwrap();
[package]
name = "foo"
version = "0.1.0"
- edition = "2018"
+ edition = "2021"
[workspace]
members = ["li"]
"#,
.file("foo/src/main.rs", "fn main() {}")
.build();
- p.cargo("publish --no-verify --token sekrit -p foo")
+ p.cargo("publish --no-verify --token sekrit")
.with_status(101)
- .with_stderr("error: can't use \"--package <SPEC>\" in virtual manifest")
+ .with_stderr("error: must use `-p` argument in virtual manifest")
.run();
}
[package]
name = "foo"
version = "0.1.0"
- edition = "2018"
+ edition = "2021"
[workspace]
"#,
)
.with_status(101)
.with_stderr(
"\
-error: not found `li` in manifest members. Check in manifest path `[CWD]`
+error: package ID specification `li` did not match any packages
+
+<tab>Did you mean `foo`?
",
)
.run();
}
#[cargo_test]
-fn in_package_workspace_found_mutilate() {
+fn in_package_workspace_found_multiple() {
registry::init();
let p = project()
[package]
name = "foo"
version = "0.1.0"
- edition = "2018"
+ edition = "2021"
[workspace]
members = ["li","lii"]
"#,
.with_status(101)
.with_stderr(
"\
-error: found multiple `li*` in manifest members. Check in manifest path `[CWD]`
+error: the `-p` argument must be specified to select a single package to publish
+",
+ )
+ .run();
+}
+
+
+#[cargo_test]
+// https://github.com/rust-lang/cargo/issues/10536
+fn publish_path_dependency_without_workspace() {
+ registry::init();
+
+ let p = project()
+ .file(
+ "Cargo.toml",
+ r#"
+ [package]
+ name = "foo"
+ version = "0.1.0"
+ edition = "2021"
+ [dependencies.bar]
+ path = "bar"
+ "#,
+ )
+ .file("src/main.rs", "fn main() {}")
+ .file(
+ "bar/Cargo.toml",
+ r#"
+ [package]
+ name = "bar"
+ version = "0.0.1"
+ edition = "2021"
+ authors = []
+ license = "MIT"
+ description = "bar"
+ "#,
+ )
+ .file("bar/src/main.rs", "fn main() {}")
+ .build();
+
+ p.cargo("publish -p bar --no-verify --token sekrit ")
+ .with_status(101)
+ .with_stderr(
+ "\
+error: package ID specification `bar` did not match any packages
+
+<tab>Did you mean `foo`?
",
)
.run();
}
+