on 02809df help sign in
stackage/Stackage/Build.hs
90 lines 3.5 kB history raw
1module Stackage.Build
2 ( build
3 , defaultBuildSettings
4 , BuildSettings (..)
5 ) where
7import Control.Monad (unless)
8import Prelude hiding (pi)
9import Stackage.CheckCabalVersion (checkCabalVersion)
10import Stackage.Config
11import Stackage.InstallInfo
12import Stackage.Types
13import Stackage.Util
14import System.Exit (ExitCode (ExitSuccess), exitWith)
15import System.IO (BufferMode (NoBuffering),
16 IOMode (WriteMode), hPutStrLn,
17 hSetBuffering, withBinaryFile)
18import System.Process (rawSystem, runProcess,
19 waitForProcess)
21defaultBuildSettings :: BuildSettings
22defaultBuildSettings = BuildSettings
23 { sandboxRoot = "sandbox"
24 , expectedFailuresBuild = defaultExpectedFailures
25 , extraArgs = const ["-fnetwork23"]
26 , testWorkerThreads = 4
27 , buildDocs = True
28 }
30build :: BuildSettings -> BuildPlan -> IO ()
31build settings' bp = do
32 libVersion <- checkCabalVersion
34 putStrLn "Wiping out old sandbox folder"
35 rm_r $ sandboxRoot settings'
36 rm_r "logs"
37 settings <- fixBuildSettings settings'
39 putStrLn "Creating new package database"
40 ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
41 unless (ec1 == ExitSuccess) $ do
42 putStrLn "Unable to create package database via ghc-pkg init"
43 exitWith ec1
45 menv <- fmap Just $ getModifiedEnv settings
46 let runCabal args handle = runProcess "cabal" args Nothing menv Nothing (Just handle) (Just handle)
48 -- First install build tools so they can be used below.
49 let installBuildTool tool = do
50 putStrLn $ "Installing build tool: " ++ tool
51 ec <- withBinaryFile "build-tools.log" WriteMode $ \handle -> do
52 hSetBuffering handle NoBuffering
54 let args = addCabalArgs settings BSBuild
55 $ "install"
56 : ("--cabal-lib-version=" ++ libVersion)
57 : "--build-log=logs-tools/$pkg.log"
58 : "-j"
59 : [tool]
60 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
61 ph <- runCabal args handle
62 waitForProcess ph
63 unless (ec == ExitSuccess) $ do
64 putStrLn $ concat
65 [ "Building of "
66 , tool
67 , " failed, please see build-tools.log"
68 ]
69 exitWith ec
70 putStrLn $ tool ++ " built"
71 mapM_ installBuildTool $ bpTools bp
73 putStrLn "Beginning Stackage build"
74 ph <- withBinaryFile "build.log" WriteMode $ \handle -> do
75 let args = addCabalArgs settings BSBuild
76 $ "install"
77 : ("--cabal-lib-version=" ++ libVersion)
78 : "--build-log=logs/$pkg.log"
79 : "--max-backjumps=-1"
80 : "--reorder-goals"
81 : "-j"
82 : concat
83 [ bpPackageList bp
84 ]
85 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
86 runCabal args handle
87 ec <- waitForProcess ph
88 unless (ec == ExitSuccess) $ do
89 putStrLn "Build failed, please see build.log"
90 exitWith ec