on 37726ac help sign in
stackage/Stackage/Build.hs
98 lines 4.0 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 :: GhcMajorVersion -> BuildSettings
22defaultBuildSettings version = BuildSettings
23 { sandboxRoot = "sandbox"
24 , expectedFailuresBuild = defaultExpectedFailures version
25 , extraArgs = const ["-fnetwork23"]
26 , testWorkerThreads = 4
27 , buildDocs = True
28 , tarballDir = "patching/tarballs"
29 }
31build :: BuildSettings -> BuildPlan -> IO ()
32build settings' bp = do
33 libVersion <- checkCabalVersion
35 putStrLn "Wiping out old sandbox folder"
36 rm_r $ sandboxRoot settings'
37 rm_r "logs"
38 settings <- fixBuildSettings settings'
40 putStrLn "Creating new package database"
41 ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
42 unless (ec1 == ExitSuccess) $ do
43 putStrLn "Unable to create package database via ghc-pkg init"
44 exitWith ec1
46 menv <- fmap Just $ getModifiedEnv settings
47 let runCabal args handle = runProcess "cabal" args Nothing menv Nothing (Just handle) (Just handle)
49 -- First install build tools so they can be used below.
50 let installBuildTool tool = do
51 let toolsDir = packageDir settings ++ "-tools"
52 rm_r toolsDir
53 ecInit <- rawSystem "ghc-pkg" ["init", toolsDir]
54 unless (ecInit == ExitSuccess) $ do
55 putStrLn "Unable to create package database via ghc-pkg init"
56 exitWith ecInit
58 putStrLn $ "Installing build tool: " ++ tool
59 ec <- withBinaryFile "build-tools.log" WriteMode $ \handle -> do
60 hSetBuffering handle NoBuffering
62 let args = addCabalArgs settings BSTools
63 $ "install"
64 : ("--cabal-lib-version=" ++ libVersion)
65 : "--build-log=logs-tools/$pkg.log"
66 : "-j"
67 : [tool]
68 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
69 ph <- runCabal args handle
70 waitForProcess ph
71 unless (ec == ExitSuccess) $ do
72 putStrLn $ concat
73 [ "Building of "
74 , tool
75 , " failed, please see build-tools.log"
76 ]
77 exitWith ec
78 putStrLn $ tool ++ " built"
79 rm_r toolsDir
80 mapM_ installBuildTool $ bpTools bp
82 putStrLn "Beginning Stackage build"
83 ph <- withBinaryFile "build.log" WriteMode $ \handle -> do
84 packageList <- mapM (replaceTarball $ tarballDir settings) $ bpPackageList bp
85 let args = addCabalArgs settings BSBuild
86 $ "install"
87 : ("--cabal-lib-version=" ++ libVersion)
88 : "--build-log=logs/$pkg.log"
89 : "--max-backjumps=-1"
90 : "--reorder-goals"
91 : "-j"
92 : packageList
93 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
94 runCabal args handle
95 ec <- waitForProcess ph
96 unless (ec == ExitSuccess) $ do
97 putStrLn "Build failed, please see build.log"
98 exitWith ec