on a549ecb help sign in
stackage/Stackage/Build.hs
99 lines 3.8 kB history raw
1module Stackage.Build
2 ( build
3 , defaultBuildSettings
4 , BuildSettings (..)
5 ) where
7import Distribution.Text (simpleParse)
8import Control.Monad (unless, when)
9import Stackage.Types
10import Stackage.CheckPlan
11import Stackage.InstallInfo
12import Stackage.Tarballs
13import Stackage.Test
14import Stackage.Util
15import Stackage.Config
16import System.Exit (ExitCode (ExitSuccess), exitWith)
17import System.IO (IOMode (WriteMode), withBinaryFile, hPutStrLn)
18import System.Process (runProcess, waitForProcess, rawSystem, readProcess)
19import System.Directory (createDirectoryIfMissing, canonicalizePath, doesDirectoryExist)
20import Distribution.Version (thisVersion, withinRange)
21import Control.Exception (assert)
23defaultBuildSettings :: BuildSettings
24defaultBuildSettings = BuildSettings
25 { sandboxRoot = "sandbox"
26 , extraBuildArgs = []
27 , extraCore = defaultExtraCore
28 , expectedFailures = defaultExpectedFailures
29 , stablePackages = defaultStablePackages
30 , extraArgs = ["-fnetwork23"]
31 , haskellPlatformCabal = "haskell-platform/haskell-platform.cabal"
32 , requireHaskellPlatform = True
33 , cleanBeforeBuild = True
34 }
36build :: BuildSettings -> IO ()
37build settings' = do
38 putStrLn "Creating a build plan"
39 ii <- getInstallInfo settings'
41 let root' = sandboxRoot settings'
42 initPkgDb <- if cleanBeforeBuild settings'
43 then do
44 putStrLn "Wiping out old sandbox folder"
45 rm_r root'
46 rm_r "logs"
47 return True
48 else do
49 b <- doesDirectoryExist root'
50 when b (putStrLn "Re-using existing sandbox")
51 return (not b)
52 createDirectoryIfMissing True root'
53 root <- canonicalizePath root'
54 let settings = settings' { sandboxRoot = root }
56 when initPkgDb $ do
57 ec1 <- rawSystem "ghc-pkg" ["init", packageDir settings]
58 unless (ec1 == ExitSuccess) $ do
59 putStrLn "Unable to create package database via ghc-pkg init"
60 exitWith ec1
61 checkPlan settings ii
62 putStrLn "No mismatches, starting the sandboxed build."
64 versionString <- readProcess "cabal" ["--version"] ""
65 libVersion <-
66 case map words $ lines versionString of
67 [_,["using","version",libVersion,"of","the","Cabal","library"]] -> return libVersion
68 _ -> error "Did not understand cabal --version output"
70 case (simpleParse libVersion, simpleParse ">= 1.16") of
71 (Nothing, _) -> error $ "Invalid Cabal library version: " ++ libVersion
72 (_, Nothing) -> assert False $ return ()
73 (Just v, Just vr)
74 | v `withinRange` vr -> return ()
75 | otherwise -> error $ "Unsupported Cabal version: " ++ libVersion
77 ph <- withBinaryFile "build.log" WriteMode $ \handle ->
78 let args = addCabalArgs settings
79 $ "install"
80 : ("--cabal-lib-version=" ++ libVersion)
81 : "--build-log=logs/$pkg.log"
82 : "-j"
83 : concat
84 [ extraBuildArgs settings
85 , extraArgs settings
86 , iiPackageList ii
87 ]
88 in do hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
89 runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
90 ec <- waitForProcess ph
91 unless (ec == ExitSuccess) $ do
92 putStrLn "Build failed, please see build.log"
93 exitWith ec
95 putStrLn "Sandbox built, beginning individual test suites"
96 runTestSuites settings ii
98 putStrLn "All test suites that were expected to pass did pass, building tarballs."
99 makeTarballs ii