From 5ef7b7ce7dfa191b31f6d4b2240eec1bbca47f8a Mon Sep 17 00:00:00 2001 From: Weihang Lo Date: Wed, 18 Oct 2023 18:27:12 -0400 Subject: [PATCH] feat: stabilize lockfile v4 --- src/cargo/core/resolver/encode.rs | 14 +++----- src/cargo/core/resolver/resolve.rs | 8 ++--- src/cargo/ops/lockfile.rs | 2 +- tests/testsuite/lockfile_compat.rs | 57 ++---------------------------- 4 files changed, 11 insertions(+), 70 deletions(-) diff --git a/src/cargo/core/resolver/encode.rs b/src/cargo/core/resolver/encode.rs index 7835c22197cb..0581173cf268 100644 --- a/src/cargo/core/resolver/encode.rs +++ b/src/cargo/core/resolver/encode.rs @@ -154,18 +154,11 @@ impl EncodableResolve { /// primary uses is to be used with `resolve_with_previous` to guide the /// resolver to create a complete Resolve. pub fn into_resolve(self, original: &str, ws: &Workspace<'_>) -> CargoResult { - let unstable_lockfile_version_allowed = ws.config().cli_unstable().next_lockfile_bump; let path_deps = build_path_deps(ws)?; let mut checksums = HashMap::new(); let mut version = match self.version { - Some(4) if ws.config().nightly_features_allowed => { - if unstable_lockfile_version_allowed { - ResolveVersion::V4 - } else { - anyhow::bail!("lock file version 4 requires `-Znext-lockfile-bump`"); - } - } + Some(4) => ResolveVersion::V4, Some(3) => ResolveVersion::V3, Some(n) => bail!( "lock file version `{}` was found, but this version of Cargo \ @@ -797,9 +790,10 @@ fn encodable_source_id(id: SourceId, version: ResolveVersion) -> Option EncodableSourceId::new(id), - _ => EncodableSourceId::without_url_encoded(id), + V4 => EncodableSourceId::new(id), + V1 | V2 | V3 => EncodableSourceId::without_url_encoded(id), }) } } diff --git a/src/cargo/core/resolver/resolve.rs b/src/cargo/core/resolver/resolve.rs index 18a389773da9..1e1bdbcc0c80 100644 --- a/src/cargo/core/resolver/resolve.rs +++ b/src/cargo/core/resolver/resolve.rs @@ -80,11 +80,9 @@ pub enum ResolveVersion { /// V3 by default staring in 1.53. #[default] V3, - /// Unstable. Will collect a certain amount of changes and then go. - /// - /// Changes made: - /// - /// * SourceId URL serialization is aware of URL encoding. + /// SourceId URL serialization is aware of URL encoding. For example, + /// `?branch=foo bar` is now encoded as `?branch=foo+bar` and can be decoded + /// back and forth correctly. Introduced in 2023 in version 1.75. V4, } diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index aa05efd3559f..9663c48e251f 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -67,7 +67,7 @@ pub fn write_pkg_lockfile(ws: &Workspace<'_>, resolve: &mut Resolve) -> CargoRes if resolve.version() < ResolveVersion::default() { resolve.set_version(ResolveVersion::default()); out = serialize_resolve(resolve, orig.as_deref()); - } else if resolve.version() > ResolveVersion::default() + } else if resolve.version() > ResolveVersion::V4 && !ws.config().cli_unstable().next_lockfile_bump { // The next version hasn't yet stabilized. diff --git a/tests/testsuite/lockfile_compat.rs b/tests/testsuite/lockfile_compat.rs index 97dcff1231a7..b149d41b36a8 100644 --- a/tests/testsuite/lockfile_compat.rs +++ b/tests/testsuite/lockfile_compat.rs @@ -889,51 +889,6 @@ perhaps a crate was updated and forgotten to be re-vendored? .run(); } -#[cargo_test] -fn v4_is_unstable() { - let p = project() - .file( - "Cargo.toml", - &format!( - r#" - [package] - name = "foo" - version = "0.0.1" - "#, - ), - ) - .file("src/lib.rs", "") - .file("Cargo.lock", "version = 4") - .build(); - - p.cargo("fetch") - .with_status(101) - .with_stderr( - "\ -error: failed to parse lock file at: [CWD]/Cargo.lock - -Caused by: - lock file version `4` was found, but this version of Cargo does not \ - understand this lock file, perhaps Cargo needs to be updated? -", - ) - .run(); - - // On nightly, let the user know about the `-Z` flag. - p.cargo("fetch") - .masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"]) - .with_status(101) - .with_stderr( - "\ -error: failed to parse lock file at: [CWD]/Cargo.lock - -Caused by: - lock file version 4 requires `-Znext-lockfile-bump` -", - ) - .run(); -} - #[cargo_test] fn v4_cannot_be_created_from_scratch() { let p = project() @@ -950,9 +905,7 @@ fn v4_cannot_be_created_from_scratch() { .file("src/lib.rs", "") .build(); - p.cargo("fetch -Znext-lockfile-bump") - .masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"]) - .run(); + p.cargo("fetch").run(); let lockfile = r#"# This file is automatically @generated by Cargo. # It is not intended for manual editing. @@ -1124,8 +1077,7 @@ dependencies = [ .file("Cargo.lock", "version = 4") .build(); - p.cargo("check -Znext-lockfile-bump") - .masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"]) + p.cargo("check") .with_stderr(format!( "\ [UPDATING] git repository `{url}` @@ -1141,10 +1093,7 @@ dependencies = [ // Unlike v3_and_git_url_encoded, v4 encodes URL parameters so no git // repository re-clone happen. - p.cargo("check -Znext-lockfile-bump") - .masquerade_as_nightly_cargo(&["-Znext-lockfile-bump"]) - .with_stderr("[FINISHED] dev [..]") - .run(); + p.cargo("check").with_stderr("[FINISHED] dev [..]").run(); } #[cargo_test]