-
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
WIP: try making cargo tree's Graph from a UnitGraph #11379
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @weihanglo (or someone else) soon. Please see the contribution instructions for more information. |
* does not understand build dependencies * completely ignores dev dependencies
Progress report for today: my If I apply this patch: diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs
index 4ce0162bf..513d4f4f8 100644
--- a/crates/cargo-test-support/src/lib.rs
+++ b/crates/cargo-test-support/src/lib.rs
@@ -414,6 +414,7 @@ impl Project {
let mut execs = self.process(&cargo);
if let Some(ref mut p) = execs.process_builder {
p.env("CARGO", cargo);
+ p.env("CARGO_TREE_FROM_UNIT_GRAPH", "1");
p.arg_line(cmd);
}
execs then it causes failures from the 25 tests [edit: copied to the top comment to give a better indication of progress] Something to work on tomorrow 😁 . |
Progress report for the weekend: Apart from the tests that pass Questions: I doubt that this PR will be in a reasonable state to merge before I get swallowed up by my new job, but it will hopefully serve as a reference of what is possible and what is easier/harder if you go down this route. I will therefore close this PR on Tuesday, whatever state it's in. I will leave the branch around in case someone wants to use it as inspiration. |
Haven't really looked deeply into your change, but I do appreciate what you've done. The amount of code added so far are less than I expected. It is indeed a great exploration. Thank you!
I don't think so, at least for the latter. They have different meanings. We already have
Package filtering process happens here, so
Go ahead, or put it into another module, so we can have a clear view of the diff :)
Even the final result reduces the complexity, I'll still ask about the extensibility, such as handling an issue like #10593 (comment). I think ehuss has some concerns on sharing code, so having ehuss taking a look is better once it is in a relatively good shape. |
Ah. I think I might have misunderstood that part of the code. For some reason, I thought ForceAllTargets was about the
I think this may be due to bugs in my understanding again. I was under the impression that it was possible to ask cargo tree to "show me how cargo would build this workspace, but only show me things below $package" in the tree.
I will do the "another module" thing first, and then do "deleting the old code" as a separate PR against my own fork if I get time.
I suppose this is a philosophical thing: is Fundamentally, |
// FIXME: we're creating this here, but build_ctx() is also creating one. | ||
// Can we refactor things so that they are shared? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// FIXME: we're creating this here, but build_ctx() is also creating one. | |
// Can we refactor things so that they are shared? | |
// FIXME: we're creating this here, but create_bcx() is also creating one. | |
// Can we refactor create_bcx() into multiple functions so that they can be shared? |
I've reached the end of my timebox for this. I briefly tried propagating ForceAllTargets, but I ran out of time before I got any --target=all tests passing. I also didn't get time to do any cleaning up, so it's still a mess. Sorry. I still think that this is a promising idea. Advantages:
As an aside, I wonder if we could use a similar approach to support displaying artifact dependencies and build-scripts. You would want a Risks:
Thanks for all of your support in this exploration. Hopefully it contains some useful ideas. Even if it doesn't, I have learned a lot. Thanks again. David. |
What does this PR try to resolve?
This is an attempt at implementing step 1 from #9599 (comment) - a function which converts from a UnitGraph to a cargo::ops::tree::graph::Graph
This would make it easier to find edge cases where
cargo tree
disagrees withcargo build
.How should we test and review this PR?
TODO (this PR is currently WIP)
Demonstrate how you test this change and guide reviewers through your PR.
With a smooth review process, a pull request usually gets reviewed quicker.
If you don't know how to write and run your tests, please read the guide:
https://doc.crates.io/contrib/tests
Additional information
tree
has a copy-pasta version of it. It might be possible to reconcile the two, but it feels a bit meaningless)cargo quickbuild
anyway, so it won't be wasted effort).Failing tests to chip away at:
new code fails to printhrm. Nevermind. I changed how I was linking my features up and the test now passes. Maybe I will revisit this later to make sure I was misreading thefeat1
, butcargo build --features=a
actually buildsbar
with features["feat1", "feat2"]
(if I'm reading the trace output correctly), so I think the old code and test are also wrong, but in a different way.cargo build
trace output.bar
as a normal dep (with optdep in there)bar
. Not sure why (the cause will probably be similar for both).optdep
dependency. I think this might be a sign that I've successfully fixedcargo tree
doesn't handle transitive duplications properly #9599 ;-)This is completely missing theDonefeat2
dependency (dependencies.b ={path="../b", features=["feat2"]}
so this is pretty glaring and should be easy to spot/debug.graph.dep_name_map[&package_index]
inadd_cli_features()
. I'm probably failing to uphold an invariant somewhere.