-
Notifications
You must be signed in to change notification settings - Fork 31
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
Allow analysis to work on binary crates with libraries #239
Allow analysis to work on binary crates with libraries #239
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.
Thanks for the PR! afaict, the significant part of this is normalising hyphens to underscores. Why does that affect binaries but not libraries?
src/build.rs
Outdated
.map(|p| p.name) | ||
.collect() | ||
} | ||
fn crate_names() -> impl Iterator<Item = String> { |
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.
Making this a free function rather than method is fine, but the other refactoring I think is not worth doing - iiuc, it adds some complexity only for the sake of removing a single allocation, which I think is unlikely to be significant.
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 don't think it really adds complexity, just a "what's happening here?" with the mapping of an empty vec.
We can replace it with:
fn crate_names() -> impl Iterator<Item = String> {
cargo_metadata::metadata_deps(None, true)
.map(|metadata| metadata.packages)
.unwrap_or_default()
.into_iter()
.map(|package| package.name)
}
In fact, if it's a one-liner we might as well inline it into clean_analysis
src/build.rs
Outdated
if !crate_names.contains(&name) { | ||
info!("deleting {:?}", entry.path()); | ||
if !crate_names.contains(&match_name) { | ||
println!("deleting {:?}", entry.path()); |
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 change should be reversed
&name[3..] | ||
} else { | ||
&name | ||
}; |
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.
Why change to the more verbose idiom here?
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'm not clear if moving the "lib" check is significant - what is the effect?
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.
Because we need &name
still to bucket libX
and X
seperately (unless that's not what you meant)
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.
OK, thanks
src/build.rs
Outdated
@@ -61,10 +61,16 @@ impl Builder { | |||
|
|||
// Remove any old or duplicate json files. | |||
fn clean_analysis(&self) { | |||
let crate_names = self.crate_names(); | |||
let crate_names = crate_names() | |||
.map(|name| name.replace("-", "_")) |
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.
Good catch!
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.
If you want to avoid duplicating the collect, you could move this map to crate_names
to avoid the new complexity there.
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.
Or could combine with the following map
on line 67
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.
You need to collect twice to have somewhere for the &str
s to point to. You can avoid it using a more verbose idiom using iter().any(|s| s == foo)
instead of contains
but I didn't think it was necessary because this isn't a particularly hot path.
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 think it is worth using any
rather than contains
for the sake of cleaner code here and in crate_names()
, if not for performance.
@nrc Because cargo generates a metadata file with a name of the format |
9297971
to
09e3bc2
Compare
Thanks for the change in the last commit. Would you also be able to address the comment about the |
Thanks for the last change and the PR, and sorry it has lingered so long. |
Closes #235