rust-lang / cargo

The Rust package manager
https://doc.rust-lang.org/cargo
Apache License 2.0
12.66k stars 2.4k forks source link

cargo metadata doesn't identify which crate in the current workspace is the "current" one #4018

Open sfackler opened 7 years ago

alexcrichton commented 7 years ago

cc @matklad

matklad commented 7 years ago

Hm, and what is "the current crate"? The one specified with --manifest-path or the closest to the current working directory?

We can surface that to cargo-metadata for sure, but logically it does not belong there (i.e, I expect cargo metadata to return the same output regardless of the location in the workspace it is invoked from).

I also feel that "current crate" is a bit elusive concept (there's no current crate with -all flag).

Perhaps it would not be that difficult to reconstruct "current" on the client's side? You don't have to do directory traversal, you can look at the manifest_path fields of Package nodes of metadata.

sfackler commented 7 years ago

The "current" crate is the one that builds if I run cargo build with the same flags.

matklad commented 7 years ago

The "current" crate is the one that builds if I run cargo build with the same flags.

Cargo may build any set of packages from a workspace depending on the flags. For example

$ cargo build -p foo -p bar  

will build foo and bar and their dependencies, but not, for example, baz. And there's also cargo build --all. So there's no the "current" crate really. Why do you need to know current crate?