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 clean --release removes entire target directory without warning #6339

Closed
spearman opened this issue Nov 20, 2018 · 5 comments · Fixed by #6349
Closed

cargo clean --release removes entire target directory without warning #6339

spearman opened this issue Nov 20, 2018 · 5 comments · Fixed by #6349
Labels

Comments

@spearman
Copy link

Problem

Running $ cargo clean --release seems to silently remove the entire target directory. I would expect at least a warning that this would happen when passing the '--release' flag since the intention was to only clean the release build.

@mbrubeck
Copy link
Contributor

I'm not sure why clean even has a --release flag, since both with and without the flag, it removes both dev and release artifacts. So even if this bug were fixed, there'd be no way to remove only non-release artifacts.

@lukaslueg
Copy link
Contributor

Having taken a quick look at the tests, it seems cargo clean will always clean everything. cargo clean -p mypkg --release should only remove the release-artifacts.

@dwijnand dwijnand added the C-bug Category: bug label Nov 20, 2018
@dwijnand
Copy link
Member

Yep, I can reproduce this too:

21:39:38 $ cargo new foo
     Created binary (application) `foo` project

21:39:42 $ cd $_

21:39:44 $ cargo build
   Compiling foo v0.1.0 (/s/foo)
Finished dev [unoptimized + debuginfo] target(s) in 0.80s

21:39:56 $ cargo build --release
   Compiling foo v0.1.0 (/s/foo)
    Finished release [optimized] target(s) in 0.35s

21:39:59 $ ls -l target
total 0
drwxr-xr-x@ 12 dnw  staff  384 20 Nov 21:39 debug/
drwxr-xr-x@ 11 dnw  staff  352 20 Nov 21:39 release/

21:40:03 $ cargo clean --release

21:40:11 $ ls -l target
ls: target: No such file or directory

21:40:13 ! cargo -Vv
cargo 1.30.0 (a1a4ad372 2018-11-02)
release: 1.30.0
commit-hash: a1a4ad37271b61209cd55d21f2c83f2773cbe113
commit-date: 2018-11-02

@lukaslueg
Copy link
Contributor

cargo new foo
cd foo
cargo build
cargo build --release
cargo clean -p foo --release

leaves you with a target/debug intact. Maybe the best course of action is to disallow --release if -p is not specified?

@dwijnand
Copy link
Member

Maybe the best course of action is to disallow --release if -p is not specified?

Only if fully fixing it isn't possible, sure!

bors added a commit that referenced this issue Nov 26, 2018
Clean only release artifacts if --release option is set

Fixes #6339
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants