Reuse crate-io constant

This commit is contained in:
Weihang Lo 2021-06-26 21:35:07 +08:00
parent 4e143fd131
commit 9244a42d52
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
8 changed files with 19 additions and 13 deletions

View File

@ -11,6 +11,8 @@ use std::fmt;
use std::hash;
use url::Url;
const DOCS_RS_URL: &'static str = "https://docs.rs/";
/// Mode used for `std`.
#[derive(Debug, Hash)]
pub enum RustdocExternMode {
@ -63,7 +65,7 @@ pub struct RustdocExternMap {
impl Default for RustdocExternMap {
fn default() -> Self {
let mut registries = HashMap::new();
registries.insert("crates-io".into(), "https://docs.rs/".into());
registries.insert(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into());
Self {
registries,
std: None,
@ -76,8 +78,8 @@ fn default_crates_io_to_docs_rs<'de, D: serde::Deserializer<'de>>(
) -> Result<HashMap<String, String>, D::Error> {
use serde::Deserialize;
let mut registries = HashMap::deserialize(de)?;
if !registries.contains_key("crates-io") {
registries.insert("crates-io".into(), "https://docs.rs/".into());
if !registries.contains_key(CRATES_IO_REGISTRY) {
registries.insert(CRATES_IO_REGISTRY.into(), DOCS_RS_URL.into());
}
Ok(registries)
}

View File

@ -1,6 +1,6 @@
use crate::core::PackageId;
use crate::sources::DirectorySource;
use crate::sources::{GitSource, PathSource, RegistrySource, CRATES_IO_INDEX};
use crate::sources::{DirectorySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX};
use crate::sources::{GitSource, PathSource, RegistrySource};
use crate::util::{CanonicalUrl, CargoResult, Config, IntoUrl};
use log::trace;
use serde::de;
@ -224,7 +224,7 @@ impl SourceId {
pub fn display_registry_name(self) -> String {
if self.is_default_registry() {
"crates.io".to_string()
CRATES_IO_DOMAIN.to_string()
} else if let Some(name) = &self.inner.name {
name.clone()
} else {

View File

@ -1,3 +1,5 @@
use crate::sources::CRATES_IO_DOMAIN;
pub use self::cargo_clean::{clean, CleanOptions};
pub use self::cargo_compile::{
compile, compile_with_exec, compile_ws, create_bcx, print, resolve_all_features, CompileOptions,
@ -66,7 +68,7 @@ fn check_dep_has_version(dep: &crate::core::Dependency, publish: bool) -> crate:
if !dep.specified_req() && dep.is_transitive() {
let dep_version_source = dep.registry_id().map_or_else(
|| "crates.io".to_string(),
|| CRATES_IO_DOMAIN.to_string(),
|registry_id| registry_id.display_registry_name(),
);
anyhow::bail!(

View File

@ -20,7 +20,7 @@ use crate::core::resolver::CliFeatures;
use crate::core::source::Source;
use crate::core::{Package, SourceId, Workspace};
use crate::ops;
use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_REGISTRY};
use crate::sources::{RegistrySource, SourceConfigMap, CRATES_IO_DOMAIN, CRATES_IO_REGISTRY};
use crate::util::config::{self, Config, SslVersionConfig, SslVersionConfigRange};
use crate::util::errors::CargoResult;
use crate::util::important_paths::find_root_manifest_for_wd;
@ -730,7 +730,7 @@ pub fn registry_login(
"Login",
format!(
"token for `{}` saved",
reg.as_ref().map_or("crates.io", String::as_str)
reg.as_ref().map_or(CRATES_IO_DOMAIN, String::as_str)
),
)?;
Ok(())
@ -738,7 +738,7 @@ pub fn registry_login(
pub fn registry_logout(config: &Config, reg: Option<String>) -> CargoResult<()> {
let (registry, reg_cfg, _) = registry(config, None, None, reg.clone(), false, false)?;
let reg_name = reg.as_deref().unwrap_or("crates.io");
let reg_name = reg.as_deref().unwrap_or(CRATES_IO_DOMAIN);
if reg_cfg.credential_process.is_none() && reg_cfg.token.is_none() {
config.shell().status(
"Logout",

View File

@ -2,6 +2,7 @@ use crate::core::shell::Verbosity;
use crate::core::{GitReference, Workspace};
use crate::ops;
use crate::sources::path::PathSource;
use crate::sources::CRATES_IO_REGISTRY;
use crate::util::{CargoResult, Config};
use anyhow::{bail, Context as _};
use cargo_util::{paths, Sha256};
@ -248,7 +249,7 @@ fn sync(
// replace original sources with vendor
for source_id in sources {
let name = if source_id.is_default_registry() {
"crates-io".to_string()
CRATES_IO_REGISTRY.to_string()
} else {
source_id.url().to_string()
};

View File

@ -247,7 +247,7 @@ restore the source replacement configuration to continue the build
check_not_set("tag", def.tag)?;
check_not_set("rev", def.rev)?;
}
if name == "crates-io" && srcs.is_empty() {
if name == CRATES_IO_REGISTRY && srcs.is_empty() {
srcs.push(SourceId::crates_io(self.config)?);
}

View File

@ -2,7 +2,7 @@ pub use self::config::SourceConfigMap;
pub use self::directory::DirectorySource;
pub use self::git::GitSource;
pub use self::path::PathSource;
pub use self::registry::{RegistrySource, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
pub use self::registry::{RegistrySource, CRATES_IO_DOMAIN, CRATES_IO_INDEX, CRATES_IO_REGISTRY};
pub use self::replaced::ReplacedSource;
pub mod config;

View File

@ -184,6 +184,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_REGISTRY: &str = "crates-io";
pub const CRATES_IO_DOMAIN: &str = "crates.io";
const CRATE_TEMPLATE: &str = "{crate}";
const VERSION_TEMPLATE: &str = "{version}";
const PREFIX_TEMPLATE: &str = "{prefix}";