@@ -132,7 +132,7 @@ impl EncodableResolve {
132
132
/// `features`. Care should be taken when using this Resolve. One of the
133
133
/// primary uses is to be used with `resolve_with_previous` to guide the
134
134
/// resolver to create a complete Resolve.
135
- pub fn into_resolve ( self , ws : & Workspace < ' _ > ) -> CargoResult < Resolve > {
135
+ pub fn into_resolve ( self , original : & str , ws : & Workspace < ' _ > ) -> CargoResult < Resolve > {
136
136
let path_deps = build_path_deps ( ws) ;
137
137
let mut checksums = HashMap :: new ( ) ;
138
138
@@ -333,6 +333,30 @@ impl EncodableResolve {
333
333
unused_patches. push ( id) ;
334
334
}
335
335
336
+ // We have a curious issue where in the "v1 format" we buggily had a
337
+ // trailing blank line at the end of lock files under some specific
338
+ // conditions.
339
+ //
340
+ // Cargo is trying to write new lockfies in the "v2 format" but if you
341
+ // have no dependencies, for example, then the lockfile encoded won't
342
+ // really have any indicator that it's in the new format (no
343
+ // dependencies or checksums listed). This means that if you type `cargo
344
+ // new` followed by `cargo build` it will generate a "v2 format" lock
345
+ // file since none previously existed. When reading this on the next
346
+ // `cargo build`, however, it generates a new lock file because when
347
+ // reading in that lockfile we think it's the v1 format.
348
+ //
349
+ // To help fix this issue we special case here. If our lockfile only has
350
+ // one trailing newline, not two, *and* it only has one package, then
351
+ // this is actually the v2 format.
352
+ if original. ends_with ( "\n " )
353
+ && !original. ends_with ( "\n \n " )
354
+ && version == ResolveVersion :: V1
355
+ && g. iter ( ) . count ( ) == 1
356
+ {
357
+ version = ResolveVersion :: V2 ;
358
+ }
359
+
336
360
Ok ( Resolve :: new (
337
361
g,
338
362
replacements,
0 commit comments