mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
refactor: move out into_resolve from EncodableResolve
This commit is contained in:
parent
97333185f6
commit
598cfab7e9
@ -144,20 +144,23 @@ struct Patch {
|
|||||||
|
|
||||||
pub type Metadata = BTreeMap<String, String>;
|
pub type Metadata = BTreeMap<String, String>;
|
||||||
|
|
||||||
impl EncodableResolve {
|
/// Convert a `Cargo.lock` to a Resolve.
|
||||||
/// Convert a `Cargo.lock` to a Resolve.
|
///
|
||||||
///
|
/// Note that this `Resolve` is not "complete". For example, the
|
||||||
/// Note that this `Resolve` is not "complete". For example, the
|
/// dependencies do not know the difference between regular/dev/build
|
||||||
/// dependencies do not know the difference between regular/dev/build
|
/// dependencies, so they are not filled in. It also does not include
|
||||||
/// dependencies, so they are not filled in. It also does not include
|
/// `features`. Care should be taken when using this Resolve. One of the
|
||||||
/// `features`. Care should be taken when using this Resolve. One of the
|
/// primary uses is to be used with `resolve_with_previous` to guide the
|
||||||
/// primary uses is to be used with `resolve_with_previous` to guide the
|
/// resolver to create a complete Resolve.
|
||||||
/// resolver to create a complete Resolve.
|
pub fn into_resolve(
|
||||||
pub fn into_resolve(self, original: &str, ws: &Workspace<'_>) -> CargoResult<Resolve> {
|
resolve: EncodableResolve,
|
||||||
|
original: &str,
|
||||||
|
ws: &Workspace<'_>,
|
||||||
|
) -> CargoResult<Resolve> {
|
||||||
let path_deps: HashMap<String, HashMap<semver::Version, SourceId>> = build_path_deps(ws)?;
|
let path_deps: HashMap<String, HashMap<semver::Version, SourceId>> = build_path_deps(ws)?;
|
||||||
let mut checksums = HashMap::new();
|
let mut checksums = HashMap::new();
|
||||||
|
|
||||||
let mut version = match self.version {
|
let mut version = match resolve.version {
|
||||||
Some(n @ 5) if ws.gctx().nightly_features_allowed => {
|
Some(n @ 5) if ws.gctx().nightly_features_allowed => {
|
||||||
if ws.gctx().cli_unstable().next_lockfile_bump {
|
if ws.gctx().cli_unstable().next_lockfile_bump {
|
||||||
ResolveVersion::V5
|
ResolveVersion::V5
|
||||||
@ -180,8 +183,8 @@ impl EncodableResolve {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let packages = {
|
let packages = {
|
||||||
let mut packages = self.package.unwrap_or_default();
|
let mut packages = resolve.package.unwrap_or_default();
|
||||||
if let Some(root) = self.root {
|
if let Some(root) = resolve.root {
|
||||||
packages.insert(0, root);
|
packages.insert(0, root);
|
||||||
}
|
}
|
||||||
packages
|
packages
|
||||||
@ -332,7 +335,7 @@ impl EncodableResolve {
|
|||||||
replacements
|
replacements
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut metadata = self.metadata.unwrap_or_default();
|
let mut metadata = resolve.metadata.unwrap_or_default();
|
||||||
|
|
||||||
// In the V1 serialization formats all checksums were listed in the lock
|
// In the V1 serialization formats all checksums were listed in the lock
|
||||||
// file in the `[metadata]` section, so if we're still V1 then look for
|
// file in the `[metadata]` section, so if we're still V1 then look for
|
||||||
@ -367,7 +370,7 @@ impl EncodableResolve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let mut unused_patches = Vec::new();
|
let mut unused_patches = Vec::new();
|
||||||
for pkg in self.patch.unused {
|
for pkg in resolve.patch.unused {
|
||||||
let id = match pkg
|
let id = match pkg
|
||||||
.source
|
.source
|
||||||
.as_deref()
|
.as_deref()
|
||||||
@ -435,7 +438,6 @@ impl EncodableResolve {
|
|||||||
None
|
None
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_path_deps(
|
fn build_path_deps(
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
|
|
||||||
|
use crate::core::resolver::encode::into_resolve;
|
||||||
use crate::core::{Resolve, ResolveVersion, Workspace, resolver};
|
use crate::core::{Resolve, ResolveVersion, Workspace, resolver};
|
||||||
use crate::util::Filesystem;
|
use crate::util::Filesystem;
|
||||||
use crate::util::errors::CargoResult;
|
use crate::util::errors::CargoResult;
|
||||||
@ -23,7 +24,7 @@ pub fn load_pkg_lockfile(ws: &Workspace<'_>) -> CargoResult<Option<Resolve>> {
|
|||||||
|
|
||||||
let resolve = (|| -> CargoResult<Option<Resolve>> {
|
let resolve = (|| -> CargoResult<Option<Resolve>> {
|
||||||
let v: resolver::EncodableResolve = toml::from_str(&s)?;
|
let v: resolver::EncodableResolve = toml::from_str(&s)?;
|
||||||
Ok(Some(v.into_resolve(&s, ws)?))
|
Ok(Some(into_resolve(v, &s, ws)?))
|
||||||
})()
|
})()
|
||||||
.with_context(|| format!("failed to parse lock file at: {}", f.path().display()))?;
|
.with_context(|| format!("failed to parse lock file at: {}", f.path().display()))?;
|
||||||
Ok(resolve)
|
Ok(resolve)
|
||||||
@ -208,7 +209,7 @@ fn are_equal_lockfiles(orig: &str, current: &str, ws: &Workspace<'_>) -> bool {
|
|||||||
let res: CargoResult<bool> = (|| {
|
let res: CargoResult<bool> = (|| {
|
||||||
let old: resolver::EncodableResolve = toml::from_str(orig)?;
|
let old: resolver::EncodableResolve = toml::from_str(orig)?;
|
||||||
let new: resolver::EncodableResolve = toml::from_str(current)?;
|
let new: resolver::EncodableResolve = toml::from_str(current)?;
|
||||||
Ok(old.into_resolve(orig, ws)? == new.into_resolve(current, ws)?)
|
Ok(into_resolve(old, orig, ws)? == into_resolve(new, current, ws)?)
|
||||||
})();
|
})();
|
||||||
if let Ok(true) = res {
|
if let Ok(true) = res {
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user