diff --git a/src/cargo/core/resolver/encode.rs b/src/cargo/core/resolver/encode.rs index 344082bf60e..5bfc6a8c8b7 100644 --- a/src/cargo/core/resolver/encode.rs +++ b/src/cargo/core/resolver/encode.rs @@ -14,7 +14,7 @@ use super::Resolve; #[derive(Serialize, Deserialize, Debug)] pub struct EncodableResolve { package: Option>, - /// `root` is optional to allow forward compatibility. + /// `root` is optional to allow backward compatibility. root: Option, metadata: Option, @@ -311,7 +311,6 @@ impl<'de> de::Deserialize<'de> for EncodablePackageId { pub struct WorkspaceResolve<'a, 'cfg: 'a> { pub ws: &'a Workspace<'cfg>, pub resolve: &'a Resolve, - pub use_root_key: bool, } impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> { @@ -321,15 +320,7 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> { let mut ids: Vec<&PackageId> = self.resolve.graph.iter().collect(); ids.sort(); - let root = self.ws.members().max_by_key(|member| { - member.name() - }).map(Package::package_id); - let encodable = ids.iter().filter_map(|&id| { - if self.use_root_key && root.unwrap() == id { - return None - } - Some(encodable_resolve_node(id, self.resolve)) }).collect::>(); @@ -347,11 +338,6 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> { let metadata = if metadata.is_empty() { None } else { Some(metadata) }; - let root = match root { - Some(root) if self.use_root_key => Some(encodable_resolve_node(root, self.resolve)), - _ => None, - }; - let patch = Patch { unused: self.resolve.unused_patches().iter().map(|id| { EncodableDependency { @@ -365,7 +351,7 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> { }; EncodableResolve { package: Some(encodable), - root: root, + root: None, metadata: metadata, patch: patch, }.serialize(s) diff --git a/src/cargo/ops/lockfile.rs b/src/cargo/ops/lockfile.rs index 64de6f1ea37..8dc5b45672e 100644 --- a/src/cargo/ops/lockfile.rs +++ b/src/cargo/ops/lockfile.rs @@ -40,30 +40,13 @@ pub fn write_pkg_lockfile(ws: &Workspace, resolve: &Resolve) -> CargoResult<()> Ok(s) }); - // Forward compatibility: if `orig` uses rootless format - // from the future, do the same. - let use_root_key = if let Ok(ref orig) = orig { - !orig.starts_with("[[package]]") - } else { - true - }; - let toml = toml::Value::try_from(WorkspaceResolve { ws: ws, resolve: resolve, - use_root_key: use_root_key, }).unwrap(); let mut out = String::new(); - // Note that we do not use e.toml.to_string() as we want to control the - // exact format the toml is in to ensure pretty diffs between updates to the - // lockfile. - if let Some(root) = toml.get("root") { - out.push_str("[root]\n"); - emit_package(root.as_table().unwrap(), &mut out); - } - let deps = toml["package"].as_array().unwrap(); for dep in deps.iter() { let dep = dep.as_table().unwrap(); diff --git a/src/doc/book/src/guide/cargo-toml-vs-cargo-lock.md b/src/doc/book/src/guide/cargo-toml-vs-cargo-lock.md index de3f18cb08b..574a6677f23 100644 --- a/src/doc/book/src/guide/cargo-toml-vs-cargo-lock.md +++ b/src/doc/book/src/guide/cargo-toml-vs-cargo-lock.md @@ -71,7 +71,7 @@ Cargo will take the latest commit and write that information out into our `Cargo.lock` when we build for the first time. That file will look like this: ```toml -[root] +[[package]] name = "hello_world" version = "0.1.0" dependencies = [ diff --git a/src/doc/guide.md b/src/doc/guide.md index 55decf1ac6a..e63be4dd592 100644 --- a/src/doc/guide.md +++ b/src/doc/guide.md @@ -328,7 +328,7 @@ Cargo will take the latest commit and write that information out into our `Cargo.lock` when we build for the first time. That file will look like this: ```toml -[root] +[[package]] name = "hello_world" version = "0.1.0" dependencies = [ diff --git a/tests/bad-config.rs b/tests/bad-config.rs index cff576dbb47..06e58100559 100644 --- a/tests/bad-config.rs +++ b/tests/bad-config.rs @@ -256,7 +256,7 @@ fn duplicate_packages_in_cargo_lock() { "#) .file("src/lib.rs", "") .file("Cargo.lock", r#" - [root] + [[package]] name = "bar" version = "0.0.1" dependencies = [ @@ -300,7 +300,7 @@ fn bad_source_in_cargo_lock() { "#) .file("src/lib.rs", "") .file("Cargo.lock", r#" - [root] + [[package]] name = "bar" version = "0.0.1" dependencies = [ @@ -334,7 +334,7 @@ fn bad_dependency_in_lockfile() { "#) .file("src/lib.rs", "") .file("Cargo.lock", r#" - [root] + [[package]] name = "foo" version = "0.0.1" dependencies = [ diff --git a/tests/generate-lockfile.rs b/tests/generate-lockfile.rs index 94432e4f645..2151f45e51c 100644 --- a/tests/generate-lockfile.rs +++ b/tests/generate-lockfile.rs @@ -145,7 +145,7 @@ fn preserve_line_endings_issue_2076() { let lock0 = p.read_lockfile(); - assert!(lock0.starts_with("[root]\n")); + assert!(lock0.starts_with("[[package]]\n")); let lock1 = lock0.replace("\n", "\r\n"); { @@ -157,7 +157,7 @@ fn preserve_line_endings_issue_2076() { let lock2 = p.read_lockfile(); - assert!(lock2.starts_with("[root]\r\n")); + assert!(lock2.starts_with("[[package]]\r\n")); assert_eq!(lock1, lock2); } diff --git a/tests/git.rs b/tests/git.rs index ca0f209f39f..7328a1e56ae 100644 --- a/tests/git.rs +++ b/tests/git.rs @@ -971,7 +971,7 @@ fn stale_cached_version() { let rev = repo.revparse_single("HEAD").unwrap().id(); File::create(&foo.root().join("Cargo.lock")).unwrap().write_all(format!(r#" - [root] + [[package]] name = "foo" version = "0.0.0" dependencies = [ diff --git a/tests/install.rs b/tests/install.rs index 3ed4bf0d9a5..a753697afcd 100644 --- a/tests/install.rs +++ b/tests/install.rs @@ -829,7 +829,7 @@ fn git_with_lockfile() { "#) .file("bar/src/lib.rs", "fn main() {}") .file("Cargo.lock", r#" - [root] + [[package]] name = "foo" version = "0.1.0" dependencies = [ "bar 0.1.0" ] diff --git a/tests/lockfile-compat.rs b/tests/lockfile-compat.rs index 00eacebbfcb..d9f6791687c 100644 --- a/tests/lockfile-compat.rs +++ b/tests/lockfile-compat.rs @@ -8,9 +8,36 @@ use hamcrest::assert_that; #[test] fn oldest_lockfile_still_works() { + let cargo_commands = vec![ + "build", + "update" + ]; + for cargo_command in cargo_commands { + oldest_lockfile_still_works_with_command(cargo_command); + } +} + +fn oldest_lockfile_still_works_with_command(cargo_command: &str) { Package::new("foo", "0.1.0").publish(); - let lockfile = r#" + let expected_lockfile = +r#"[[package]] +name = "bar" +version = "0.0.1" +dependencies = [ + "foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "foo" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[metadata] +"checksum foo 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "[..]" +"#; + + let old_lockfile = r#" [root] name = "bar" version = "0.0.1" @@ -35,14 +62,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" foo = "0.1.0" "#) .file("src/lib.rs", "") - .file("Cargo.lock", lockfile); + .file("Cargo.lock", old_lockfile); + p.build(); - assert_that(p.cargo("build"), + assert_that(p.cargo(cargo_command), execs().with_status(0)); let lock = p.read_lockfile(); - assert!(lock.starts_with(lockfile.trim())); + for (l, r) in expected_lockfile.lines().zip(lock.lines()) { + assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r); + } + + assert_eq!(lock.lines().count(), expected_lockfile.lines().count()); } #[test] @@ -61,7 +93,7 @@ fn totally_wild_checksums_works() { "#) .file("src/lib.rs", "") .file("Cargo.lock", r#" -[root] +[[package]] name = "bar" version = "0.0.1" dependencies = [ @@ -85,7 +117,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" let lock = p.read_lockfile(); assert!(lock.starts_with(r#" -[root] +[[package]] name = "bar" version = "0.0.1" dependencies = [ @@ -117,7 +149,7 @@ fn wrong_checksum_is_an_error() { "#) .file("src/lib.rs", "") .file("Cargo.lock", r#" -[root] +[[package]] name = "bar" version = "0.0.1" dependencies = [ @@ -170,7 +202,7 @@ fn unlisted_checksum_is_bad_if_we_calculate() { "#) .file("src/lib.rs", "") .file("Cargo.lock", r#" -[root] +[[package]] name = "bar" version = "0.0.1" dependencies = [ @@ -230,7 +262,7 @@ fn listed_checksum_bad_if_we_cannot_compute() { "#, git.url())) .file("src/lib.rs", "") .file("Cargo.lock", &format!(r#" -[root] +[[package]] name = "bar" version = "0.0.1" dependencies = [ @@ -287,7 +319,7 @@ fn current_lockfile_format() { let actual = p.read_lockfile(); let expected = "\ -[root] +[[package]] name = \"bar\" version = \"0.0.1\" dependencies = [ diff --git a/tests/overrides.rs b/tests/overrides.rs index 0941f774dea..0a022650f67 100644 --- a/tests/overrides.rs +++ b/tests/overrides.rs @@ -802,7 +802,7 @@ fn override_an_override() { "serde:0.8.0" = { path = "serde" } "#) .file("Cargo.lock", r#" - [root] + [[package]] name = "local" version = "0.0.1" dependencies = [ diff --git a/tests/workspaces.rs b/tests/workspaces.rs index 68e9468f008..2e2dc1b32a1 100644 --- a/tests/workspaces.rs +++ b/tests/workspaces.rs @@ -961,7 +961,7 @@ fn lockfile_can_specify_nonexistant_members() { "#) .file("a/src/main.rs", "fn main() {}") .file("Cargo.lock", r#" - [root] + [[package]] name = "a" version = "0.1.0"