on master help sign in
Option "--no-clean" for the build command
f9391c0Stefan Wehr
Stackage/Build.hs+23−14
@@ -5,7 +5,7 @@ module Stackage.Build
5 ) where
5 ) where
6
6
7import Distribution.Text (simpleParse)
7import Distribution.Text (simpleParse)
8−import Control.Monad (unless)
8+import Control.Monad (unless, when)
9import Stackage.Types
9import Stackage.Types
10import Stackage.CheckPlan
10import Stackage.CheckPlan
11import Stackage.InstallInfo
11import Stackage.InstallInfo
@@ -14,9 +14,9 @@ import Stackage.Test
14import Stackage.Util
14import Stackage.Util
15import Stackage.Config
15import Stackage.Config
16import System.Exit (ExitCode (ExitSuccess), exitWith)
16import System.Exit (ExitCode (ExitSuccess), exitWith)
17−import System.IO (IOMode (WriteMode), withBinaryFile)
17+import System.IO (IOMode (WriteMode), withBinaryFile, hPutStrLn)
18import System.Process (runProcess, waitForProcess, rawSystem, readProcess)
18import System.Process (runProcess, waitForProcess, rawSystem, readProcess)
19−import System.Directory (createDirectoryIfMissing, canonicalizePath)
19+import System.Directory (createDirectoryIfMissing, canonicalizePath, doesDirectoryExist)
20import Distribution.Version (thisVersion, withinRange)
20import Distribution.Version (thisVersion, withinRange)
21import Control.Exception (assert)
21import Control.Exception (assert)
22
22
@@ -30,6 +30,7 @@ defaultBuildSettings = BuildSettings
30 , extraArgs = ["-fnetwork23"]
30 , extraArgs = ["-fnetwork23"]
31 , haskellPlatformCabal = "haskell-platform/haskell-platform.cabal"
31 , haskellPlatformCabal = "haskell-platform/haskell-platform.cabal"
32 , requireHaskellPlatform = True
32 , requireHaskellPlatform = True
33+ , cleanBeforeBuild = True
33 }
34 }
34
35
35build :: BuildSettings -> IO ()
36build :: BuildSettings -> IO ()
@@ -37,21 +38,28 @@ build settings' = do
37 putStrLn "Creating a build plan"
38 putStrLn "Creating a build plan"
38 ii <- getInstallInfo settings'
39 ii <- getInstallInfo settings'
39
40
40− putStrLn "Wiping out old sandbox folder"
41 let root' = sandboxRoot settings'
41 let root' = sandboxRoot settings'
42+ initPkgDb <- if cleanBeforeBuild settings'
43+ then do
44+ putStrLn "Wiping out old sandbox folder"
42− rm_r root'
45+ rm_r root'
43− rm_r "logs"
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)
44 createDirectoryIfMissing True root'
52 createDirectoryIfMissing True root'
45 root <- canonicalizePath root'
53 root <- canonicalizePath root'
46 let settings = settings' { sandboxRoot = root }
54 let settings = settings' { sandboxRoot = root }
47
55
56+ when initPkgDb $ do
48− ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
57+ ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
49− unless (ec1 == ExitSuccess) $ do
58+ unless (ec1 == ExitSuccess) $ do
50− putStrLn "Unable to create package database via ghc-pkg init"
59+ putStrLn "Unable to create package database via ghc-pkg init"
51− exitWith ec1
60+ exitWith ec1
52−
53− checkPlan settings ii
61+ checkPlan settings ii
54− putStrLn "No mismatches, starting the sandboxed build."
62+ putStrLn "No mismatches, starting the sandboxed build."
55
63
56 versionString <- readProcess "cabal" ["--version"] ""
64 versionString <- readProcess "cabal" ["--version"] ""
57 libVersion <-
65 libVersion <-
@@ -77,7 +85,8 @@ build settings' = do
77 , extraArgs settings
85 , extraArgs settings
78 , iiPackageList ii
86 , iiPackageList ii
79 ]
87 ]
88+ in do hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
80− in runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
89+ runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
81 ec <- waitForProcess ph
90 ec <- waitForProcess ph
82 unless (ec == ExitSuccess) $ do
91 unless (ec == ExitSuccess) $ do
83 putStrLn "Build failed, please see build.log"
92 putStrLn "Build failed, please see build.log"
Stackage/Types.hs+1
@@ -63,4 +63,5 @@ data BuildSettings = BuildSettings
63 , extraArgs :: [String]
63 , extraArgs :: [String]
64 , haskellPlatformCabal :: FilePath
64 , haskellPlatformCabal :: FilePath
65 , requireHaskellPlatform :: Bool
65 , requireHaskellPlatform :: Bool
66+ , cleanBeforeBuild :: Bool
66 }
67 }
app/stackage.hs+5−3
@@ -1,3 +1,4 @@
1+import Stackage.Types (BuildSettings(..))
1import Stackage.Build (build, defaultBuildSettings)
2import Stackage.Build (build, defaultBuildSettings)
2import Stackage.Init (stackageInit)
3import Stackage.Init (stackageInit)
3import System.Environment (getArgs, getProgName)
4import System.Environment (getArgs, getProgName)
@@ -7,12 +8,13 @@ main = do
7 args <- getArgs
8 args <- getArgs
8 case args of
9 case args of
9 ["build"] -> build defaultBuildSettings
10 ["build"] -> build defaultBuildSettings
11+ ["build", "--no-clean"] -> build (defaultBuildSettings { cleanBeforeBuild = False })
10 ["init"] -> stackageInit
12 ["init"] -> stackageInit
11 ["update"] -> stackageInit >> error "FIXME update"
13 ["update"] -> stackageInit >> error "FIXME update"
12 _ -> do
14 _ -> do
13 pn <- getProgName
15 pn <- getProgName
14 putStrLn $ "Usage: " ++ pn ++ " <command>"
16 putStrLn $ "Usage: " ++ pn ++ " <command>"
15 putStrLn "Available commands:"
17 putStrLn "Available commands:"
16− putStrLn " update Download updated Stackage databases. Automatically calls init."
18+ putStrLn " update Download updated Stackage databases. Automatically calls init."
17− putStrLn " init Initialize your cabal file to use Stackage"
19+ putStrLn " init Initialize your cabal file to use Stackage"
18− putStrLn " build Build the package databases (maintainers only)"
20+ putStrLn " build [--no-clean] Build the package databases (maintainers only)"