on a2f2434 help sign in
stackage/Stackage/Build.hs
88 lines 3.4 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 (IOMode (WriteMode), hPutStrLn,
16 withBinaryFile)
17import System.Process (rawSystem, runProcess,
18 waitForProcess)
20defaultBuildSettings :: BuildSettings
21defaultBuildSettings = BuildSettings
22 { sandboxRoot = "sandbox"
23 , expectedFailuresBuild = defaultExpectedFailures
24 , extraArgs = ["-fnetwork23"]
25 , testWorkerThreads = 4
26 }
28build :: BuildSettings -> BuildPlan -> IO ()
29build settings' bp = do
30 libVersion <- checkCabalVersion
32 putStrLn "Wiping out old sandbox folder"
33 rm_r $ sandboxRoot settings'
34 rm_r "logs"
35 settings <- fixBuildSettings settings'
37 putStrLn "Creating new package database"
38 ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
39 unless (ec1 == ExitSuccess) $ do
40 putStrLn "Unable to create package database via ghc-pkg init"
41 exitWith ec1
43 menv <- fmap Just $ getModifiedEnv settings
44 let runCabal args handle = runProcess "cabal" args Nothing menv Nothing (Just handle) (Just handle)
46 -- First install build tools so they can be used below.
47 let installBuildTool tool = do
48 putStrLn $ "Installing build tool: " ++ tool
49 ec <- withBinaryFile "build-tools.log" WriteMode $ \handle -> do
50 let args = addCabalArgs settings
51 $ "install"
52 : ("--cabal-lib-version=" ++ libVersion)
53 : "--build-log=logs-tools/$pkg.log"
54 : "-j"
55 : concat
56 [ extraArgs settings
57 , [tool]
58 ]
59 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
60 ph <- runCabal args handle
61 waitForProcess ph
62 unless (ec == ExitSuccess) $ do
63 putStrLn $ concat
64 [ "Building of "
65 , tool
66 , " failed, please see build-tools.log"
67 ]
68 exitWith ec
69 putStrLn $ tool ++ " built"
70 mapM_ installBuildTool $ bpTools bp
72 putStrLn "Beginning Stackage build"
73 ph <- withBinaryFile "build.log" WriteMode $ \handle -> do
74 let args = addCabalArgs settings
75 $ "install"
76 : ("--cabal-lib-version=" ++ libVersion)
77 : "--build-log=logs/$pkg.log"
78 : "-j"
79 : concat
80 [ extraArgs settings
81 , bpPackageList bp
82 ]
83 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
84 runCabal args handle
85 ec <- waitForProcess ph
86 unless (ec == ExitSuccess) $ do
87 putStrLn "Build failed, please see build.log"
88 exitWith ec