From cb1f824d91b5fc5675620543d68ca65f92085927 Mon Sep 17 00:00:00 2001 From: Vance Palacio Date: Wed, 31 Oct 2018 11:26:27 -0700 Subject: [PATCH 01/11] Implemented stack purge --- src/Stack/Clean.hs | 6 ++++++ src/Stack/Options/CleanParser.hs | 8 +++++--- src/main/Main.hs | 8 ++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/Stack/Clean.hs b/src/Stack/Clean.hs index c14f583b6c..168d8c4dc7 100644 --- a/src/Stack/Clean.hs +++ b/src/Stack/Clean.hs @@ -8,6 +8,7 @@ module Stack.Clean (clean ,CleanOpts(..) + ,CleanCommand(..) ,StackCleanException(..) ) where @@ -61,6 +62,11 @@ data CleanOpts | CleanFull -- ^ Delete all work directories in the project. +-- | Clean commands +data CleanCommand + = Clean + | Purge + -- | Exceptions during cleanup. newtype StackCleanException = NonLocalPackages [PackageName] diff --git a/src/Stack/Options/CleanParser.hs b/src/Stack/Options/CleanParser.hs index de566e9638..b80cf68687 100644 --- a/src/Stack/Options/CleanParser.hs +++ b/src/Stack/Options/CleanParser.hs @@ -2,13 +2,13 @@ module Stack.Options.CleanParser where import Options.Applicative -import Stack.Clean (CleanOpts (..)) +import Stack.Clean (CleanCommand(..), CleanOpts (..)) import Stack.Prelude import Stack.Types.PackageName -- | Command-line parser for the clean command. -cleanOptsParser :: Parser CleanOpts -cleanOptsParser = CleanShallow <$> packages <|> doFullClean +cleanOptsParser :: CleanCommand -> Parser CleanOpts +cleanOptsParser Clean = CleanShallow <$> packages <|> doFullClean where packages = many @@ -20,3 +20,5 @@ cleanOptsParser = CleanShallow <$> packages <|> doFullClean CleanFull (long "full" <> help "Delete all work directories (.stack-work by default) in the project") + +cleanOptsParser Purge = pure CleanFull diff --git a/src/main/Main.hs b/src/main/Main.hs index 32983637a9..981df02ad3 100644 --- a/src/main/Main.hs +++ b/src/main/Main.hs @@ -53,7 +53,7 @@ import RIO.PrettyPrint import qualified RIO.PrettyPrint as PP (style) import Stack.Build import Stack.Build.Target (NeedTargets(..)) -import Stack.Clean (CleanOpts(..), clean) +import Stack.Clean (CleanCommand(..), CleanOpts(..), clean) import Stack.Config import Stack.ConfigCmd as ConfigCmd import Stack.Constants @@ -405,7 +405,11 @@ commandLineHandler currentDir progName isInterpreter = complicatedOptions addCommand' "clean" "Clean the local packages" cleanCmd - cleanOptsParser + (cleanOptsParser Clean) + addCommand' "purge" + "Delete all work directories (.stack-work by default) in the project. Shortcut for 'stack clean --full'" + cleanCmd + (cleanOptsParser Purge) addCommand' "list-dependencies" "List the dependencies" (listDependenciesCmd True) From d4d73529cd9c92963a8af613badf21c24cd79551 Mon Sep 17 00:00:00 2001 From: Vance Palacio Date: Wed, 31 Oct 2018 11:57:35 -0700 Subject: [PATCH 02/11] Updated comment for clean shallow. (No fix was needed) --- src/Stack/Clean.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stack/Clean.hs b/src/Stack/Clean.hs index 168d8c4dc7..05b87e1a07 100644 --- a/src/Stack/Clean.hs +++ b/src/Stack/Clean.hs @@ -56,7 +56,7 @@ dirsToDelete cleanOpts = do -- | Options for @stack clean@. data CleanOpts = CleanShallow [PackageName] - -- ^ Delete the "dist directories" as defined in 'Stack.Constants.distRelativeDir' + -- ^ Delete the "dist directories" as defined in 'Stack.Constants.Config.distRelativeDir' -- for the given local packages. If no packages are given, all project packages -- should be cleaned. | CleanFull From bac2fcfdcd9caa3dc8351c641a9ad8d3958fc965 Mon Sep 17 00:00:00 2001 From: Vance Palacio Date: Fri, 2 Nov 2018 12:02:42 -0700 Subject: [PATCH 03/11] Updated docs for stack clean --- doc/GUIDE.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/doc/GUIDE.md b/doc/GUIDE.md index 850cf64fbd..708f24e67f 100644 --- a/doc/GUIDE.md +++ b/doc/GUIDE.md @@ -280,6 +280,23 @@ As you can see from that path (and as emphasized earlier), the installation is placed to not interfere with any other GHC installation, whether system-wide or even different GHC versions installed by stack. +## Cleaning your project +You can clean up build artifacts for your project using the `stack clean` and `stack purge`. + +### `stack clean` +`stack clean` Deletes the local working directories containing compiler output. +(typically '.stack-work/dist' by default) + +Use `stack clean ` to delete the output for a package specific-package only. + +### `stack purge` +`stack purge` Deletes the local stack working directory, including extra-deps, git dependencies and the compiler output. +It does not delete any snapshot packages, compilers or installed programs. -- This essentially +reverts your project to a completely fresh state, as if it had never been built. +`stack purge` is just a shortcut for `stack clean --full` + +- Note: `stack purge` is not available when used in docker + ### The build command The build command is the heart and soul of stack. It is the engine that powers From caa2b9baee6d525f41c41eec38e3a775eea408b4 Mon Sep 17 00:00:00 2001 From: Vance Palacio Date: Fri, 2 Nov 2018 12:52:09 -0700 Subject: [PATCH 04/11] Updated help messages for stack clean and purge --- src/Stack/Options/CleanParser.hs | 2 +- src/main/Main.hs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Stack/Options/CleanParser.hs b/src/Stack/Options/CleanParser.hs index b80cf68687..edd124bcf5 100644 --- a/src/Stack/Options/CleanParser.hs +++ b/src/Stack/Options/CleanParser.hs @@ -19,6 +19,6 @@ cleanOptsParser Clean = CleanShallow <$> packages <|> doFullClean flag' CleanFull (long "full" <> - help "Delete all work directories (.stack-work by default) in the project") + help "Delete the local stack working directory (.stack-work by default).") cleanOptsParser Purge = pure CleanFull diff --git a/src/main/Main.hs b/src/main/Main.hs index 981df02ad3..6804591870 100644 --- a/src/main/Main.hs +++ b/src/main/Main.hs @@ -407,7 +407,7 @@ commandLineHandler currentDir progName isInterpreter = complicatedOptions cleanCmd (cleanOptsParser Clean) addCommand' "purge" - "Delete all work directories (.stack-work by default) in the project. Shortcut for 'stack clean --full'" + "Delete the local stack working directory (.stack-work by default). Shortcut for 'stack clean --full'" cleanCmd (cleanOptsParser Purge) addCommand' "list-dependencies" From 23d534d98449a9d36f9b4707282b29e32226ea81 Mon Sep 17 00:00:00 2001 From: dbaynard Date: Wed, 7 Nov 2018 11:11:38 -0800 Subject: [PATCH 05/11] fix docs wording Co-Authored-By: vanceism7 --- doc/GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/GUIDE.md b/doc/GUIDE.md index 708f24e67f..988391896f 100644 --- a/doc/GUIDE.md +++ b/doc/GUIDE.md @@ -287,7 +287,7 @@ You can clean up build artifacts for your project using the `stack clean` and `s `stack clean` Deletes the local working directories containing compiler output. (typically '.stack-work/dist' by default) -Use `stack clean ` to delete the output for a package specific-package only. +Use `stack clean ` to delete the output for a package _specific-package_ only. ### `stack purge` `stack purge` Deletes the local stack working directory, including extra-deps, git dependencies and the compiler output. From 854593bc407bcfc653c5ccc96fe68245a7fcf8c1 Mon Sep 17 00:00:00 2001 From: Matt Audesse Date: Thu, 8 Nov 2018 20:54:00 -0800 Subject: [PATCH 06/11] fixed wording Co-Authored-By: vanceism7 --- doc/GUIDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/GUIDE.md b/doc/GUIDE.md index 988391896f..f8740b9e54 100644 --- a/doc/GUIDE.md +++ b/doc/GUIDE.md @@ -281,7 +281,7 @@ placed to not interfere with any other GHC installation, whether system-wide or even different GHC versions installed by stack. ## Cleaning your project -You can clean up build artifacts for your project using the `stack clean` and `stack purge`. +You can clean up build artifacts for your project using the `stack clean` and `stack purge` commands. ### `stack clean` `stack clean` Deletes the local working directories containing compiler output. From dad8f922607cee9b8aacec8806a2944d2d03b032 Mon Sep 17 00:00:00 2001 From: dbaynard Date: Sat, 17 Nov 2018 20:52:10 +0100 Subject: [PATCH 07/11] Clarify differences between clean and purge --- doc/GUIDE.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/GUIDE.md b/doc/GUIDE.md index f8740b9e54..a558176323 100644 --- a/doc/GUIDE.md +++ b/doc/GUIDE.md @@ -281,18 +281,21 @@ placed to not interfere with any other GHC installation, whether system-wide or even different GHC versions installed by stack. ## Cleaning your project + You can clean up build artifacts for your project using the `stack clean` and `stack purge` commands. ### `stack clean` -`stack clean` Deletes the local working directories containing compiler output. -(typically '.stack-work/dist' by default) -Use `stack clean ` to delete the output for a package _specific-package_ only. +`stack clean` deletes the local working directories containing compiler output. +By default, that means the contents of directories in `.stack-work/dist`, for all the `.stack-work` directories within a project. + +Use `stack clean ` to delete the output for the package _specific-package_ only. ### `stack purge` -`stack purge` Deletes the local stack working directory, including extra-deps, git dependencies and the compiler output. -It does not delete any snapshot packages, compilers or installed programs. -- This essentially -reverts your project to a completely fresh state, as if it had never been built. + +`stack purge` deletes the local stack working directories, including extra-deps, git dependencies and the compiler output (including logs). +It does not delete any snapshot packages, compilers or programs installed using `stack install`. This essentially +reverts the project to a completely fresh state, as if it had never been built. `stack purge` is just a shortcut for `stack clean --full` - Note: `stack purge` is not available when used in docker From ccba7f2e2730d1960d0b81532b5698066aee6685 Mon Sep 17 00:00:00 2001 From: dbaynard Date: Sat, 17 Nov 2018 20:53:38 +0100 Subject: [PATCH 08/11] Improve description of --full --- src/Stack/Options/CleanParser.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Stack/Options/CleanParser.hs b/src/Stack/Options/CleanParser.hs index edd124bcf5..b90845ff05 100644 --- a/src/Stack/Options/CleanParser.hs +++ b/src/Stack/Options/CleanParser.hs @@ -14,11 +14,11 @@ cleanOptsParser Clean = CleanShallow <$> packages <|> doFullClean many (packageNameArgument (metavar "PACKAGE" <> - help "If none specified, clean all local packages")) + help "If none specified, clean all project packages")) doFullClean = flag' CleanFull (long "full" <> - help "Delete the local stack working directory (.stack-work by default).") + help "Delete the project’s stack working directories (.stack-work by default).") cleanOptsParser Purge = pure CleanFull From 9ccfdabcacf0fa40c65cd5c7070362644c6ecd79 Mon Sep 17 00:00:00 2001 From: dbaynard Date: Sat, 17 Nov 2018 21:05:28 +0100 Subject: [PATCH 09/11] Clarify clean and purge help text --- src/main/Main.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/Main.hs b/src/main/Main.hs index 6804591870..09e04174ac 100644 --- a/src/main/Main.hs +++ b/src/main/Main.hs @@ -403,11 +403,11 @@ commandLineHandler currentDir progName isInterpreter = complicatedOptions evalCmd (evalOptsParser "CODE") addCommand' "clean" - "Clean the local packages" + "Delete build artefacts for the project packages." cleanCmd (cleanOptsParser Clean) addCommand' "purge" - "Delete the local stack working directory (.stack-work by default). Shortcut for 'stack clean --full'" + "Delete the project stack working directories (.stack-work by default). Shortcut for 'stack clean --full'" cleanCmd (cleanOptsParser Purge) addCommand' "list-dependencies" From 97f280b618b81700da0d58d841f8c0a6493f0c85 Mon Sep 17 00:00:00 2001 From: Vance Palacio Date: Wed, 28 Nov 2018 20:21:38 -0800 Subject: [PATCH 10/11] Added stack purge integration test --- test/integration/tests/3863-purge-command/Main.hs | 7 +++++++ .../tests/3863-purge-command/files/new-template.cabal | 11 +++++++++++ .../tests/3863-purge-command/files/src/Lib.hs | 4 ++++ .../tests/3863-purge-command/files/stack.yaml | 5 +++++ 4 files changed, 27 insertions(+) create mode 100644 test/integration/tests/3863-purge-command/Main.hs create mode 100644 test/integration/tests/3863-purge-command/files/new-template.cabal create mode 100644 test/integration/tests/3863-purge-command/files/src/Lib.hs create mode 100644 test/integration/tests/3863-purge-command/files/stack.yaml diff --git a/test/integration/tests/3863-purge-command/Main.hs b/test/integration/tests/3863-purge-command/Main.hs new file mode 100644 index 0000000000..ec56caa206 --- /dev/null +++ b/test/integration/tests/3863-purge-command/Main.hs @@ -0,0 +1,7 @@ +import StackTest +import System.Directory + +main :: IO () +main = do + stack ["build"] + stack ["purge"] diff --git a/test/integration/tests/3863-purge-command/files/new-template.cabal b/test/integration/tests/3863-purge-command/files/new-template.cabal new file mode 100644 index 0000000000..192e0b2dfb --- /dev/null +++ b/test/integration/tests/3863-purge-command/files/new-template.cabal @@ -0,0 +1,11 @@ +name: new-template +version: 0.1.0.0 +build-type: Simple +cabal-version: >=1.10 + + +library + hs-source-dirs: src + exposed-modules: Lib + build-depends: base >= 4.7 && < 5 + default-language: Haskell2010 diff --git a/test/integration/tests/3863-purge-command/files/src/Lib.hs b/test/integration/tests/3863-purge-command/files/src/Lib.hs new file mode 100644 index 0000000000..1c88a82644 --- /dev/null +++ b/test/integration/tests/3863-purge-command/files/src/Lib.hs @@ -0,0 +1,4 @@ +module Lib where + +someFunc :: () +someFunc = () diff --git a/test/integration/tests/3863-purge-command/files/stack.yaml b/test/integration/tests/3863-purge-command/files/stack.yaml new file mode 100644 index 0000000000..227c646ed3 --- /dev/null +++ b/test/integration/tests/3863-purge-command/files/stack.yaml @@ -0,0 +1,5 @@ +flags: {} +packages: +- '.' +extra-deps: [] +resolver: lts-11.22 From 893a8b7faa4bed83de6fcf1ee96d1cfd00e73e18 Mon Sep 17 00:00:00 2001 From: David Baynard Date: Sun, 10 Feb 2019 22:41:02 +0000 Subject: [PATCH 11/11] Check correct directory deletion behaviour for simple project - The integration test ensures the correct directories are present, then deleted, for a project with only one package, not in a subdirectory. --- .../tests/3863-purge-command/Main.hs | 38 +++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/test/integration/tests/3863-purge-command/Main.hs b/test/integration/tests/3863-purge-command/Main.hs index ec56caa206..4c54e19faa 100644 --- a/test/integration/tests/3863-purge-command/Main.hs +++ b/test/integration/tests/3863-purge-command/Main.hs @@ -1,7 +1,39 @@ import StackTest +import Data.Maybe (listToMaybe, fromMaybe) import System.Directory +import System.FilePath main :: IO () -main = do - stack ["build"] - stack ["purge"] +main = + -- For these commands, we'll need to know the `dist` directory. + -- This is usually `.stack-work/dist/$compiler-variant/Cabal-xxxx` + stackCheckStdout [defaultResolverArg, "path", "--dist-dir"] $ \distDir -> + + stackCheckStdout [defaultResolverArg, "path", "--local-install-root"] $ \localInstallRoot -> do + + -- Usually `.stack-work` + let stackWork = fromMaybe (error "There must be a stack working directory.") $ + listToMaybe (splitDirectories distDir) + + -- First, clean the .stack-work directory. + -- This is only necessary when running individual tests. + stack [defaultResolverArg, "purge"] + doesNotExist stackWork + + -- The dist directory should exist after a build + stack [defaultResolverArg, "build"] + doesExist distDir + doesExist localInstallRoot + doesExist stackWork + + -- The dist directory should not exist after a clean, whereas the + -- .stack-work directory should + stack [defaultResolverArg, "clean"] + run "exa" ["-T", ".stack-work"] + doesNotExist distDir + doesExist localInstallRoot + doesExist stackWork + + -- The .stack-work directory should not exist after a purge + stack [defaultResolverArg, "purge"] + doesNotExist stackWork