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

Use the "cargo metadata" command instead of manipulating paths directly #828

Merged
merged 2 commits into from
Jul 18, 2022

Conversation

Michael-F-Bryan
Copy link
Contributor

No description provided.

@hannobraun
Copy link
Owner

Thank you, @Michael-F-Bryan! Looks reasonable. I'll take a closer look on Monday.

@Michael-F-Bryan Michael-F-Bryan changed the title Try to use the "cargo metadata" command when automatically discovering the target dir Use the "cargo metadata" command instead of manipulating paths directly Jul 16, 2022
@Michael-F-Bryan
Copy link
Contributor Author

Michael-F-Bryan commented Jul 16, 2022

I found a second issue which is related to the assumptions we make about paths and directory structures.

When my projects all have a common prefix (e.g. fj-) I'll typically call the crate fj-foo and put it in the crates/foo/ folder, however because we assume the compiled *.so is the named same as its folder, I was getting a bunch of "target/debug/libfoo.so not found" errors when it is actually compiled as .../libfj_foo.so.

My second commit switches the naming logic to use a package's name as derived by cargo metadata (i.e. the thing in your Cargo.toml). The behaviour is identical for the models in this repo, but now it also handles the renamed directories case.

Copy link
Owner

@hannobraun hannobraun left a comment

Choose a reason for hiding this comment

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

Thanks again for the pull request, @Michael-F-Bryan!

I've left some comments about the error handling. Feel free to address this in a follow-up commit, if you want. If not, I will open an issue to track it shortly.

let metadata = cargo_metadata::MetadataCommand::new()
.current_dir(&crate_dir)
.exec()
.map_err(metadata_error_to_io)?;
Copy link
Owner

Choose a reason for hiding this comment

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

Let's remove this conversion. The function doesn't need to return io::Error. It can return a custom error type that covers all its failure modes. (The crate already depends on thiserror, so we don't even need an additional dependency.)


let msg = format!("\"{}\" doesn't point to a crate", dir.display());

Err(io::Error::new(io::ErrorKind::Other, msg))
Copy link
Owner

Choose a reason for hiding this comment

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

Let's use a more appropriate custom error type here. We can probably reuse whatever Model::from_path will end up returning.

@hannobraun hannobraun enabled auto-merge July 18, 2022 13:58
@hannobraun hannobraun merged commit 626e5fb into hannobraun:main Jul 18, 2022
@Michael-F-Bryan Michael-F-Bryan deleted the hotfix/target-dir branch August 9, 2022 12:34
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