Skip to content
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

Merged
merged 3 commits into from
Sep 11, 2018

Conversation

eira-fransham
Copy link
Contributor

Closes #235

Copy link
Member

@nrc nrc left a 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> {
Copy link
Member

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.

Copy link
Contributor Author

@eira-fransham eira-fransham Jul 4, 2018

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());
Copy link
Member

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
};
Copy link
Member

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?

Copy link
Member

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?

Copy link
Contributor Author

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)

Copy link
Member

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("-", "_"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

Copy link
Member

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.

Copy link
Member

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

Copy link
Contributor Author

@eira-fransham eira-fransham Jul 2, 2018

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 &strs 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.

Copy link
Member

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.

@eira-fransham
Copy link
Contributor Author

@nrc Because cargo generates a metadata file with a name of the format libfoo-somehash for libraries and the format foo-somehash for binaries. For example, cargo_src-somehash and libcargo_src-somehash.

@nrc
Copy link
Member

nrc commented Jul 3, 2018

Thanks for the change in the last commit. Would you also be able to address the comment about the crate_names function please?

@nrc nrc merged commit 476aada into rust-dev-tools:master Sep 11, 2018
@nrc
Copy link
Member

nrc commented Sep 11, 2018

Thanks for the last change and the PR, and sorry it has lingered so long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants