Skip to content

Warn about CARGO environment variable in cargo proxy #4175

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

Closed
wants to merge 9 commits into from

Conversation

smoelius
Copy link
Contributor

@smoelius smoelius commented Feb 3, 2025

Addresses rust-lang/clippy#15099

To recount the problem (copied from rust-lang/cargo#15099 (comment)):

  • The cargo proxy runs, selects the default cargo, and sets the CARGO environment variable to default toolchain's cargo.
  • That cargo invocations runs some other code, which invokes cargo +<toolchain> <subcommand>.
  • <subcommand> reads the CARGO environment variable and runs the default toolchain's cargo rather than <toolchain>'s cargo.

This PR addresses the problem by warning when the CARGO environment variable does not match what cargo +<toolchain> <subcommand> will run.

This PR is currently organized as eight commits:

Nits are welcome.

@smoelius smoelius marked this pull request as draft February 3, 2025 20:54
@smoelius smoelius changed the title Clear CARGO environment variable in cargo proxy Warn about CARGO environment variable in cargo proxy Feb 6, 2025
@smoelius
Copy link
Contributor Author

The issue was resolved in the Cargo repository, making this PR moot.

However, I humbly consider some of the PR's changes to be improvements to the testing infrastructure. For example, I think 6059cb1 (Do not append EXE_SUFFIX in Config::cmd) is a genuine bugfix

Should I submit any of the commits as separate PRs?

@djc
Copy link
Contributor

djc commented Feb 28, 2025

Should I submit any of the commits as separate PRs?

Yes, please!

@rami3l rami3l marked this pull request as draft March 1, 2025 09:57
@rami3l
Copy link
Member

rami3l commented Mar 1, 2025

@smoelius Thanks for the work! I'm interested in extracted PRs as well.

PS: Following the previous discussion, I'm now converting this PR to draft to prevent accidental merges.

smoelius added a commit to smoelius/rustup that referenced this pull request Mar 1, 2025
Previously, `Config::cmd` would always append an `EXE_SUFFIX`. However,
this would produce an invalid path if the suffix was already present.

Extracted from rust-lang#4175
smoelius added a commit to smoelius/rustup that referenced this pull request Mar 1, 2025
`SanitizedOutput`s have `String` `stdout` and `stderr` fields. This
makes `SanitizedOutput`s easier to display than `Output`s.

This commit adds a `TryFrom<Output>` implementation for
`SanitizedOutput`. In this way, a test can run a command to produce an
`Output, and from that `Output` produce a `SanitizedOutput`.

Extracted from rust-lang#4175
smoelius added a commit to smoelius/rustup that referenced this pull request Mar 1, 2025
The function `Config::run_subprocess` takes a program name and a list
of arguments, constructs a command from them, and then runs the command.

The function this commit adds is similar, but it accepts an already
constructed command.

Extracted from rust-lang#4175
smoelius added a commit to smoelius/rustup that referenced this pull request Mar 1, 2025
Currently, when the mocked cargo command is passed
`--recursive-cargo-subcommand`, it runs:

```
cargo-foo --recursive-cargo
```

However, cargo subcommands are normally passed their subcommand name as
the first argument. Thus, one would expect the following to be run:

```
cargo-foo foo --recursive-cargo
```

This commit changes the mocked cargo command to do the latter. It also
adds a check to ensure that the "subcommand name as first argument"
behavior is respected.

This is, admittedly, a rather pedantic change.

Extracted from rust-lang#4175
smoelius added a commit to smoelius/rustup that referenced this pull request Mar 1, 2025
`SanitizedOutput`s have `String` `stdout` and `stderr` fields. This
makes `SanitizedOutput`s easier to display than `Output`s.

This commit adds a `TryFrom<Output>` implementation for
`SanitizedOutput`. In this way, a test can run a command to produce an
`Output`, and from that `Output` produce a `SanitizedOutput`.

Extracted from rust-lang#4175
@smoelius smoelius closed this Mar 1, 2025
github-merge-queue bot pushed a commit that referenced this pull request Mar 2, 2025
`SanitizedOutput`s have `String` `stdout` and `stderr` fields. This
makes `SanitizedOutput`s easier to display than `Output`s.

This commit adds a `TryFrom<Output>` implementation for
`SanitizedOutput`. In this way, a test can run a command to produce an
`Output`, and from that `Output` produce a `SanitizedOutput`.

Extracted from #4175
github-merge-queue bot pushed a commit that referenced this pull request Mar 2, 2025
Currently, when the mocked cargo command is passed
`--recursive-cargo-subcommand`, it runs:

```
cargo-foo --recursive-cargo
```

However, cargo subcommands are normally passed their subcommand name as
the first argument. Thus, one would expect the following to be run:

```
cargo-foo foo --recursive-cargo
```

This commit changes the mocked cargo command to do the latter. It also
adds a check to ensure that the "subcommand name as first argument"
behavior is respected.

This is, admittedly, a rather pedantic change.

Extracted from #4175
github-merge-queue bot pushed a commit that referenced this pull request Mar 2, 2025
Previously, `Config::cmd` would always append an `EXE_SUFFIX`. However,
this would produce an invalid path if the suffix was already present.

Extracted from #4175
github-merge-queue bot pushed a commit that referenced this pull request Mar 2, 2025
Currently, when the mocked cargo command is passed
`--recursive-cargo-subcommand`, it runs:

```
cargo-foo --recursive-cargo
```

However, cargo subcommands are normally passed their subcommand name as
the first argument. Thus, one would expect the following to be run:

```
cargo-foo foo --recursive-cargo
```

This commit changes the mocked cargo command to do the latter. It also
adds a check to ensure that the "subcommand name as first argument"
behavior is respected.

This is, admittedly, a rather pedantic change.

Extracted from #4175
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.

3 participants