@@ -5,7 +5,7 @@ module Stackage.Build
55 ) where
66
77import Distribution.Text (simpleParse)
8−import Control.Monad (unless)
8+import Control.Monad (unless, when)
99import Stackage.Types
1010import Stackage.CheckPlan
1111import Stackage.InstallInfo
@@ -14,9 +14,9 @@ import Stackage.Test
1414import Stackage.Util
1515import Stackage.Config
1616import System.Exit (ExitCode (ExitSuccess), exitWith)
17−import System.IO (IOMode (WriteMode), withBinaryFile)
17+import System.IO (IOMode (WriteMode), withBinaryFile, hPutStrLn)
1818import System.Process (runProcess, waitForProcess, rawSystem, readProcess)
19−import System.Directory (createDirectoryIfMissing, canonicalizePath)
19+import System.Directory (createDirectoryIfMissing, canonicalizePath, doesDirectoryExist)
2020import Distribution.Version (thisVersion, withinRange)
2121import Control.Exception (assert)
2222
@@ -30,6 +30,7 @@ defaultBuildSettings = BuildSettings
3030 , extraArgs = ["-fnetwork23"]
3131 , haskellPlatformCabal = "haskell-platform/haskell-platform.cabal"
3232 , requireHaskellPlatform = True
33+ , cleanBeforeBuild = True
3334 }
3435
3536build :: BuildSettings -> IO ()
@@ -37,21 +38,28 @@ build settings' = do
3738 putStrLn "Creating a build plan"
3839 ii <- getInstallInfo settings'
3940
40− putStrLn "Wiping out old sandbox folder"
4141 let root' = sandboxRoot settings'
42− rm_r root'
43− rm_r "logs"
42+ initPkgDb <- if cleanBeforeBuild settings'
43+ then do
44+ putStrLn "Wiping out old sandbox folder"
45+ rm_r root'
46+ rm_r "logs"
47+ return True
48+ else do
49+ b <- doesDirectoryExist root'
50+ when b (putStrLn "Re-using existing sandbox")
51+ return (not b)
4452 createDirectoryIfMissing True root'
4553 root <- canonicalizePath root'
4654 let settings = settings' { sandboxRoot = root }
4755
48− ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
49− unless (ec1 == ExitSuccess) $ do
50− putStrLn "Unable to create package database via ghc-pkg init"
51− exitWith ec1
52−
53− checkPlan settings ii
54− putStrLn "No mismatches, starting the sandboxed build."
56+ when initPkgDb $ do
57+ ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
58+ unless (ec1 == ExitSuccess) $ do
59+ putStrLn "Unable to create package database via ghc-pkg init"
60+ exitWith ec1
61+ checkPlan settings ii
62+ putStrLn "No mismatches, starting the sandboxed build."
5563
5664 versionString <- readProcess "cabal" ["--version"] ""
5765 libVersion <-
@@ -77,7 +85,8 @@ build settings' = do
7785 , extraArgs settings
7886 , iiPackageList ii
7987 ]
80− in runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
88+ in do hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
89+ runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
8190 ec <- waitForProcess ph
8291 unless (ec == ExitSuccess) $ do
8392 putStrLn "Build failed, please see build.log"