-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Add format option to cargo tree to print the package version requirement
#16192
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
base: master
Are you sure you want to change the base?
Changes from 4 commits
0949c7e
8e7b557
7a01106
995e693
9381123
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1128,7 +1128,10 @@ foo v0.1.0 ([ROOT]/foo) | |
| #[cargo_test] | ||
| fn format() { | ||
| Package::new("dep", "1.0.0").publish(); | ||
| Package::new("other-dep", "1.0.0").publish(); | ||
| Package::new("dep", "2.0.0").publish(); | ||
| Package::new("other-dep", "1.0.0") | ||
| .dep("dep", "^1.0") | ||
| .publish(); | ||
|
|
||
| Package::new("dep_that_is_awesome", "1.0.0") | ||
| .file( | ||
|
|
@@ -1140,6 +1143,10 @@ fn format() { | |
|
|
||
| [lib] | ||
| name = "awesome_dep" | ||
|
|
||
| [dependencies] | ||
| dep1 = {package="dep", version="<2.0"} | ||
| dep2 = {package="dep", version="2.0"} | ||
| "#, | ||
| ) | ||
| .file("src/lib.rs", "pub struct Straw;") | ||
|
|
@@ -1156,9 +1163,9 @@ fn format() { | |
| repository = "https://github.com/rust-lang/cargo" | ||
|
|
||
| [dependencies] | ||
| dep = {version="1.0", optional=true} | ||
| dep = {version="=1.0"} | ||
| other-dep = {version="1.0", optional=true} | ||
| dep_that_is_awesome = {version="1.0", optional=true} | ||
| dep_that_is_awesome = {version=">=1.0, <2", optional=true} | ||
devodev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| [features] | ||
|
|
@@ -1173,6 +1180,7 @@ fn format() { | |
| p.cargo("tree --format <<<{p}>>>") | ||
| .with_stdout_data(str![[r#" | ||
| <<<foo v0.1.0 ([ROOT]/foo)>>> | ||
| └── <<<dep v1.0.0>>> | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
@@ -1191,6 +1199,7 @@ Caused by: | |
| p.cargo("tree --format {p}-{{hello}}") | ||
| .with_stdout_data(str![[r#" | ||
| foo v0.1.0 ([ROOT]/foo)-{hello} | ||
| └── dep v1.0.0-{hello} | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
@@ -1199,6 +1208,7 @@ foo v0.1.0 ([ROOT]/foo)-{hello} | |
| .arg("{p} {l} {r}") | ||
| .with_stdout_data(str![[r#" | ||
| foo v0.1.0 ([ROOT]/foo) MIT https://github.com/rust-lang/cargo | ||
| └── dep v1.0.0 | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
@@ -1207,17 +1217,19 @@ foo v0.1.0 ([ROOT]/foo) MIT https://github.com/rust-lang/cargo | |
| .arg("{p} {f}") | ||
| .with_stdout_data(str![[r#" | ||
| foo v0.1.0 ([ROOT]/foo) bar,default,foo | ||
| └── dep v1.0.0 | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
||
| p.cargo("tree --all-features --format") | ||
| .arg("{p} [{f}]") | ||
| .with_stdout_data(str![[r#" | ||
| foo v0.1.0 ([ROOT]/foo) [bar,default,dep,dep_that_is_awesome,foo,other-dep] | ||
| foo v0.1.0 ([ROOT]/foo) [bar,default,dep_that_is_awesome,foo,other-dep] | ||
| ├── dep v1.0.0 [] | ||
| ├── dep_that_is_awesome v1.0.0 [] | ||
| └── other-dep v1.0.0 [] | ||
| └── dep v1.0.0 [] | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
@@ -1227,8 +1239,34 @@ foo v0.1.0 ([ROOT]/foo) [bar,default,dep,dep_that_is_awesome,foo,other-dep] | |
| .arg("--format={lib}") | ||
| .with_stdout_data(str![[r#" | ||
|
|
||
| ├── dep | ||
| ├── awesome_dep | ||
| └── other_dep | ||
| └── dep | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
||
| p.cargo("tree --all-features") | ||
| .arg("--format={p} satisfies {ver-req}") | ||
| .with_stdout_data(str![[r#" | ||
| foo v0.1.0 ([ROOT]/foo) satisfies | ||
| ├── dep v1.0.0 satisfies ^1.0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Am I misreading things? This says dep = {version="=1.0"}
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, this version requirement seems to belong to other-dep. I think I see what's happening. We don't consider the parent when registering the version requirement in the lookup map, so it's probably replacing previous entries for the same package? I think using NodeID as index should make this unique.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a forewarning, a problem I suspect we'll see when we have two different, compatible version requirements on the same package and version requirements are more of a property of edges and not nodes. We don't annotate edges. Is that good enough, a blocker for this feature, or a cause to re-think some base assumptions? As an example of the latter, maybe for |
||
| ├── dep_that_is_awesome v1.0.0 satisfies >=1.0, <2 | ||
| └── other-dep v1.0.0 satisfies ^1.0 | ||
| └── dep v1.0.0 satisfies ^1.0 | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
||
| p.cargo("tree --all-features") | ||
| .arg("--format={p} satisfies {ver-req}") | ||
| .arg("--invert=dep") | ||
| .with_stdout_data(str![[r#" | ||
| dep v1.0.0 satisfies ^1.0 | ||
| ├── foo v0.1.0 ([ROOT]/foo) satisfies | ||
| └── other-dep v1.0.0 satisfies ^1.0 | ||
| └── foo v0.1.0 ([ROOT]/foo) satisfies | ||
|
|
||
| "#]]) | ||
| .run(); | ||
|
|
||
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.
This is removing coverage.
I suspect the test changes here should be purely additive rather than mutating existing stuff.
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.
I also question our having a single
formattest and wonder if we should break out your new cases into a separate test or even multiple testsThere 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.
Yes that's a good callout, I can work on splitting this out.