Skip to content
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

Remove root from cargo lock #4571

Merged
merged 7 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 1 addition & 17 deletions src/cargo/ops/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,30 +40,14 @@ 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,
use_root_key: false,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this field can be removed now as well?

}).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();
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book/src/guide/cargo-toml-vs-cargo-lock.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion src/doc/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent catch! I haven't thought of the docs at all!

name = "hello_world"
version = "0.1.0"
dependencies = [
Expand Down
6 changes: 3 additions & 3 deletions tests/bad-config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions tests/generate-lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
{
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it true that changes in tests are mostly cosmetics? That is, the tests pass with [root] as well as with [[package]]?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it. I made the same change against master branch and the test passes without a hitch

name = "foo"
version = "0.0.0"
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion tests/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
35 changes: 28 additions & 7 deletions tests/lockfile-compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@ use hamcrest::assert_that;
fn oldest_lockfile_still_works() {
Package::new("foo", "0.1.0").publish();

let expected_lock_file =
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 lockfile = r#"
[root]
name = "bar"
Expand Down Expand Up @@ -42,7 +59,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
execs().with_status(0));

let lock = p.read_lockfile();
assert!(lock.starts_with(lockfile.trim()));
for (l, r) in expected_lock_file.lines().zip(lock.lines()) {
assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r);
}

assert_eq!(lock.lines().count(), expected_lock_file.lines().count());
}

#[test]
Expand All @@ -61,7 +82,7 @@ fn totally_wild_checksums_works() {
"#)
.file("src/lib.rs", "")
.file("Cargo.lock", r#"
[root]
[[package]]
name = "bar"
version = "0.0.1"
dependencies = [
Expand All @@ -85,7 +106,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 = [
Expand Down Expand Up @@ -117,7 +138,7 @@ fn wrong_checksum_is_an_error() {
"#)
.file("src/lib.rs", "")
.file("Cargo.lock", r#"
[root]
[[package]]
name = "bar"
version = "0.0.1"
dependencies = [
Expand Down Expand Up @@ -170,7 +191,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 = [
Expand Down Expand Up @@ -230,7 +251,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 = [
Expand Down Expand Up @@ -287,7 +308,7 @@ fn current_lockfile_format() {
let actual = p.read_lockfile();

let expected = "\
[root]
[[package]]
name = \"bar\"
version = \"0.0.1\"
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion tests/overrides.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion tests/workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down