mirror of
https://github.com/rust-lang/cargo
synced 2024-08-28 11:50:23 +00:00
Auto merge of #10725 - arlosi:http-cratesio, r=Eh2406
Make -Z http-registry use index.crates.io when accessing crates-io Use `sparse+https://index.crates.io/` to access crates.io when `-Z http-registry` is set. * `Cargo.lock` files still emit the github URL `https://github.com/rust-lang/crates.io-index`. * Allows publishing to a source-replaced `crates-io` only for `index.crates.io`. Other source-replacements of `crates-io` are still blocked. Fixes #10722 r? `@Eh2406`
This commit is contained in:
commit
85e457e158
|
@ -1,4 +1,5 @@
|
|||
use crate::core::PackageId;
|
||||
use crate::sources::registry::CRATES_IO_HTTP_INDEX;
|
||||
use crate::sources::{DirectorySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
|
||||
use crate::sources::{GitSource, PathSource, RegistrySource};
|
||||
use crate::util::{CanonicalUrl, CargoResult, Config, IntoUrl};
|
||||
|
@ -206,6 +207,18 @@ impl SourceId {
|
|||
})
|
||||
}
|
||||
|
||||
/// Returns the `SourceId` corresponding to the main repository, using the
|
||||
/// http index if allowed.
|
||||
pub fn crates_io_maybe_http(config: &Config) -> CargoResult<SourceId> {
|
||||
if config.cli_unstable().http_registry {
|
||||
config.check_registry_index_not_set()?;
|
||||
let url = CRATES_IO_HTTP_INDEX.into_url().unwrap();
|
||||
SourceId::new(SourceKind::Registry, url, Some(CRATES_IO_REGISTRY))
|
||||
} else {
|
||||
Self::crates_io(config)
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the `SourceId` associated with given name of the remote registry.
|
||||
pub fn alt_registry(config: &Config, key: &str) -> CargoResult<SourceId> {
|
||||
let url = config.get_registry_index(key)?;
|
||||
|
@ -356,7 +369,8 @@ impl SourceId {
|
|||
SourceKind::Registry => {}
|
||||
_ => return false,
|
||||
}
|
||||
self.inner.url.as_str() == CRATES_IO_INDEX
|
||||
let url = self.inner.url.as_str();
|
||||
url == CRATES_IO_INDEX || url == CRATES_IO_HTTP_INDEX
|
||||
}
|
||||
|
||||
/// Hashes `self`.
|
||||
|
|
|
@ -196,6 +196,10 @@ fn verify_dependencies(
|
|||
if super::check_dep_has_version(dep, true)? {
|
||||
continue;
|
||||
}
|
||||
// Allow publishing to crates.io with index.crates.io as a source replacement.
|
||||
if registry_src.is_default_registry() && dep.source_id().is_default_registry() {
|
||||
continue;
|
||||
}
|
||||
// TomlManifest::prepare_for_publish will rewrite the dependency
|
||||
// to be just the `version` field.
|
||||
if dep.source_id() != registry_src {
|
||||
|
|
|
@ -91,6 +91,15 @@ impl<'cfg> SourceConfigMap<'cfg> {
|
|||
replace_with: None,
|
||||
},
|
||||
)?;
|
||||
if config.cli_unstable().http_registry {
|
||||
base.add(
|
||||
CRATES_IO_REGISTRY,
|
||||
SourceConfig {
|
||||
id: SourceId::crates_io_maybe_http(config)?,
|
||||
replace_with: None,
|
||||
},
|
||||
)?;
|
||||
}
|
||||
Ok(base)
|
||||
}
|
||||
|
||||
|
@ -248,7 +257,7 @@ restore the source replacement configuration to continue the build
|
|||
check_not_set("rev", def.rev)?;
|
||||
}
|
||||
if name == CRATES_IO_REGISTRY && srcs.is_empty() {
|
||||
srcs.push(SourceId::crates_io(self.config)?);
|
||||
srcs.push(SourceId::crates_io_maybe_http(self.config)?);
|
||||
}
|
||||
|
||||
match srcs.len() {
|
||||
|
|
|
@ -186,6 +186,7 @@ use crate::util::{restricted_names, CargoResult, Config, Filesystem, OptVersionR
|
|||
|
||||
const PACKAGE_SOURCE_LOCK: &str = ".cargo-ok";
|
||||
pub const CRATES_IO_INDEX: &str = "https://github.com/rust-lang/crates.io-index";
|
||||
pub const CRATES_IO_HTTP_INDEX: &str = "sparse+https://index.crates.io/";
|
||||
pub const CRATES_IO_REGISTRY: &str = "crates-io";
|
||||
pub const CRATES_IO_DOMAIN: &str = "crates.io";
|
||||
const CRATE_TEMPLATE: &str = "{crate}";
|
||||
|
|
Loading…
Reference in a new issue