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: don't use Command::new(bin_name) as it won't work on Windows #750

Merged
merged 1 commit into from
Mar 24, 2024

Conversation

SteveLauC
Copy link
Member

Standards checklist:

  • The PR title is descriptive.
  • I have read CONTRIBUTING.md
  • The code compiles (cargo build)
  • The code passes rustfmt (cargo fmt)
  • The code passes clippy (cargo clippy)
  • The code passes tests (cargo test)
  • Optional: I have tested the code myself

For new steps

  • Optional: Topgrade skips this step where needed
  • Optional: The --dry-run option works with this step
  • Optional: The --yes option works with this step if it is supported by
    the underlying command

If you developed a feature or a bug fix for someone else and you do not have the
means to test it, please tag this person here.


What does this PR do

On Windows, involving a command using Command::new("binary_name") can fail with error Command not found even though the corresponding binary is installed and put somewhere under $PATH, for example, #720.

There is a Rust issue for it: rust-lang/rust#37519

A workaround is to use the which crate, which works in a way closer to how PowerShell handles cmd resolution, Topgrade's helper function require() uses which() under the hood, so this PR replaces those Command::new("binary-name-string") with Command::new(a_path_returned_from_which).

Closes #720

Copy link

codecov bot commented Mar 24, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 5.03%. Comparing base (f4e0258) to head (d0e8b7e).

Files Patch % Lines
src/steps/generic.rs 0.00% 4 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #750   +/-   ##
=====================================
  Coverage   5.03%   5.03%           
=====================================
  Files         37      37           
  Lines      12085   12085           
=====================================
  Hits         609     609           
  Misses     11476   11476           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SteveLauC SteveLauC merged commit 373cd3b into topgrade-rs:main Mar 24, 2024
18 of 19 checks passed
@SteveLauC SteveLauC deleted the fix/code_not_found_win branch March 24, 2024 03:48
@SteveLauC SteveLauC mentioned this pull request Mar 26, 2024
10 tasks
InnocentZero pushed a commit to InnocentZero/topgrade that referenced this pull request May 25, 2024
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.

VSCode installed, but winget can't execute code --version
1 participant