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

fix: handling of --all when local dep name and dir name differ #3664

Merged
merged 1 commit into from
Jul 6, 2019

Conversation

calebcartwright
Copy link
Member

@calebcartwright calebcartwright commented Jun 30, 2019

Refs #3643 (the cargo fmt --all portion)

Fixes issue running cargo fmt --all when local dependencies reside in a directory name that differs from the package name.

I created a sample repo here with local dependencies that reside in directories named differently than their package names that can be used to test against. Run cargo fmt --all -- --check in the root of the project, and note the formatting errors coming from the local dependency directories.

.find(|p| p.name == dependency.name);
let manifest_path = if dependency_package.is_some() {
PathBuf::from(&dependency_package.unwrap().manifest_path)
} else {
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure if there's a circumstance where the dependency name wouldn't be found/when the if block woudln't be executed, but have this else block to fallback to the previous behavior just in case.

@@ -282,7 +282,8 @@ fn get_targets_recursive(
mut targets: &mut BTreeSet<Target>,
visited: &mut BTreeSet<String>,
) -> Result<(), io::Error> {
let metadata = get_cargo_metadata(manifest_path)?;
let metadata = get_cargo_metadata(manifest_path, false)?;
let metadata_with_deps = get_cargo_metadata(manifest_path, true)?;
Copy link
Member Author

@calebcartwright calebcartwright Jun 30, 2019

Choose a reason for hiding this comment

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

The dependency struct returned from the cargo_metadata crate unsurprisingly does not include info about the manifest location of the dependency.

As such, I figured I could make another call to cargo_metadata to get the metadata including dependencies since that cargo metadata will include the correct manifest path for the dependency, regardless of what package name/directory name are used. That "correct" manifest path is then used below.

Copy link
Contributor

@topecongiro topecongiro Jul 1, 2019

Choose a reason for hiding this comment

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

Calling cargo_metadata twice is a bit unfortunate, but I think this is the best we can do right now. A possible approach in the future would be to refactor cargo_metadata so that the cargo_metadata::Dependency contains the manifest location if the dependency is local

Copy link
Member Author

Choose a reason for hiding this comment

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

Completely agree 👍

@calebcartwright calebcartwright changed the title fix: handling of --all when dep name and dir name differ fix: handling of --all when local dep name and dir name differ Jun 30, 2019
@topecongiro topecongiro added this to the 1.3.2 milestone Jul 1, 2019
Copy link
Contributor

@topecongiro topecongiro left a comment

Choose a reason for hiding this comment

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

Thank you for investigating the issue and creating the PR! LGTM.

@@ -282,7 +282,8 @@ fn get_targets_recursive(
mut targets: &mut BTreeSet<Target>,
visited: &mut BTreeSet<String>,
) -> Result<(), io::Error> {
let metadata = get_cargo_metadata(manifest_path)?;
let metadata = get_cargo_metadata(manifest_path, false)?;
let metadata_with_deps = get_cargo_metadata(manifest_path, true)?;
Copy link
Contributor

@topecongiro topecongiro Jul 1, 2019

Choose a reason for hiding this comment

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

Calling cargo_metadata twice is a bit unfortunate, but I think this is the best we can do right now. A possible approach in the future would be to refactor cargo_metadata so that the cargo_metadata::Dependency contains the manifest location if the dependency is local

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.

None yet

2 participants