on e6ec0cd help sign in
stackage/Stackage/Build.hs
113 lines 4.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.ModuleNameConflict
13import Stackage.Types
14import Stackage.Util
15import System.Exit (ExitCode (ExitSuccess), exitWith)
16import System.IO (BufferMode (NoBuffering),
17 IOMode (WriteMode), hPutStrLn,
18 hSetBuffering, withBinaryFile)
19import qualified System.IO.UTF8
20import System.Process (rawSystem, runProcess,
21 waitForProcess)
23defaultBuildSettings :: Maybe Int -- ^ argument to -j
24 -> GhcMajorVersion
25 -> BuildSettings
26defaultBuildSettings cores version = BuildSettings
27 { sandboxRoot = "sandbox"
28 , expectedFailuresBuild = defaultExpectedFailures version
29 , extraArgs = \bs -> "-fnetwork23" :
30 case bs of
31 BSTest -> []
32 _ ->
33 case cores of
34 Nothing -> ["-j"]
35 Just 1 -> []
36 Just j -> ["-j" ++ show j]
37 , testWorkerThreads = 4
38 , buildDocs = True
39 , tarballDir = "patching/tarballs"
40 , cabalFileDir = Nothing
41 }
43build :: BuildSettings -> BuildPlan -> IO ()
44build settings' bp = do
45 libVersion <- checkCabalVersion
47 putStrLn "Wiping out old sandbox folder"
48 rm_r $ sandboxRoot settings'
49 rm_r "logs"
50 settings <- fixBuildSettings settings'
52 putStrLn "Creating new package database"
53 ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
54 unless (ec1 == ExitSuccess) $ do
55 putStrLn "Unable to create package database via ghc-pkg init"
56 exitWith ec1
58 menv <- fmap Just $ getModifiedEnv settings
59 let runCabal args handle = runProcess "cabal" args Nothing menv Nothing (Just handle) (Just handle)
61 -- First install build tools so they can be used below.
62 let installBuildTool tool = do
63 let toolsDir = packageDir settings ++ "-tools"
64 rm_r toolsDir
65 ecInit <- rawSystem "ghc-pkg" ["init", toolsDir]
66 unless (ecInit == ExitSuccess) $ do
67 putStrLn "Unable to create package database via ghc-pkg init"
68 exitWith ecInit
70 putStrLn $ "Installing build tool: " ++ tool
71 ec <- withBinaryFile "build-tools.log" WriteMode $ \handle -> do
72 hSetBuffering handle NoBuffering
74 let args = addCabalArgs settings BSTools
75 $ "install"
76 : ("--cabal-lib-version=" ++ libVersion)
77 : "--build-log=logs-tools/$pkg.log"
78 : [tool]
79 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
80 ph <- runCabal args handle
81 waitForProcess ph
82 unless (ec == ExitSuccess) $ do
83 putStrLn $ concat
84 [ "Building of "
85 , tool
86 , " failed, please see build-tools.log"
87 ]
88 exitWith ec
89 putStrLn $ tool ++ " built"
90 rm_r toolsDir
91 mapM_ installBuildTool $ bpTools bp
93 putStrLn "Beginning Stackage build"
94 ph <- withBinaryFile "build.log" WriteMode $ \handle -> do
95 packageList <- mapM (replaceTarball $ tarballDir settings) $ bpPackageList bp
96 let args = addCabalArgs settings BSBuild
97 $ "install"
98 : ("--cabal-lib-version=" ++ libVersion)
99 : "--build-log=logs/$pkg.log"
100 : "--max-backjumps=-1"
101 : "--reorder-goals"
102 : packageList
103 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
104 runCabal args handle
105 ec <- waitForProcess ph
106 unless (ec == ExitSuccess) $ do
107 putStrLn "Build failed, please see build.log"
108 exitWith ec
110 putStrLn "Build completed successfully, checking for module name conflicts"
111 conflicts <- getModuleNameConflicts $ packageDir settings
112 System.IO.UTF8.writeFile "module-name-conflicts.txt"
113 $ renderModuleNameConflicts conflicts