holmgr / cargo-sweep

A cargo subcommand for cleaning up unused build files generated by Cargo
MIT License
693 stars 31 forks source link

Don't give a hard error if we can't determine the fingerprint for a custom toolchain #67

Closed jyn514 closed 1 year ago

jyn514 commented 1 year ago

Previously, cargo sweep would unconditionally give an error when it couldn't determine the fingerprint. But for custom toolchains, it makes sense for it to be linked but give an error when you try to run it: it means the compiler hasn't yet been built.

Rather than aborting straight away, treat the toolchain as if it isn't installed and clean its artifacts.

This also gives a significantly better error message if cargo-sweep can't determine the fingerprint (which can still happen in practice if you've managed to really mess up one of your toolchains). Before:

[ERROR] Failed to clean "/home/jnelson/rust-community/cargo-sweep/target":

After:

[ERROR] Failed to clean "/home/jnelson/rust-community/cargo-sweep/target": failed to determine fingerprint for toolchain stage1: thread 'main' panicked at 'RUSTC_STAGE was not set: NotPresent', src/bootstrap/bin/rustc.rs:49:41

Fixes https://github.com/holmgr/cargo-sweep/issues/65.

elpiel commented 1 year ago

@holmgr would it be possible to take a look at this PR? Ever since I've installed cargo-sweep I cannot use the -i option because of this issue.

jyn514 commented 1 year ago

@elpiel FYI I am the current maintainer of cargo-sweep. I plan to add tests for cargo-sweep before I merge this, since it has a lot of functionality and I've never used more than one or two flags. See https://github.com/holmgr/cargo-sweep/pull/63#issuecomment-1213585613.

elpiel commented 1 year ago

Awesome! 🚀