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

cargo fmt --all from excluded sub-directory still checks parent workspace #13962

Closed
dhardy opened this issue May 24, 2024 · 5 comments
Closed
Labels
A-workspaces Area: workspaces C-bug Category: bug Command-fmt S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix

Comments

@dhardy
Copy link

dhardy commented May 24, 2024

Problem

Here I run tests on an exclude-d sub-directory, benches. CI kept failing until I removed the --all from cargo fmt due to issues with other workspace members, which should not be checked from here.

Cargo.toml looks like this:

[workspace]
members = [
    "rand_jitter",
    "rand_isaac",
    "rand_xorshift",
    "rand_xoshiro",
    "rand_hc",
]
exclude = [
    "benches",
]
resolver = "2"

Therefore, cargo test -p benches from the repo root fails (expected).

However, this succeeds:

$ cd benches/
$ cargo test -p rand_hc
   Compiling libc v0.2.155

This should fail since benches is, by explicit exclusion, not part of the parent workspace.

Steps

No response

Possible Solution(s)

No response

Notes

No response

Version

No response

@dhardy dhardy added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels May 24, 2024
@weihanglo weihanglo changed the title --all from excluded sub-directory still checks parent workspace cargo fmt --all from excluded sub-directory still checks parent workspace May 24, 2024
@newpavlov
Copy link

newpavlov commented May 24, 2024

@weihanglo
It's not only about cargo fmt, you also can run tests (e.g. cargo test -p rand_core) for packages in root workspace from an excluded crate directory. Adding [workspace] members = ["."] to excluded crates does not help.

@weihanglo
Copy link
Member

cargo fmt is actually an external subcommand implemented in rust-lang/rustfmt repository. It has different behavior than --all in other built-in commands Cargo.
(note that --all is dep created and we favor --workspace).

Here is the current implementation of cargo fmt --all. And here is a prior discussion you might be interested.

Given this is a thing managed by the Rustfmt team an issue in Cargo, please find an existing issue and reach out to them for further discussions.

@weihanglo weihanglo added Command-fmt A-workspaces Area: workspaces S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix and removed S-triage Status: This issue is waiting on initial triage. labels May 24, 2024
@weihanglo
Copy link
Member

@newpavlov Sorry I overlooked that, though that is also an expected behavior.

For the cargo test case, it is because rand_hc is a dependency of the benches package, so what cargo test -p rand_hc actually does is selecting rand_hc to test against. The same behavior applies to most build commands.

https://github.com/rust-random/rngs/blob/061af2943f51207746917ea7d6d1d422e7eb9afc/benches/Cargo.toml#L17

@dhardy
Copy link
Author

dhardy commented Jun 4, 2024

Thanks for the explanations @weihanglo.

So I can cd rand_distr then do cargo test -p num-traits for example, running tests on Cargo's cached copy of num-traits. I hadn't expected this to work and it contributed to the confusion above, but otherwise this is likely unimportant.

Given the linked rustfmt issue, it sounds like they are uninterested in being compliant with the behaviour of other Cargo commands, so I guess this issue can be closed now.

@weihanglo
Copy link
Member

Thanks for the understanding. Closing.

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-workspaces Area: workspaces C-bug Category: bug Command-fmt S-blocked-external Status: ❌ blocked on something out of the direct control of the Cargo project, e.g., upstream fix
Projects
None yet
Development

No branches or pull requests

3 participants