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