-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Include path/url of local dependencies in cargo metadata --no-deps
output
#7483
Comments
Thanks for the report! That serialization of |
You can back the directory out of the manifest_path field, but it would be nice for source to be properly populated. |
I don't see a Edit: Nevermind, I was looking at the |
Just to clarify on the original ask here, we're in need of the source information not being stripped for local dependencies of the packages. I know there's a A null |
I'm digging into this at the moment and will submit a PR shortly. Interestingly, it looks like none of the tests fail if I simply remove the |
Previously, the location for path-based (i.e., local) packages was redacted from metadata output. This was done way back when so that `Cargo.lock` would not include path sources: rust-lang#7483 (comment) This PR makes this redaction optional so that `cargo metadata` and friends _will_ output the source location, which is useful for tools like `rustfmt` which need to know the paths to local packages (see rust-lang#7483 and rust-lang/rustfmt#4599). Interestingly enough, no tests fail even though `disable_path_serialization` is never currently called. I don't know if that's because there's no test that cover where redaction is needed, or because redaction is simply no longer needed (presumably because lockfile generation now uses custom logic). If it is the latter, this PR can be simplified to not support opting into redaction. Fixes rust-lang#7483
Including those outside the current workspace. This allows for finding all local code without having to recursively call Cargo, which is useful for rustfmt and other tools. Fixes: rust-lang#7483
metadata: Supply local path for path dependencies This is potentially a simpler way to address #7483 than #8988. /cc rust-lang/rustfmt#4247 Fixes #7483.
Describe the problem you are trying to solve
We're running into some challenges over in
rustfmt
due to the output of thecargo metadata
command missing thesource
path for local dependencies when using the--no-deps
flag withcargo metadata
.Describe the solution you'd like
Ideally, in the output of
cargo metadata --no-deps
, the source field for local dependencies would include the path value instead of being null.Notes
cargo fmt
uses thecargo metadata
command to get info about the workspace to pass as inputs torustfmt
. One of the modescargo fmt
supports is--all
which allowsrustfmt
to also format local dependencies. In order to be able to do this,cargo fmt
needs to be able locate the manifest path for the local dependency.However, the serialization for Dependency results in the path value for local dependencies being stripped, so in the output from
cargo metadata
, local dependencies have"source": null,
and the output ofcargo metadata --no-deps
does not contain any other infocargo fmt
can use to definitively determine the manifest path of the local dependency. This is problematic forcargo fmt
, especially since the directory name where the local dependency resides and the name of the dependency can differ - rust-lang/rustfmt#3643We've been working around the missing data by running
cargo metadata
(without the--no-deps
flag) since that output does allow us to correctly determine themanifest_path
value for local dependencies. However, runningcargo metadata
without--no-deps
is creating some other challenges for us, and we'd really like to be able to get everything needed viacargo metadata --no-deps
.AFAICT, for path-based dependencies, the value is stripped deliberately from the serialized output:
cargo/src/cargo/core/source/source_id.rs
Lines 401 to 412 in 0fe1638
I'm sure that's done for good reason, though I'm wondering/hoping that those reasons may not be applicable for
cargo metadata
output and that it would be possible to keep that value for local path-based dependencies included just in thecargo metadata
output (perhaps by using different struct representations)?cc @topecongiro
The text was updated successfully, but these errors were encountered: