mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
fix(pkgid): drop cargo:// support
This commit is contained in:
parent
1ee261e475
commit
1bbc0569b9
@ -51,23 +51,21 @@ impl PackageIdSpec {
|
||||
/// assert!(PackageIdSpec::parse(spec).is_ok());
|
||||
/// }
|
||||
pub fn parse(spec: &str) -> CargoResult<PackageIdSpec> {
|
||||
if spec.contains('/') {
|
||||
if spec.contains("://") {
|
||||
if let Ok(url) = spec.into_url() {
|
||||
return PackageIdSpec::from_url(url);
|
||||
}
|
||||
if !spec.contains("://") {
|
||||
if spec.starts_with('/') {
|
||||
// This is out of current pkgid spec.
|
||||
// Only for fixing rust-lang/cargo#9041
|
||||
bail!(
|
||||
"pkgid urls with local paths must be prefixed \
|
||||
with a `file://` scheme: {}",
|
||||
spec
|
||||
)
|
||||
}
|
||||
if let Ok(url) = Url::parse(&format!("cargo://{}", spec)) {
|
||||
return PackageIdSpec::from_url(url);
|
||||
}
|
||||
} else if spec.contains('/') || spec.contains('\\') {
|
||||
let abs = std::env::current_dir().unwrap_or_default().join(spec);
|
||||
if abs.exists() {
|
||||
let maybe_url = Url::from_file_path(abs)
|
||||
.map_or_else(|_| "a file:// URL".to_string(), |url| url.to_string());
|
||||
bail!(
|
||||
"package ID specification `{}` looks like a file path, \
|
||||
maybe try {}",
|
||||
spec,
|
||||
maybe_url
|
||||
);
|
||||
}
|
||||
}
|
||||
let mut parts = spec.splitn(2, ':');
|
||||
@ -284,11 +282,7 @@ impl fmt::Display for PackageIdSpec {
|
||||
let mut printed_name = false;
|
||||
match self.url {
|
||||
Some(ref url) => {
|
||||
if url.scheme() == "cargo" {
|
||||
write!(f, "{}{}", url.host().unwrap(), url.path())?;
|
||||
} else {
|
||||
write!(f, "{}", url)?;
|
||||
}
|
||||
write!(f, "{}", url)?;
|
||||
if url.path_segments().unwrap().next_back().unwrap() != &*self.name {
|
||||
printed_name = true;
|
||||
write!(f, "#{}", self.name)?;
|
||||
@ -341,6 +335,14 @@ mod tests {
|
||||
assert_eq!(parsed.to_string(), spec);
|
||||
}
|
||||
|
||||
ok(
|
||||
"https://crates.io/foo",
|
||||
PackageIdSpec {
|
||||
name: InternedString::new("foo"),
|
||||
version: None,
|
||||
url: Some(Url::parse("https://crates.io/foo").unwrap()),
|
||||
},
|
||||
);
|
||||
ok(
|
||||
"https://crates.io/foo#1.2.3",
|
||||
PackageIdSpec {
|
||||
@ -357,38 +359,6 @@ mod tests {
|
||||
url: Some(Url::parse("https://crates.io/foo").unwrap()),
|
||||
},
|
||||
);
|
||||
ok(
|
||||
"crates.io/foo",
|
||||
PackageIdSpec {
|
||||
name: InternedString::new("foo"),
|
||||
version: None,
|
||||
url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
|
||||
},
|
||||
);
|
||||
ok(
|
||||
"crates.io/foo#1.2.3",
|
||||
PackageIdSpec {
|
||||
name: InternedString::new("foo"),
|
||||
version: Some("1.2.3".to_semver().unwrap()),
|
||||
url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
|
||||
},
|
||||
);
|
||||
ok(
|
||||
"crates.io/foo#bar",
|
||||
PackageIdSpec {
|
||||
name: InternedString::new("bar"),
|
||||
version: None,
|
||||
url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
|
||||
},
|
||||
);
|
||||
ok(
|
||||
"crates.io/foo#bar:1.2.3",
|
||||
PackageIdSpec {
|
||||
name: InternedString::new("bar"),
|
||||
version: Some("1.2.3".to_semver().unwrap()),
|
||||
url: Some(Url::parse("cargo://crates.io/foo").unwrap()),
|
||||
},
|
||||
);
|
||||
ok(
|
||||
"foo",
|
||||
PackageIdSpec {
|
||||
@ -414,7 +384,6 @@ mod tests {
|
||||
assert!(PackageIdSpec::parse("baz:1.0").is_err());
|
||||
assert!(PackageIdSpec::parse("https://baz:1.0").is_err());
|
||||
assert!(PackageIdSpec::parse("https://#baz:1.0").is_err());
|
||||
assert!(PackageIdSpec::parse("/baz").is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user