Several times I have been caught out by expecting stack clean to reset state and fix some transient failure, then finding out that only removing the .stack-work directories was sufficient. And I have only just now discovered stack clean --full. In the most recent example two of us spent several hours troubleshooting weird NFData version-skew-ish doctest failures on one machine, which stack clean did not fix. Somewhat related: #2278, #2936 and #3152.
We were using stack 1.6.3 (and recent HEAD in my case). I don't know how to reproduce the failure state. I expected clean to reset state and be pretty much equivalent to starting with fresh clone of the project. Instead the doctest failures persisted until we tried a fresh clone (and then remembered to try manually removing .stack-work). clean's --full flag was not obvious.
Makes sense to me. In favor of deprecating --full, and adding a flag to instead just use cabal clean.
Stupid question: with this enhancement, will stack clean fail if cabal is not already on PATH?
@adrianwong Nope, the cabal command is the cabal-install package / executable, which stack only uses for solver and building ghcjs. The usage of cabal for cleaning is instead using the compiled Setup.hs. For simple build types, the Setup.hs is a simple invocation of a function in the Cabal library. So, in a way there are two different libraries / executables that are both called "cabal", and stack mostly just uses the lower level one, called Cabal.
I can try my hand at this one if no one else is doing it yet
Hey @mgsloan, do you mean to just add a warning in the cli when the --full flag is used, and adding a new flag like --shallow? Or should I add a new clean command which actually does a full clean by default (In addition to the deprecated warnings)?
@vanceism7 I believe I meant the latter - that clean would do --full by default, and some other flag cause it to do cabal cleans.
It is possible that might not be an expected behavior change. Perhaps it would be safer to require specifying either --shallow (or some other name) or --full. Perhaps @mihaimaruseac , @snoyberg , or some other maintainer has an opinion on what to do here?
The behaviour of --full is more like a purge. If the concern is changing existing behaviour, then introducing stack purge as a synonym for stack clean --full would help. In particular, as a new command, it would be listed alongside clean and would make clear that clean doesn't clear everything.
It is still not clear from the docs what stack clean means — would it be accurate to say the following?
stack cleanDelete the local working directories containing compiler output. e.g. …
Use
stack clean <specific-package>to delete the output for package specific-package only.
stack purgeDelete the local stack working directory, including extra-deps, git dependencies and the compiler output. Does not delete any snapshot packages, compilers or installed programs.
Also
should point to Stack.Constants.Config.distRelativeDir.
Yea, the main issue I was thinking about is preserving backward compatibility. But I think in general it makes sense to use a stack purge command/synonym instead of changing the default behavior of clean. From my experience with other systems (such as dotnet cli), clean only deletes any files generated in a build, it doesn't clear out the entire bin folder. I'll add stack purge and see what I can do to make the documentation a little clearer. Thanks for the input everyone!
@simonmichael Would you please confirm that this would resolve your issue?
Hi @dbaynard, I think:
After rereading this, I'll qualify: my first three points are debatable, perhaps. I'm more confident about the last two. But my main desires are:
If half-cleaning remains the default, printing a note explaining what was cleaned and how to clean more thoroughly could be another option.
Our team uses stack all day for working on a large project with a lot of dependencies. We occasionally need to do rm -rf .stack-work, but it is painful.
We expect stack clean to do the same thing that clean does for every other build tool I know - remove the build artifacts and cause all modules within the local project to be rebuilt. We do not need an alias for rm -fr .stack-work; we can type that ourselves. It's OK if that is provided, similar to "distclean" in other build tools, but it would be a surprising default for stack clean.
Others may have different preferences. The world won't come to an end for us if we are outvoted and stack clean is changed to be like distclean instead of clean. I think the biggest issue here is poor documentation #2278, as mentioned by @simonmichael.
- to reset to a known state, for predictable builds and to drive out ghosts;
This is what stack clean by itself will do, by deleting the build artefacts.
See #4480 for further discussion.
We do not need an alias for
rm -fr .stack-work; we can type that ourselves.
There are multiple .stack-work directories for a project, and the clean command ought to handle them.
None of this discussion concerns issues with shared artefacts, e.g. snapshot dependencies. clean currently does nothing for any ghosts there.
Most helpful comment
I can try my hand at this one if no one else is doing it yet