holmgr / cargo-sweep

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

cargo-sweep should ignore custom toolchains #65

Closed jyn514 closed 1 year ago

jyn514 commented 2 years ago

I installed a custom version of rust from source (with x.py) and then cleaned the target directory. Now cargo sweep -i doesn't work. Instead of giving a hard error, it should just skip custom toolchains and continue sweeping all others.

$ cargo sweep -i
[INFO] Using all installed toolchains: ["stable-x86_64-unknown-linux-gnu", "beta-x86_64-unknown-linux-gnu", "nightly-2021-07-17-x86_64-unknown-linux-gnu", "nightly-2021-07-19-x86_64-unknown-linux-gnu", "nightly-2021-07-23-x86_64-unknown-linux-gnu", "nightly-2021-12-30-x86_64-unknown-linux-gnu", "nightly-x86_64-unknown-linux-gnu", "1.42-x86_64-unknown-linux-gnu", "1.43-x86_64-unknown-linux-gnu", "1.44-x86_64-unknown-linux-gnu", "1.45-x86_64-unknown-linux-gnu", "1.47-x86_64-unknown-linux-gnu", "1.50-x86_64-unknown-linux-gnu", "1.51-x86_64-unknown-linux-gnu", "1.54-x86_64-unknown-linux-gnu", "1.57-x86_64-unknown-linux-gnu", "wasi", "1.46.0-x86_64-unknown-linux-gnu", "1.49.0-x86_64-unknown-linux-gnu", "1.53.0-x86_64-unknown-linux-gnu", "1.55.0-x86_64-unknown-linux-gnu"]
[ERROR] Failed to clean "/home/jnelson/redacted/target": 
$ cargo +wasi -vV
error: toolchain 'wasi' is not installed
$ rustup toolchain list -v | grep -v -
wasi    /home/jnelson/src/rust/out
jyn514 commented 2 years ago

I just checked and rustup prevents you from naming custom toolchains things that could be a version number:

$ rustup toolchain link 1.52.0 /home/jnelson/rust-lang/rust/out
error: invalid custom toolchain name: '1.52.0-x86_64-unknown-linux-gnu'
$ rustup toolchain link beta /home/jnelson/rust-lang/rust/out
error: invalid custom toolchain name: 'beta-x86_64-unknown-linux-gnu'
$ rustup toolchain link stable /home/jnelson/rust-lang/rust/out
error: invalid custom toolchain name: 'stable-x86_64-unknown-linux-gnu'
$ rustup toolchain link nightly /home/jnelson/rust-lang/rust/out
error: invalid custom toolchain name: 'nightly-x86_64-unknown-linux-gnu'

So it should be possible to tell if toolchains are custom by seeing if they match \d+\.\d+(:?\.\d+).* or stable/beta/nightly or not.