-
Notifications
You must be signed in to change notification settings - Fork 9
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
initial duplicate bevy version lint #185
base: main
Are you sure you want to change the base?
Conversation
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.
So far this looks good! I am interested in getting a span to Cargo.toml
/ Cargo.lock
, though I'm unsure if the compiler will know that file exists. Ping me when this is ready for a final review!
example of the lint message
|
One function you may find useful is |
nice catch! Thanks will add this. |
@DaAlbrecht The tests are failing, because Bevy needs additional system packages to be installed on Linux. I had the same issue in #222, so we can either merge that PR first and then merge main back in your branch or you can copy the CI-related changes here to fix this :) |
# Easy structured output for `cargo metadata`, used for cargo lints | ||
cargo_metadata = "0.19" | ||
# Deserializes the Cargo.toml for cargo lints | ||
toml = "0.8.19" |
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.
In the CLI we are using the toml_edit
crate to parse Cargo.toml
, do you think we can use one or the other in both, to avoid duplication?
|
||
// Load the `Cargo.toml` into the `SourceMap` this is necessary to get the `Span` of the | ||
// `Cargo.toml` file. | ||
if let Ok(file) = cx.tcx.sess.source_map().load_file(Path::new("Cargo.toml")) |
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.
In the main CLI, we are using the cargo metadata
command for a more robust method of finding the path to Cargo.toml
.
Not sure how easy it would be to use that logic in the linter, I'd be fine to pull that out into a follow-up issue.
But essentially it would make the linter more robust to the location where it's called.
# Easy structured output for `cargo metadata`, used for cargo lints | ||
cargo_metadata = "0.19" |
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.
Oh, we retrieved and parsed this manually in the main CLI. We should probably use the crate there as well :D
// Semver only supports checking if a given `VersionReq` matches a `Version` and not if two | ||
// `VersionReq` can successfully resolve to one `Version`. Therefore we try to parse the | ||
// `Version` from the `bevy` dependency in the `Cargo.toml` file. This only works if a | ||
// single version of `bevy` is specified and not a range. | ||
let Ok(target_version) = get_version_from_toml(bevy_cargo.as_ref()) else { | ||
return; | ||
}; |
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.
Hmmm, I'm not sure if this is the right approach here, as the version string in Cargo.toml
really is a VersionReq
instead of a Version
.
In the cargo metadata
output is a resolve
object, which I believe essentially contains the dependency graph.
Do you think we could search that for bevy
entries and then extract the versions from the package ID? Then we already know it's two different versions and don't need to compare them.
I guess it would make it a bit harder though to find where the duplicated bevy version is coming from (and which of both the "main" Bevy version is).
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.
Actually, I think you are already doing something similar?
I'm not sure if I'm understanding the code correctly
error: Mismatching versions of `bevy` found | ||
--> Cargo.toml:11:26 | ||
| | ||
11 | leafwing-input-manager = "0.13" |
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.
Super cool to have the spans here!
Bonus would be if it told you which Bevy version the dependency used instead, but that'd just be the cherry on top, feel free to leave it out
A first draft of a quick lint to check if multiple versions of bevy are defined. #15
todos:
cargo metadata
to get information about the crate versions.Cargo.toml
)