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

[REGRESSION] cargo metadata looks into $HOME/Cargo.toml #3718

Closed
ignatenkobrain opened this issue Feb 16, 2017 · 8 comments
Closed

[REGRESSION] cargo metadata looks into $HOME/Cargo.toml #3718

ignatenkobrain opened this issue Feb 16, 2017 · 8 comments

Comments

@ignatenkobrain
Copy link
Contributor

[brain@ignatenko-w541 bitflags-0.8.0]$ cargo --version
cargo 0.15.0 (built 2017-02-07)
[brain@ignatenko-w541 bitflags-0.8.0]$ cargo metadata
{"packages":[{"name":"bitflags","version":"0.8.0","id":"bitflags 0.8.0 (path+file:///home/brain/rpmbuild/BUILD/bitflags-0.8.0)","license":"MIT/Apache-2.0","license_file":null,"source":null,"dependencies":[],"targets":[{"kind":["lib"],"name":"bitflags","src_path":"/home/brain/rpmbuild/BUILD/bitflags-0.8.0/src/lib.rs"},{"kind":["test"],"name":"external","src_path":"/home/brain/rpmbuild/BUILD/bitflags-0.8.0/tests/external.rs"},{"kind":["test"],"name":"external_no_std","src_path":"/home/brain/rpmbuild/BUILD/bitflags-0.8.0/tests/external_no_std.rs"},{"kind":["test"],"name":"i128_bitflags","src_path":"/home/brain/rpmbuild/BUILD/bitflags-0.8.0/tests/i128_bitflags.rs"}],"features":{"i128":[],"unstable":["i128"]},"manifest_path":"/home/brain/rpmbuild/BUILD/bitflags-0.8.0/Cargo.toml"}],"workspace_members":["bitflags 0.8.0 (path+file:///home/brain/rpmbuild/BUILD/bitflags-0.8.0)"],"resolve":{"root":"bitflags 0.8.0 (path+file:///home/brain/rpmbuild/BUILD/bitflags-0.8.0)","nodes":[{"id":"bitflags 0.8.0 (path+file:///home/brain/rpmbuild/BUILD/bitflags-0.8.0)","dependencies":[]}]},"version":1}

...

[brain@ignatenko-w541 bitflags-0.8.0]$ cargo --version
cargo 0.16.0 (built 2017-02-14)
[brain@ignatenko-w541 bitflags-0.8.0]$ cargo metadata
error: failed to parse manifest at `/home/brain/Cargo.toml`

Caused by:
  no `package` or `project` section found.

The problem is that I created empty ~/Cargo.toml for something else and forgot to remove it which broke normal cargo operations (in my case cargo metadata)...

@ignatenkobrain
Copy link
Contributor Author

The cargo build is affected as well:

+ /usr/bin/cargo build --release -j8
error: failed to parse manifest at `/home/brain/Cargo.toml`

@cuviper
Copy link
Member

cuviper commented Feb 16, 2017

I think cargo now walks up the directory tree looking for a parent workspace -- finding your ~/Cargo.toml.

@ignatenkobrain
Copy link
Contributor Author

@cuviper that seems weird... especially if I would have multiple subdirectories with different projects...

@cuviper
Copy link
Member

cuviper commented Feb 16, 2017

But you would probably not put those different projects with one in a subdirectory of another, would you?

Anyway, I think that would probably still work fine if every Cargo.toml is well-formed. The issue as I see it here is that it found an invalid (empty) Cargo.toml and treated this as a fatal error. I think it would be reasonable to expect cargo to just ignore such errors. (assuming it had already found a more immediate file as the primary.)

@alexcrichton
Copy link
Member

Yeah ignoring invalid Cargo.toml as we traverse upwards looking for a root sounds reasonable to me!

@matklad
Copy link
Member

matklad commented Mar 1, 2017

Yeah ignoring invalid Cargo.toml as we traverse upwards looking for a root sounds reasonable to me!

We've just recently fixed cargo in the opposite direction: #3409 :)

I think that the current behavior of not silently ignoring errors in Cargo.toml is the correct one, because problems like the one in #3407 are much harder to diagnose and fix.

And here the error is a very reasonable one:

error: failed to parse manifest at `/home/brain/Cargo.toml`

Caused by:
  no `package` or `project` section found.

But it is indeed can be surprising that now Cargo walks the directory tree up.

@ignatenkobrain
Copy link
Contributor Author

@matklad I've created Cargo.toml in my $HOME just for testing purpose and even forgot about that and was very surprised, why cargo looks into it.

@alexcrichton
Copy link
Member

@matklad oh right thanks for refreshing my memory! At least I can rest easy knowing that if such a change were implemented the tests would have caught it :)

In that case though I'm going to close this as this is currently a deliberate decision.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants