-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Update to semver 1.0.0 #9508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to semver 1.0.0 #9508
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,5 @@ | ||
| use anyhow::Context as _; | ||
| use cargo_platform::Platform; | ||
| use log::trace; | ||
| use semver::ReqParseError; | ||
| use semver::VersionReq; | ||
| use serde::ser; | ||
| use serde::Serialize; | ||
|
|
@@ -11,17 +9,17 @@ use std::rc::Rc; | |
| use crate::core::{PackageId, SourceId, Summary}; | ||
| use crate::util::errors::CargoResult; | ||
| use crate::util::interning::InternedString; | ||
| use crate::util::Config; | ||
| use crate::util::{Config, OptVersionReq}; | ||
|
|
||
| /// Information about a dependency requested by a Cargo manifest. | ||
| /// Cheap to copy. | ||
| #[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug)] | ||
| #[derive(PartialEq, Eq, Hash, Clone, Debug)] | ||
| pub struct Dependency { | ||
| inner: Rc<Inner>, | ||
| } | ||
|
|
||
| /// The data underlying a `Dependency`. | ||
| #[derive(PartialEq, Eq, Hash, Ord, PartialOrd, Clone, Debug)] | ||
| #[derive(PartialEq, Eq, Hash, Clone, Debug)] | ||
| struct Inner { | ||
| name: InternedString, | ||
| source_id: SourceId, | ||
|
|
@@ -32,7 +30,7 @@ struct Inner { | |
| /// `registry` is specified. Or in the case of a crates.io dependency, | ||
| /// `source_id` will be crates.io and this will be None. | ||
| registry_id: Option<SourceId>, | ||
| req: VersionReq, | ||
| req: OptVersionReq, | ||
| specified_req: bool, | ||
| kind: DepKind, | ||
| only_match_name: bool, | ||
|
|
@@ -104,14 +102,32 @@ fn parse_req_with_deprecated( | |
| req: &str, | ||
| extra: Option<(PackageId, &Config)>, | ||
| ) -> CargoResult<VersionReq> { | ||
| match VersionReq::parse(req) { | ||
| Err(ReqParseError::DeprecatedVersionRequirement(requirement)) => { | ||
| let (inside, config) = match extra { | ||
| Some(pair) => pair, | ||
| None => return Err(ReqParseError::DeprecatedVersionRequirement(requirement).into()), | ||
| }; | ||
| let msg = format!( | ||
| "\ | ||
| let err = match VersionReq::parse(req) { | ||
| Ok(req) => return Ok(req), | ||
| Err(err) => err, | ||
| }; | ||
|
|
||
| let (inside, config) = match extra { | ||
| Some(pair) => pair, | ||
| None => return Err(err.into()), | ||
| }; | ||
|
|
||
| let corrected = match req { | ||
| ".*" => "*", | ||
| "0.1.0." => "0.1.0", | ||
| "0.3.1.3" => "0.3.13", | ||
| "0.2*" => "0.2.*", | ||
| "*.0" => "*", | ||
| _ => { | ||
| return Err(anyhow::Error::new(err).context(format!( | ||
| "failed to parse the version requirement `{}` for dependency `{}`", | ||
| req, name, | ||
| ))); | ||
| } | ||
| }; | ||
|
|
||
| let msg = format!( | ||
| "\ | ||
| parsed version requirement `{}` is no longer valid | ||
|
|
||
| Previous versions of Cargo accepted this malformed requirement, | ||
|
|
@@ -122,27 +138,15 @@ This will soon become a hard error, so it's either recommended to | |
| update to a fixed version or contact the upstream maintainer about | ||
| this warning. | ||
| ", | ||
| req, | ||
| inside.name(), | ||
| inside.version(), | ||
| requirement | ||
| ); | ||
| config.shell().warn(&msg)?; | ||
|
|
||
| Ok(requirement) | ||
| } | ||
| Err(e) => { | ||
| let err: CargoResult<VersionReq> = Err(e.into()); | ||
| let v: VersionReq = err.with_context(|| { | ||
| format!( | ||
| "failed to parse the version requirement `{}` for dependency `{}`", | ||
| req, name | ||
| ) | ||
| })?; | ||
| Ok(v) | ||
| } | ||
| Ok(v) => Ok(v), | ||
| } | ||
| req, | ||
| inside.name(), | ||
| inside.version(), | ||
| corrected, | ||
| ); | ||
|
|
||
| config.shell().warn(&msg)?; | ||
|
|
||
| Ok(VersionReq::parse(corrected).unwrap()) | ||
| } | ||
|
|
||
| impl ser::Serialize for DepKind { | ||
|
|
@@ -171,8 +175,8 @@ impl Dependency { | |
| let name = name.into(); | ||
| let arg = Some((inside, config)); | ||
| let (specified_req, version_req) = match version { | ||
| Some(v) => (true, parse_req_with_deprecated(name, v, arg)?), | ||
| None => (false, VersionReq::any()), | ||
| Some(v) => (true, parse_req_with_deprecated(name, v, arg)?.into()), | ||
| None => (false, OptVersionReq::Any), | ||
|
||
| }; | ||
|
|
||
| let mut ret = Dependency::new_override(name, source_id); | ||
|
|
@@ -193,8 +197,8 @@ impl Dependency { | |
| ) -> CargoResult<Dependency> { | ||
| let name = name.into(); | ||
| let (specified_req, version_req) = match version { | ||
| Some(v) => (true, parse_req_with_deprecated(name, v, None)?), | ||
| None => (false, VersionReq::any()), | ||
| Some(v) => (true, parse_req_with_deprecated(name, v, None)?.into()), | ||
| None => (false, OptVersionReq::Any), | ||
| }; | ||
|
|
||
| let mut ret = Dependency::new_override(name, source_id); | ||
|
|
@@ -214,7 +218,7 @@ impl Dependency { | |
| name, | ||
| source_id, | ||
| registry_id: None, | ||
| req: VersionReq::any(), | ||
| req: OptVersionReq::Any, | ||
| kind: DepKind::Normal, | ||
| only_match_name: true, | ||
| optional: false, | ||
|
|
@@ -228,7 +232,7 @@ impl Dependency { | |
| } | ||
| } | ||
|
|
||
| pub fn version_req(&self) -> &VersionReq { | ||
| pub fn version_req(&self) -> &OptVersionReq { | ||
| &self.inner.req | ||
| } | ||
|
|
||
|
|
@@ -365,7 +369,7 @@ impl Dependency { | |
|
|
||
| /// Sets the version requirement for this dependency. | ||
| pub fn set_version_req(&mut self, req: VersionReq) -> &mut Dependency { | ||
| Rc::make_mut(&mut self.inner).req = req; | ||
| Rc::make_mut(&mut self.inner).req = OptVersionReq::Req(req); | ||
| self | ||
| } | ||
|
|
||
|
|
@@ -394,7 +398,7 @@ impl Dependency { | |
| id | ||
| ); | ||
| let me = Rc::make_mut(&mut self.inner); | ||
| me.req = VersionReq::exact(id.version()); | ||
| me.req = OptVersionReq::exact(id.version()); | ||
|
|
||
| // Only update the `precise` of this source to preserve other | ||
| // information about dependency's source which may not otherwise be | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are copied from dtolnay/semver#93.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for keeping the compat here! That being said the warning below says that it will soon become a hard error, and that was added 5 years ago in #3154. I think it's probably fine to just delete all this at this point (and I'm glad you moved this logic to Cargo from the
semvercrate itself!)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call 😛 I've deleted the compatibility code in 396bdd3.