From 4e039251f70302fd5228451b09c35c15cb5a1574 Mon Sep 17 00:00:00 2001 From: Mel Zuser Date: Tue, 7 Dec 2021 11:24:35 -0500 Subject: [PATCH] Fix clean bug uncovered by 5fad1214 - clean was trying to read source-builds even if it didn't exist - add test specific to this case with other clean tests --- cabal-install/src/Distribution/Client/CmdClean.hs | 3 ++- .../CmdClean/CleanScriptWithNoScriptsBuilt/cabal.out | 1 + .../CmdClean/CleanScriptWithNoScriptsBuilt/cabal.test.hs | 6 ++++++ .../CmdClean/CleanScriptWithNoScriptsBuilt/script.hs | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.out create mode 100644 cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.test.hs create mode 100644 cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/script.hs diff --git a/cabal-install/src/Distribution/Client/CmdClean.hs b/cabal-install/src/Distribution/Client/CmdClean.hs index 5503df8c624..e0289602b9e 100644 --- a/cabal-install/src/Distribution/Client/CmdClean.hs +++ b/cabal-install/src/Distribution/Client/CmdClean.hs @@ -120,7 +120,8 @@ cleanAction CleanFlags{..} extraArgs _ = do -- It would be better as part of an explicit gc step (see issue #3333) toClean <- Set.fromList <$> mapM canonicalizePath extraArgs cacheDir <- getScriptCacheDirectoryRoot - caches <- listDirectory cacheDir + existsCD <- doesDirectoryExist cacheDir + caches <- if existsCD then listDirectory cacheDir else return [] paths <- fmap concat . forM caches $ \cache -> do let locFile = cacheDir cache "scriptlocation" exists <- doesFileExist locFile diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.out b/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.out new file mode 100644 index 00000000000..8bddc515089 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.out @@ -0,0 +1 @@ +# cabal v2-clean diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.test.hs b/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.test.hs new file mode 100644 index 00000000000..08b7defd89c --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/cabal.test.hs @@ -0,0 +1,6 @@ +import Test.Cabal.Prelude +import System.Environment (setEnv) +import Distribution.Client.ScriptUtils (getScriptCacheDirectory) + +main = cabalTest . void $ do + cabal' "v2-clean" ["script.hs"] diff --git a/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/script.hs b/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/script.hs new file mode 100644 index 00000000000..cd2fae4e8f4 --- /dev/null +++ b/cabal-testsuite/PackageTests/NewBuild/CmdClean/CleanScriptWithNoScriptsBuilt/script.hs @@ -0,0 +1,6 @@ +{- cabal: +build-depends: base +-} + +main :: IO () +main = putStrLn "Hello World"