From 028aa47a3c65abb4f0ed538dbd7d9b653cd24038 Mon Sep 17 00:00:00 2001 From: Arlo Siemsen Date: Wed, 27 Jul 2022 13:44:38 -0500 Subject: [PATCH] Implement RFC 3289: source replacement ambiguity --- crates/cargo-test-support/src/lib.rs | 15 +++ crates/cargo-test-support/src/registry.rs | 7 +- src/cargo/core/source/source_id.rs | 13 +++ src/cargo/ops/registry.rs | 105 ++++++++---------- src/cargo/sources/config.rs | 27 +++-- src/doc/src/reference/source-replacement.md | 3 + tests/testsuite/artifact_dep.rs | 2 +- tests/testsuite/bad_config.rs | 4 +- tests/testsuite/cargo_features.rs | 2 +- tests/testsuite/credential_process.rs | 24 ++-- tests/testsuite/cross_publish.rs | 2 +- tests/testsuite/features_namespaced.rs | 4 +- .../testsuite/inheritable_workspace_fields.rs | 17 ++- tests/testsuite/logout.rs | 2 + tests/testsuite/owner.rs | 6 +- tests/testsuite/publish.rs | 96 ++++++++-------- tests/testsuite/registry.rs | 29 +++-- tests/testsuite/search.rs | 10 +- tests/testsuite/weak_dep_features.rs | 2 +- tests/testsuite/yank.rs | 10 +- 20 files changed, 213 insertions(+), 167 deletions(-) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 0d61d5931d90..f90eb46ca249 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -818,6 +818,20 @@ impl Execs { self } + /// Allows replacement of crates-io source without specifying --registry + /// + /// Can be used for testing crates-io specific items where alt registries + /// cannot be used. + pub fn allow_silent_crates_io_replacement(&mut self) -> &mut Self { + if let Some(ref mut p) = self.process_builder { + p.env( + "__CARGO_TEST_ALLOW_CRATES_IO_REPLACEMENT_DO_NOT_USE", + "true", + ); + } + self + } + pub fn enable_mac_dsym(&mut self) -> &mut Self { if cfg!(target_os = "macos") { self.env("CARGO_PROFILE_DEV_SPLIT_DEBUGINFO", "packed") @@ -1214,6 +1228,7 @@ pub trait TestEnv: Sized { // stable channel yet. Once incremental support hits the stable compiler we // can switch this to one and then fix the tests. .env("CARGO_INCREMENTAL", "0") + .env("__CARGO_TEST_CRATESIO_REPLACEMENT", "true") .env_remove("__CARGO_DEFAULT_LIB_METADATA") .env_remove("RUSTC") .env_remove("RUSTDOC") diff --git a/crates/cargo-test-support/src/registry.rs b/crates/cargo-test-support/src/registry.rs index 5a0a4c582807..9f6ced2fc1b6 100644 --- a/crates/cargo-test-support/src/registry.rs +++ b/crates/cargo-test-support/src/registry.rs @@ -250,8 +250,8 @@ impl RegistryBuilder { [source.crates-io] replace-with = 'dummy-registry' - [source.dummy-registry] - registry = '{}'", + [registries.dummy-registry] + index = '{}'", registry.index_url ) .as_bytes(), @@ -282,6 +282,9 @@ impl RegistryBuilder { r#" [registry] token = "{token}" + + [registries.dummy-registry] + token = "{token}" "# ) .as_bytes(), diff --git a/src/cargo/core/source/source_id.rs b/src/cargo/core/source/source_id.rs index c51a67c5074f..83779a114c8d 100644 --- a/src/cargo/core/source/source_id.rs +++ b/src/cargo/core/source/source_id.rs @@ -39,6 +39,10 @@ struct SourceIdInner { /// WARNING: this is not always set for alt-registries when the name is /// not known. name: Option, + /// Name of the alt registry in the [registries] table. + /// WARNING: this is not always set for alt-registries when the name is + /// not known. + alt_registry_key: Option, } /// The possible kinds of code source. Along with `SourceIdInner`, this fully defines the @@ -81,6 +85,7 @@ impl SourceId { url, precise: None, name: name.map(|n| n.into()), + alt_registry_key: None, }); Ok(source_id) } @@ -228,6 +233,7 @@ impl SourceId { url, precise: None, name: Some(key.to_string()), + alt_registry_key: Some(key.to_string()), })) } @@ -264,6 +270,13 @@ impl SourceId { } } + /// Gets the name of the remote registry as defined in the [registries] table. + /// WARNING: alt registries that come from Cargo.lock, or --index will + /// not have a name. + pub fn alt_registry_key(&self) -> Option<&str> { + self.inner.alt_registry_key.as_deref() + } + /// Returns `true` if this source is from a filesystem path. pub fn is_path(self) -> bool { self.inner.kind == SourceKind::Path diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 303b9466d7e6..034eceba4119 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -444,11 +444,9 @@ pub fn registry_configuration( /// /// * `token`: The token from the command-line. If not set, uses the token /// from the config. -/// * `index`: The index URL from the command-line. This is ignored if -/// `registry` is set. +/// * `index`: The index URL from the command-line. /// * `registry`: The registry name from the command-line. If neither -/// `registry`, or `index` are set, then uses `crates-io`, honoring -/// `[source]` replacement if defined. +/// `registry`, or `index` are set, then uses `crates-io`. /// * `force_update`: If `true`, forces the index to be updated. /// * `validate_token`: If `true`, the token must be set. fn registry( @@ -459,24 +457,8 @@ fn registry( force_update: bool, validate_token: bool, ) -> CargoResult<(Registry, RegistryConfig, SourceId)> { - if index.is_some() && registry.is_some() { - // Otherwise we would silently ignore one or the other. - bail!("both `--index` and `--registry` should not be set at the same time"); - } - // Parse all configuration options + let (sid, sid_no_replacement) = get_source_id(config, index, registry)?; let reg_cfg = registry_configuration(config, registry)?; - let opt_index = registry - .map(|r| config.get_registry_index(r)) - .transpose()? - .map(|u| u.to_string()); - let sid = get_source_id(config, opt_index.as_deref().or(index), registry)?; - if !sid.is_remote_registry() { - bail!( - "{} does not support API commands.\n\ - Check for a source-replacement in .cargo/config.", - sid - ); - } let api_host = { let _lock = config.acquire_package_cache_lock()?; let mut src = RegistrySource::remote(sid, &HashSet::new(), config)?; @@ -503,42 +485,18 @@ fn registry( } token } else { - // Check `is_default_registry` so that the crates.io index can - // change config.json's "api" value, and this won't affect most - // people. It will affect those using source replacement, but - // hopefully that's a relatively small set of users. - if token.is_none() - && reg_cfg.is_token() - && registry.is_none() - && !sid.is_default_registry() - && !crates_io::is_url_crates_io(&api_host) - { - config.shell().warn( - "using `registry.token` config value with source \ - replacement is deprecated\n\ - This may become a hard error in the future; \ - see .\n\ - Use the --token command-line flag to remove this warning.", - )?; - reg_cfg.as_token().map(|t| t.to_owned()) - } else { - let token = - auth::auth_token(config, token.as_deref(), ®_cfg, registry, &api_host)?; - Some(token) - } + let token = auth::auth_token(config, token.as_deref(), ®_cfg, registry, &api_host)?; + Some(token) } } else { None }; let handle = http_handle(config)?; - // Workaround for the sparse+https://index.crates.io replacement index. Use the non-replaced - // source_id so that the original (github) url is used when publishing a crate. - let sid = if sid.is_default_registry() { - SourceId::crates_io(config)? - } else { - sid - }; - Ok((Registry::new_handle(api_host, token, handle), reg_cfg, sid)) + Ok(( + Registry::new_handle(api_host, token, handle), + reg_cfg, + sid_no_replacement, + )) } /// Creates a new HTTP handle with appropriate global configuration for cargo. @@ -943,16 +901,41 @@ pub fn yank( /// Gets the SourceId for an index or registry setting. /// /// The `index` and `reg` values are from the command-line or config settings. -/// If both are None, returns the source for crates.io. -fn get_source_id(config: &Config, index: Option<&str>, reg: Option<&str>) -> CargoResult { - match (reg, index) { - (Some(r), _) => SourceId::alt_registry(config, r), - (_, Some(i)) => SourceId::for_registry(&i.into_url()?), - _ => { - let map = SourceConfigMap::new(config)?; - let src = map.load(SourceId::crates_io(config)?, &HashSet::new())?; - Ok(src.replaced_source_id()) +/// If both are None, and no source-replacement is configured, returns the source for crates.io. +/// If both are None, and source replacement is configured, returns an error (except when testing Cargo). +/// +/// If `reg` is set, source replacement is not followed. +fn get_source_id( + config: &Config, + index: Option<&str>, + reg: Option<&str>, +) -> CargoResult<(SourceId, SourceId)> { + let map = SourceConfigMap::new(config)?; + let sid = match (reg, index) { + (None, None) | (Some("crates-io"), None) => SourceId::crates_io(config)?, + (Some(r), None) => SourceId::alt_registry(config, r)?, + (None, Some(i)) => SourceId::for_registry(&i.into_url()?)?, + (Some(_), Some(_)) => { + bail!("both `--index` and `--registry` should not be set at the same time") } + }; + let src = map.load(sid, &HashSet::new())?; + if src.is_replaced() && reg.is_none() && index.is_none() { + // Neither --registry nor --index was passed and source replacement is configured. + let replacement_sid = src.replaced_source_id(); + if replacement_sid.is_default_registry() + || std::env::var("__CARGO_TEST_ALLOW_CRATES_IO_REPLACEMENT_DO_NOT_USE").is_ok() + { + // Allow replacement of crates.io for the sparse crates.io endpoint or for Cargo's + // testing framework. + Ok((replacement_sid, sid)) + } else if let Some(replacement_name) = replacement_sid.alt_registry_key() { + bail!("crates-io is replaced with remote registry {replacement_name};\ninclude `--registry {replacement_name}` or `--registry crates-io`"); + } else { + bail!("crates-io is replaced with non-remote-registry source {replacement_sid};\ninclude `--registry crates-io` to publish to crates.io"); + } + } else { + Ok((sid.clone(), sid)) } } diff --git a/src/cargo/sources/config.rs b/src/cargo/sources/config.rs index 6d6c7ee3944a..b98d5b53690f 100644 --- a/src/cargo/sources/config.rs +++ b/src/cargo/sources/config.rs @@ -121,18 +121,24 @@ impl<'cfg> SourceConfigMap<'cfg> { }; let mut cfg_loc = ""; let orig_name = name; - let new_id; - loop { + let new_id = loop { let cfg = match self.cfgs.get(name) { Some(cfg) => cfg, - None => bail!( - "could not find a configured source with the \ + None => { + // Attempt to interpret the source name as an alt registry name + if let Ok(alt_id) = SourceId::alt_registry(self.config, name) { + debug!("following pointer to registry {}", name); + break alt_id.with_precise(id.precise().map(str::to_string)); + } + bail!( + "could not find a configured source with the \ name `{}` when attempting to lookup `{}` \ (configuration in `{}`)", - name, - orig_name, - cfg_loc - ), + name, + orig_name, + cfg_loc + ); + } }; match &cfg.replace_with { Some((s, c)) => { @@ -141,8 +147,7 @@ impl<'cfg> SourceConfigMap<'cfg> { } None if id == cfg.id => return id.load(self.config, yanked_whitelist), None => { - new_id = cfg.id.with_precise(id.precise().map(|s| s.to_string())); - break; + break cfg.id.with_precise(id.precise().map(|s| s.to_string())); } } debug!("following pointer to {}", name); @@ -155,7 +160,7 @@ impl<'cfg> SourceConfigMap<'cfg> { cfg_loc ) } - } + }; let new_src = new_id.load( self.config, diff --git a/src/doc/src/reference/source-replacement.md b/src/doc/src/reference/source-replacement.md index 3ee3e7f0e07c..647f230eaff3 100644 --- a/src/doc/src/reference/source-replacement.md +++ b/src/doc/src/reference/source-replacement.md @@ -50,6 +50,9 @@ directory = "vendor" # The crates.io default source for crates is available under the name # "crates-io", and here we use the `replace-with` key to indicate that it's # replaced with our source above. +# +# The `replace-with` key can also reference an alternative registry name +# defined in the `[registries]` table. [source.crates-io] replace-with = "my-vendor-source" diff --git a/tests/testsuite/artifact_dep.rs b/tests/testsuite/artifact_dep.rs index 521e59537bea..6a1b16772f16 100644 --- a/tests/testsuite/artifact_dep.rs +++ b/tests/testsuite/artifact_dep.rs @@ -1900,7 +1900,7 @@ fn publish_artifact_dep() { .file("src/lib.rs", "") .build(); - p.cargo("publish -Z bindeps --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry -Z bindeps --no-verify --token sekrit") .masquerade_as_nightly_cargo(&["bindeps"]) .with_stderr( "\ diff --git a/tests/testsuite/bad_config.rs b/tests/testsuite/bad_config.rs index 06f9b449b263..235d1a52c8af 100644 --- a/tests/testsuite/bad_config.rs +++ b/tests/testsuite/bad_config.rs @@ -74,7 +74,7 @@ fn bad3() { .build(); Package::new("foo", "1.0.0").publish(); - p.cargo("publish -v") + p.cargo("publish --registry dummy-registry -v") .with_status(101) .with_stderr( "\ @@ -125,7 +125,7 @@ fn bad6() { .build(); Package::new("foo", "1.0.0").publish(); - p.cargo("publish -v") + p.cargo("publish --registry dummy-registry -v") .with_status(101) .with_stderr( "\ diff --git a/tests/testsuite/cargo_features.rs b/tests/testsuite/cargo_features.rs index be26d14ada72..730a0788446d 100644 --- a/tests/testsuite/cargo_features.rs +++ b/tests/testsuite/cargo_features.rs @@ -644,7 +644,7 @@ fn publish_allowed() { ) .file("src/lib.rs", "") .build(); - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .masquerade_as_nightly_cargo(&["test-dummy-unstable"]) .run(); } diff --git a/tests/testsuite/credential_process.rs b/tests/testsuite/credential_process.rs index 74f9a30ee764..3cf8530d84d5 100644 --- a/tests/testsuite/credential_process.rs +++ b/tests/testsuite/credential_process.rs @@ -31,7 +31,7 @@ fn gated() { .file("src/lib.rs", "") .build(); - p.cargo("publish --no-verify") + p.cargo("publish --registry dummy-registry --no-verify") .masquerade_as_nightly_cargo(&["credential-process"]) .with_status(101) .with_stderr( @@ -218,7 +218,7 @@ fn basic_unsupported() { ) .unwrap(); - cargo_process("login -Z credential-process abcdefg") + cargo_process("login -Z credential-process --registry dummy-registry abcdefg") .masquerade_as_nightly_cargo(&["credential-process"]) .with_status(101) .with_stderr( @@ -231,7 +231,7 @@ the credential-process configuration value must pass the \ ) .run(); - cargo_process("logout -Z credential-process") + cargo_process("logout -Z credential-process --registry dummy-registry") .masquerade_as_nightly_cargo(&["credential-process", "cargo-logout"]) .with_status(101) .with_stderr( @@ -259,7 +259,7 @@ fn login() { use std::io::Read; fn main() { - assert_eq!(std::env::var("CARGO_REGISTRY_NAME").unwrap(), "crates-io"); + assert_eq!(std::env::var("CARGO_REGISTRY_NAME").unwrap(), "dummy-registry"); assert_eq!(std::env::var("CARGO_REGISTRY_API_URL").unwrap(), "__API__"); assert_eq!(std::env::args().skip(1).next().unwrap(), "store"); let mut buffer = String::new(); @@ -286,12 +286,12 @@ fn login() { ) .unwrap(); - cargo_process("login -Z credential-process abcdefg") + cargo_process("login -Z credential-process --registry dummy-registry abcdefg") .masquerade_as_nightly_cargo(&["credential-process"]) .with_stderr( "\ [UPDATING] [..] -[LOGIN] token for `crates.io` saved +[LOGIN] token for `dummy-registry` saved ", ) .run(); @@ -316,7 +316,7 @@ fn logout() { use std::io::Read; fn main() { - assert_eq!(std::env::var("CARGO_REGISTRY_NAME").unwrap(), "crates-io"); + assert_eq!(std::env::var("CARGO_REGISTRY_NAME").unwrap(), "dummy-registry"); assert_eq!(std::env::args().skip(1).next().unwrap(), "erase"); std::fs::write("token-store", "").unwrap(); eprintln!("token for `{}` has been erased!", @@ -340,13 +340,13 @@ fn logout() { ) .unwrap(); - cargo_process("logout -Z credential-process") + cargo_process("logout -Z credential-process --registry dummy-registry") .masquerade_as_nightly_cargo(&["credential-process", "cargo-logout"]) .with_stderr( "\ [UPDATING] [..] -token for `crates-io` has been erased! -[LOGOUT] token for `crates.io` has been removed from local storage +token for `dummy-registry` has been erased! +[LOGOUT] token for `dummy-registry` has been removed from local storage ", ) .run(); @@ -401,7 +401,7 @@ fn libexec_path() { ) .unwrap(); - cargo_process("login -Z credential-process abcdefg") + cargo_process("login -Z credential-process --registry dummy-registry abcdefg") .masquerade_as_nightly_cargo(&["credential-process"]) .with_status(101) .with_stderr( @@ -410,7 +410,7 @@ fn libexec_path() { // error messages. &format!("\ [UPDATING] [..] -[ERROR] failed to execute `[..]libexec/cargo-credential-doesnotexist[EXE]` to store authentication token for registry `crates-io` +[ERROR] failed to execute `[..]libexec/cargo-credential-doesnotexist[EXE]` to store authentication token for registry `dummy-registry` Caused by: [..] diff --git a/tests/testsuite/cross_publish.rs b/tests/testsuite/cross_publish.rs index c2f08bc4091d..5fdecbb1006f 100644 --- a/tests/testsuite/cross_publish.rs +++ b/tests/testsuite/cross_publish.rs @@ -97,7 +97,7 @@ fn publish_with_target() { let target = cross_compile::alternate(); - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .arg("--target") .arg(&target) .with_stderr( diff --git a/tests/testsuite/features_namespaced.rs b/tests/testsuite/features_namespaced.rs index 0fe1c964bc18..1da739b006f0 100644 --- a/tests/testsuite/features_namespaced.rs +++ b/tests/testsuite/features_namespaced.rs @@ -884,7 +884,7 @@ fn publish_no_implicit() { .file("src/lib.rs", "") .build(); - p.cargo("publish --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") .with_stderr( "\ [UPDATING] [..] @@ -996,7 +996,7 @@ fn publish() { .file("src/lib.rs", "") .build(); - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .with_stderr( "\ [UPDATING] [..] diff --git a/tests/testsuite/inheritable_workspace_fields.rs b/tests/testsuite/inheritable_workspace_fields.rs index 9f136453665a..351a58c147d2 100644 --- a/tests/testsuite/inheritable_workspace_fields.rs +++ b/tests/testsuite/inheritable_workspace_fields.rs @@ -160,7 +160,8 @@ fn inherit_own_workspace_fields() { .file("bar.txt", "") // should be included when packaging .build(); - p.cargo("publish --token sekrit").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .run(); publish::validate_upload_with_contents( r#" { @@ -284,7 +285,8 @@ fn inherit_own_dependencies() { assert!(lockfile.contains("dep")); assert!(lockfile.contains("dep-dev")); assert!(lockfile.contains("dep-build")); - p.cargo("publish --token sekrit").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .run(); publish::validate_upload_with_contents( r#" { @@ -408,7 +410,8 @@ fn inherit_own_detailed_dependencies() { p.cargo("check").run(); let lockfile = p.read_lockfile(); assert!(lockfile.contains("dep")); - p.cargo("publish --token sekrit").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .run(); publish::validate_upload_with_contents( r#" { @@ -624,7 +627,9 @@ fn inherit_workspace_fields() { .file("bar/bar.txt", "") // should be included when packaging .build(); - p.cargo("publish --token sekrit").cwd("bar").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .cwd("bar") + .run(); publish::validate_upload_with_contents( r#" { @@ -755,7 +760,9 @@ fn inherit_dependencies() { assert!(lockfile.contains("dep")); assert!(lockfile.contains("dep-dev")); assert!(lockfile.contains("dep-build")); - p.cargo("publish --token sekrit").cwd("bar").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .cwd("bar") + .run(); publish::validate_upload_with_contents( r#" { diff --git a/tests/testsuite/logout.rs b/tests/testsuite/logout.rs index 4a6c3f3dcb5b..63ea9b1cf335 100644 --- a/tests/testsuite/logout.rs +++ b/tests/testsuite/logout.rs @@ -49,6 +49,7 @@ fn simple_logout_test(reg: Option<&str>, flag: &str) { check_config_token(reg, true); cargo_process(&format!("logout -Z unstable-options {}", flag)) .masquerade_as_nightly_cargo(&["cargo-logout"]) + .allow_silent_crates_io_replacement() .with_stderr(&format!( "\ [UPDATING] [..] @@ -61,6 +62,7 @@ fn simple_logout_test(reg: Option<&str>, flag: &str) { cargo_process(&format!("logout -Z unstable-options {}", flag)) .masquerade_as_nightly_cargo(&["cargo-logout"]) + .allow_silent_crates_io_replacement() .with_stderr(&format!( "\ [LOGOUT] not currently logged in to `{}` diff --git a/tests/testsuite/owner.rs b/tests/testsuite/owner.rs index 8c4bcbe17b15..9e6a784897b5 100644 --- a/tests/testsuite/owner.rs +++ b/tests/testsuite/owner.rs @@ -47,7 +47,7 @@ fn simple_list() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("owner -l --token sekrit") + p.cargo("owner --registry dummy-registry -l --token sekrit") .with_stdout( "\ github:rust-lang:core (Core) @@ -77,7 +77,7 @@ fn simple_add() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("owner -a username --token sekrit") + p.cargo("owner --registry dummy-registry -a username --token sekrit") .with_status(101) .with_stderr( " Updating `[..]` index @@ -109,7 +109,7 @@ fn simple_remove() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("owner -r username --token sekrit") + p.cargo("owner --registry dummy-registry -r username --token sekrit") .with_status(101) .with_stderr( " Updating `[..]` index diff --git a/tests/testsuite/publish.rs b/tests/testsuite/publish.rs index 77de699f6c77..719b9a92edc8 100644 --- a/tests/testsuite/publish.rs +++ b/tests/testsuite/publish.rs @@ -117,7 +117,7 @@ fn simple() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("publish --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") .with_stderr( "\ [UPDATING] `dummy-registry` index @@ -158,6 +158,7 @@ fn old_token_location() { // Verify can't publish without a token. p.cargo("publish --no-verify") + .allow_silent_crates_io_replacement() .with_status(101) .with_stderr_contains( "[ERROR] no upload token found, \ @@ -168,12 +169,10 @@ fn old_token_location() { fs::write(&credentials, r#"token = "api-token""#).unwrap(); p.cargo("publish --no-verify") + .allow_silent_crates_io_replacement() .with_stderr( "\ [UPDATING] `dummy-registry` index -[WARNING] using `registry.token` config value with source replacement is deprecated -This may become a hard error in the future[..] -Use the --token command-line flag to remove this warning. [WARNING] manifest has no documentation, [..] See [..] [PACKAGING] foo v0.0.1 ([CWD]) @@ -233,7 +232,7 @@ fn git_deps() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("publish -v --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry -v --no-verify --token sekrit") .with_status(101) .with_stderr( "\ @@ -271,7 +270,7 @@ fn path_dependency_no_version() { .file("bar/src/lib.rs", "") .build(); - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .with_status(101) .with_stderr( "\ @@ -340,7 +339,7 @@ fn dont_publish_dirty() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .with_status(101) .with_stderr( "\ @@ -380,7 +379,8 @@ fn publish_clean() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("publish --token sekrit").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .run(); validate_upload_foo_clean(); } @@ -409,7 +409,9 @@ fn publish_in_sub_repo() { .file("bar/src/main.rs", "fn main() {}") .build(); - p.cargo("publish --token sekrit").cwd("bar").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .cwd("bar") + .run(); validate_upload_foo_clean(); } @@ -439,7 +441,8 @@ fn publish_when_ignored() { .file(".gitignore", "baz") .build(); - p.cargo("publish --token sekrit").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .run(); publish::validate_upload( CLEAN_FOO_JSON, @@ -478,7 +481,9 @@ fn ignore_when_crate_ignored() { "#, ) .nocommit_file("bar/src/main.rs", "fn main() {}"); - p.cargo("publish --token sekrit").cwd("bar").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .cwd("bar") + .run(); publish::validate_upload( CLEAN_FOO_JSON, @@ -515,7 +520,7 @@ fn new_crate_rejected() { "#, ) .nocommit_file("src/main.rs", "fn main() {}"); - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .with_status(101) .with_stderr_contains( "[ERROR] 3 files in the working directory contain \ @@ -809,7 +814,9 @@ The registry `alternative` is not listed in the `publish` value in Cargo.toml. ) .run(); - p.cargo("publish").run(); + p.cargo("publish") + .allow_silent_crates_io_replacement() + .run(); } #[cargo_test] @@ -840,7 +847,7 @@ fn publish_with_select_features() { ) .build(); - p.cargo("publish --features required --token sekrit") + p.cargo("publish --registry dummy-registry --features required --token sekrit") .with_stderr_contains("[UPLOADING] foo v0.0.1 ([CWD])") .run(); } @@ -873,7 +880,7 @@ fn publish_with_all_features() { ) .build(); - p.cargo("publish --all-features --token sekrit") + p.cargo("publish --registry dummy-registry --all-features --token sekrit") .with_stderr_contains("[UPLOADING] foo v0.0.1 ([CWD])") .run(); } @@ -906,7 +913,7 @@ fn publish_with_no_default_features() { ) .build(); - p.cargo("publish --no-default-features --token sekrit") + p.cargo("publish --registry dummy-registry --no-default-features --token sekrit") .with_stderr_contains("error: This crate requires `required` feature!") .with_status(101) .run(); @@ -947,7 +954,7 @@ fn publish_with_patch() { p.cargo("build").run(); // Check that verify fails with patched crate which has new functionality. - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .with_stderr_contains("[..]newfunc[..]") .with_status(101) .run(); @@ -955,7 +962,8 @@ fn publish_with_patch() { // Remove the usage of new functionality and try again. p.change_file("src/main.rs", "extern crate bar; pub fn main() {}"); - p.cargo("publish --token sekrit").run(); + p.cargo("publish --registry dummy-registry --token sekrit") + .run(); // Note, use of `registry` in the deps here is an artifact that this // publishes to a fake, local registry that is pretending to be crates.io. @@ -1021,7 +1029,7 @@ fn publish_checks_for_token_before_verify() { fs::remove_file(&credentials).unwrap(); // Assert upload token error before the package is verified - p.cargo("publish") + p.cargo("publish --registry dummy-registry") .with_status(101) .with_stderr_contains( "[ERROR] no upload token found, \ @@ -1031,7 +1039,7 @@ fn publish_checks_for_token_before_verify() { .run(); // Assert package verified successfully on dry run - p.cargo("publish --dry-run") + p.cargo("publish --registry dummy-registry --dry-run") .with_status(0) .with_stderr_contains("[VERIFYING] foo v0.0.1 ([CWD])") .run(); @@ -1057,8 +1065,8 @@ fn publish_with_bad_source() { .with_status(101) .with_stderr( "\ -[ERROR] registry `[..]/foo/registry` does not support API commands. -Check for a source-replacement in .cargo/config. +[ERROR] crates-io is replaced with non-remote-registry source registry `[..]/foo/registry`; +include `--registry crates-io` to publish to crates.io ", ) .run(); @@ -1078,8 +1086,8 @@ Check for a source-replacement in .cargo/config. .with_status(101) .with_stderr( "\ -[ERROR] dir [..]/foo/vendor does not support API commands. -Check for a source-replacement in .cargo/config. +[ERROR] crates-io is replaced with non-remote-registry source dir [..]/foo/vendor; +include `--registry crates-io` to publish to crates.io ", ) .run(); @@ -1128,7 +1136,8 @@ fn publish_git_with_version() { .build(); p.cargo("run").with_stdout("2").run(); - p.cargo("publish --no-verify --token sekrit").run(); + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") + .run(); publish::validate_upload_with_contents( r#" @@ -1237,7 +1246,7 @@ fn publish_dev_dep_no_version() { .file("bar/src/lib.rs", "") .build(); - p.cargo("publish --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") .with_stderr( "\ [UPDATING] [..] @@ -1315,7 +1324,7 @@ fn credentials_ambiguous_filename() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("publish --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") .with_stderr_contains( "\ [WARNING] Both `[..]/credentials` and `[..]/credentials.toml` exist. Using `[..]/credentials` @@ -1362,8 +1371,8 @@ fn index_requires_token() { } #[cargo_test] -fn registry_token_with_source_replacement() { - // publish with source replacement without --token +fn cratesio_source_replacement() { + // publish with source replacement without --registry registry::init(); let p = project() @@ -1382,16 +1391,11 @@ fn registry_token_with_source_replacement() { .build(); p.cargo("publish --no-verify") + .with_status(101) .with_stderr( "\ -[UPDATING] [..] -[WARNING] using `registry.token` config value with source replacement is deprecated -This may become a hard error in the future[..] -Use the --token command-line flag to remove this warning. -[WARNING] manifest has no documentation, [..] -See [..] -[PACKAGING] foo v0.0.1 ([CWD]) -[UPLOADING] foo v0.0.1 ([CWD]) +[ERROR] crates-io is replaced with remote registry dummy-registry; +include `--registry dummy-registry` or `--registry crates-io` ", ) .run(); @@ -1417,7 +1421,7 @@ fn publish_with_missing_readme() { .file("src/lib.rs", "") .build(); - p.cargo("publish --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") .with_status(101) .with_stderr(&format!( "\ @@ -1713,7 +1717,7 @@ fn in_package_workspace() { .file("li/src/main.rs", "fn main() {}") .build(); - p.cargo("publish -p li --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry -p li --no-verify --token sekrit") .with_stderr( "\ [UPDATING] [..] @@ -1770,7 +1774,7 @@ fn with_duplicate_spec_in_members() { .file("bar/src/main.rs", "fn main() {}") .build(); - p.cargo("publish --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") .with_status(101) .with_stderr( "error: the `-p` argument must be specified to select a single package to publish", @@ -1807,7 +1811,7 @@ fn in_package_workspace_with_members_with_features_old() { .file("li/src/main.rs", "fn main() {}") .build(); - p.cargo("publish -p li --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry -p li --no-verify --token sekrit") .with_stderr( "\ [UPDATING] [..] @@ -1848,7 +1852,7 @@ fn in_virtual_workspace() { .file("foo/src/main.rs", "fn main() {}") .build(); - p.cargo("publish --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry --no-verify --token sekrit") .with_status(101) .with_stderr( "error: the `-p` argument must be specified in the root of a virtual workspace", @@ -1893,7 +1897,7 @@ fn in_virtual_workspace_with_p() { .file("li/src/main.rs", "fn main() {}") .build(); - p.cargo("publish -p li --no-verify --token sekrit") + p.cargo("publish --registry dummy-registry -p li --no-verify --token sekrit") .with_stderr( "\ [UPDATING] [..] @@ -1937,7 +1941,7 @@ fn in_package_workspace_not_found() { .file("li/src/main.rs", "fn main() {}") .build(); - p.cargo("publish -p li --no-verify --token sekrit ") + p.cargo("publish --registry dummy-registry -p li --no-verify --token sekrit ") .with_status(101) .with_stderr( "\ @@ -1994,7 +1998,7 @@ fn in_package_workspace_found_multiple() { .file("lii/src/main.rs", "fn main() {}") .build(); - p.cargo("publish -p li* --no-verify --token sekrit ") + p.cargo("publish --registry dummy-registry -p li* --no-verify --token sekrit ") .with_status(101) .with_stderr( "\ @@ -2037,7 +2041,7 @@ fn publish_path_dependency_without_workspace() { .file("bar/src/main.rs", "fn main() {}") .build(); - p.cargo("publish -p bar --no-verify --token sekrit ") + p.cargo("publish --registry dummy-registry -p bar --no-verify --token sekrit ") .with_status(101) .with_stderr( "\ diff --git a/tests/testsuite/registry.rs b/tests/testsuite/registry.rs index 7dbae00765f1..72dc3a608450 100644 --- a/tests/testsuite/registry.rs +++ b/tests/testsuite/registry.rs @@ -1076,9 +1076,12 @@ fn login_with_no_cargo_dir() { registry::init(); fs::rename(paths::home().join(".cargo"), paths::root().join(".cargo")).unwrap(); paths::home().rm_rf(); - cargo_process("login foo -v").run(); + cargo_process("login --registry dummy-registry foo -v").run(); let credentials = fs::read_to_string(paths::home().join(".cargo/credentials")).unwrap(); - assert_eq!(credentials, "[registry]\ntoken = \"foo\"\n"); + assert_eq!( + credentials, + "\n[registries.dummy-registry]\ntoken = \"foo\"\n" + ); } #[cargo_test] @@ -1087,11 +1090,14 @@ fn login_with_differently_sized_token() { registry::init(); let credentials = paths::home().join(".cargo/credentials"); fs::remove_file(&credentials).unwrap(); - cargo_process("login lmaolmaolmao -v").run(); - cargo_process("login lmao -v").run(); - cargo_process("login lmaolmaolmao -v").run(); + cargo_process("login --registry dummy-registry lmaolmaolmao -v").run(); + cargo_process("login --registry dummy-registry lmao -v").run(); + cargo_process("login --registry dummy-registry lmaolmaolmao -v").run(); let credentials = fs::read_to_string(&credentials).unwrap(); - assert_eq!(credentials, "[registry]\ntoken = \"lmaolmaolmao\"\n"); + assert_eq!( + credentials, + "\n[registries.dummy-registry]\ntoken = \"lmaolmaolmao\"\n" + ); } #[cargo_test] @@ -1099,13 +1105,16 @@ fn login_with_token_on_stdin() { registry::init(); let credentials = paths::home().join(".cargo/credentials"); fs::remove_file(&credentials).unwrap(); - cargo_process("login lmao -v").run(); - cargo_process("login") + cargo_process("login --registry dummy-registry lmao -v").run(); + cargo_process("login --registry dummy-registry") .with_stdout("please paste the API Token found on [..]/me below") .with_stdin("some token") .run(); let credentials = fs::read_to_string(&credentials).unwrap(); - assert_eq!(credentials, "[registry]\ntoken = \"some token\"\n"); + assert_eq!( + credentials, + "\n[registries.dummy-registry]\ntoken = \"some token\"\n" + ); } #[cargo_test] @@ -1136,7 +1145,7 @@ fn bad_license_file(cargo: fn(&Project, &str) -> Execs) { ) .file("src/main.rs", "fn main() {}") .build(); - cargo(&p, "publish -v --token sekrit") + cargo(&p, "publish --registry dummy-registry -v --token sekrit") .with_status(101) .with_stderr_contains("[ERROR] the license file `foo` does not exist") .run(); diff --git a/tests/testsuite/search.rs b/tests/testsuite/search.rs index 6f4845d01e68..a8ad5749a594 100644 --- a/tests/testsuite/search.rs +++ b/tests/testsuite/search.rs @@ -105,7 +105,7 @@ fn not_update() { regsrc.block_until_ready().unwrap(); drop(lock); - cargo_process("search postgres") + cargo_process("search --registry dummy-registry postgres") .with_stdout_contains(SEARCH_RESULTS) .with_stderr("") // without "Updating ... index" .run(); @@ -115,7 +115,7 @@ fn not_update() { fn replace_default() { let _server = setup().build(); - cargo_process("search postgres") + cargo_process("search --registry dummy-registry postgres") .with_stdout_contains(SEARCH_RESULTS) .with_stderr_contains("[..]Updating [..] index") .run(); @@ -145,7 +145,7 @@ fn multiple_query_params() { fn ignore_quiet() { let _server = setup().build(); - cargo_process("search -q postgres") + cargo_process("search --registry dummy-registry -q postgres") .with_stdout_contains(SEARCH_RESULTS) .run(); } @@ -154,11 +154,11 @@ fn ignore_quiet() { fn colored_results() { let _server = setup().build(); - cargo_process("search --color=never postgres") + cargo_process("search --registry dummy-registry --color=never postgres") .with_stdout_does_not_contain("[..]\x1b[[..]") .run(); - cargo_process("search --color=always postgres") + cargo_process("search --registry dummy-registry --color=always postgres") .with_stdout_contains("[..]\x1b[[..]") .run(); } diff --git a/tests/testsuite/weak_dep_features.rs b/tests/testsuite/weak_dep_features.rs index 07d864700819..ac2fe38c12fe 100644 --- a/tests/testsuite/weak_dep_features.rs +++ b/tests/testsuite/weak_dep_features.rs @@ -547,7 +547,7 @@ fn publish() { .file("src/lib.rs", "") .build(); - p.cargo("publish --token sekrit") + p.cargo("publish --registry dummy-registry --token sekrit") .with_stderr( "\ [UPDATING] [..] diff --git a/tests/testsuite/yank.rs b/tests/testsuite/yank.rs index 3447aac28853..16a0764e87e0 100644 --- a/tests/testsuite/yank.rs +++ b/tests/testsuite/yank.rs @@ -32,9 +32,10 @@ fn explicit_version() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("yank --version 0.0.1 --token sekrit").run(); + p.cargo("yank --registry dummy-registry --version 0.0.1 --token sekrit") + .run(); - p.cargo("yank --undo --version 0.0.1 --token sekrit") + p.cargo("yank --registry dummy-registry --undo --version 0.0.1 --token sekrit") .with_status(101) .with_stderr( " Updating `[..]` index @@ -67,9 +68,10 @@ fn inline_version() { .file("src/main.rs", "fn main() {}") .build(); - p.cargo("yank foo@0.0.1 --token sekrit").run(); + p.cargo("yank --registry dummy-registry foo@0.0.1 --token sekrit") + .run(); - p.cargo("yank --undo foo@0.0.1 --token sekrit") + p.cargo("yank --registry dummy-registry --undo foo@0.0.1 --token sekrit") .with_status(101) .with_stderr( " Updating `[..]` index