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