-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Also emit source information for paths #8988
Conversation
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
(rust-highfive has picked a reviewer for you, use r? to override) |
The failing test is due to |
I don't think this is something that can be changed, because tools will be depending on that value being null. Also, for rustfmt's use case, it needs the path to the package. The SourceId is intended to be opaque, and that shouldn't be used for determining the path. I was roughly thinking of adding a new field for that path information. EDIT (Or maybe manifest_path is enough, I don't remember.) As for fixing rustfmt's specific use case, there's also a problem where |
Hmm, interesting. Wouldn't adding a field be just as breaking? In what cases would consumers specifically expect the field to be The problem with using I'd be happy to write up a PR that includes path dependencies even if |
@ehuss - we need to know where on the file system to locate the path-based dependencies, which are indeed typically local implicit workspace members, but can also be some random other package on the file system (I've no idea what that use case would be but we technically support that today) |
New fields are allowed, as they are usually ignored by things like serde. I thought that was documented, but I can only see it mentioned in the rustc docs.
Whenever it wants to collect all local packages (like this).
Yea, it's a bit of a thorny issue. I was working on rust-lang/rustfmt#4247, but never really finished. The idea is that |
@ehuss Hmm, yeah, that's tricky. If new fields are indeed ignored and we're willing to add one, how about just adding a |
I don't think that would address the |
Hmm, wouldn't it be sufficient for |
if the dependency nodes (crucially with |
I fear I may be missing some context on this, as I don't understand why we'd need more paths available than we already have with each package's manifest path listed. Can you elaborate a bit more where the current output falls short? (e.g. if this is a rustfmt thing, can all packages be iterated over with |
We already do this today for the packages, but #7483 is about our need to be able to locate the manifest file for dependencies of those packages. Implicit workspace members are not included in the packages collection, and with That forces us to eschew the |
Ah ok, that makes sense. I don't think that "just add the information to dependencies" is what you want to fix this, though, because you presumably want all transtive path dependencies of a crate, not just the first-level path dependencies outside of the workspace, right? I don't think that Cargo has any equivalent to that right now, you almost want |
That's correct and currently we do that transitive walking within
That would be fantastic and allow us to simplify things a bit on the rustfmt side, but even being able to get the paths for the direct dependencies without having to require network connectivity, index/performance hit, etc. would be a huge win |
Ok mostly just wanted to confirm. This means that "just add info to dependencies" is not going to work for rustfmt's use case as-is I think, since it will require more invasive changes in Cargo. Unfortunately though even implementing something like Would it be possible for rustfmt to run |
We already do this today (albeit without
I'm not following the distinction between these two, could you elaborate? At the end of the day, the most minimal thing that would solve our need on the rustfmt side is the ability to determine the manifest path for implicit workspace members (even just direct local deps on packages would suffice) from cargo without having to the required network connectivity, downloading dependencies, etc. that happens today. We're happy to work with whatever makes sense on the cargo side (understand there's some complexity here), but if there was some field |
Just for comparison, I took a stab at a PR for surfacing manifest paths just for direct local dependencies in #8994. |
Oh interesting, @calebcartwright how come you invoke
What I'm imagining is that rustfmt would always invoke Would that work for rustfmt? If so #8994 definitely sounds like a good PR to me! Although it also seems good in isolation :) |
Yes, that's precisely what we'd like to be able to, and is essentially what we do today just sans --no-deps
Does the metadata output contain all the target and manifest path information for all dependencies for all packages? The core data points cargo fmt is grabbing to pass to rustfmt are the entry point files (obtained from the targets) and the edition. We first run cargo metadata in the cwd, and then if there's local deps at some I don't recall that initial metadata output containing all the information we need for that entire tree of local deps but could certainly be mistaken. |
I thought that the metadata information contained all that, but I could also be remembering wrong! In any case it sounds like we should perhaps close this in favor of #8994? |
@alexcrichton I went ahead and closed this -- #8994 seems like a much simpler way to get at this then, seeing as it still solves the need that rustfmt has 🎉 |
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.
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:#7483 (comment)
This PR makes this redaction optional so that
cargo metadata
andfriends will output the source location, which is useful for tools
like
rustfmt
which need to know the paths to local packages (see #7483and rust-lang/rustfmt#4599).
Interestingly enough, no tests fail even though
disable_path_serialization
is never currently called. I don't know ifthat'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 #7483