@@ -2,6 +2,7 @@ module Stackage.Build
5+import Distribution.Text (simpleParse)
5import Control.Monad (unless)
6import Control.Monad (unless)
6import Stackage.CheckPlan
7import Stackage.CheckPlan
7import Stackage.InstallInfo
8import Stackage.InstallInfo
@@ -10,28 +11,63 @@ import Stackage.Test
10import Stackage.Util
11import Stackage.Util
11import System.Exit (ExitCode (ExitSuccess), exitWith)
12import System.Exit (ExitCode (ExitSuccess), exitWith)
12import System.IO (IOMode (WriteMode), withBinaryFile)
13import System.IO (IOMode (WriteMode), withBinaryFile)
13−import System.Process (runProcess, waitForProcess)
14+import System.Process (runProcess, waitForProcess, rawSystem, readProcess)
15+import System.Directory (createDirectoryIfMissing, canonicalizePath)
16+import Distribution.Version (thisVersion, withinRange)
17+import Control.Exception (assert)
15−build :: IO ()
19+build :: FilePath
20+ -> ([String] -> [String]) -- ^ extra build rgs
16−build = do
22+build root' extraBuildArgs = do
17 putStrLn "Creating a build plan"
23 putStrLn "Creating a build plan"
18 ii <- getInstallInfo
24 ii <- getInstallInfo
20− putStrLn "Wiping out old cabal-dev folder"
26+ putStrLn "Wiping out old sandbox folder"
21− rm_r "cabal-dev"
27+ rm_r root'
29+ createDirectoryIfMissing True root'
30+ root <- canonicalizePath root'
32+ ec1 <- rawSystem "ghc-pkg" ["init", packageDir root]
33+ unless (ec1 == ExitSuccess) $ do
34+ putStrLn "Unable to create package database via ghc-pkg init"
37+ let extraArgs = ("-fnetwork23":)
23− checkPlan ii
39+ checkPlan (addCabalArgs root . extraArgs) ii
24 putStrLn "No mismatches, starting the sandboxed build."
40 putStrLn "No mismatches, starting the sandboxed build."
42+ versionString <- readProcess "cabal" ["--version"] ""
44+ case map words $ lines versionString of
45+ [_,["using","version",libVersion,"of","the","Cabal","library"]] -> return libVersion
46+ _ -> error "Did not understand cabal --version output"
48+ case (simpleParse libVersion, simpleParse ">= 1.16") of
49+ (Nothing, _) -> error $ "Invalid Cabal library version: " ++ libVersion
50+ (_, Nothing) -> assert False $ return ()
52+ | v `withinRange` vr -> return ()
53+ | otherwise -> error $ "Unsupported Cabal version: " ++ libVersion
26 ph <- withBinaryFile "build.log" WriteMode $ \handle ->
55 ph <- withBinaryFile "build.log" WriteMode $ \handle ->
56+ let args = addCabalArgs root
58+ : ("--cabal-lib-version=" ++ libVersion)
59+ : "--build-log=logs/$pkg.log"
62+ : (extraBuildArgs . extraArgs) (iiPackageList ii)
27− runProcess "cabal-dev" ("install":"-fnetwork23":iiPackageList ii) Nothing Nothing Nothing (Just handle) (Just handle)
63+ in runProcess "cabal" args Nothing Nothing Nothing (Just handle) (Just handle)
28 ec <- waitForProcess ph
64 ec <- waitForProcess ph
29 unless (ec == ExitSuccess) $ do
65 unless (ec == ExitSuccess) $ do
30 putStrLn "Build failed, please see build.log"
66 putStrLn "Build failed, please see build.log"
31 exitWith ec
67 exitWith ec
33 putStrLn "Sandbox built, beginning individual test suites"
69 putStrLn "Sandbox built, beginning individual test suites"
34− runTestSuites ii
70+ runTestSuites root ii
36 putStrLn "All test suites that were expected to pass did pass, building tarballs."
72 putStrLn "All test suites that were expected to pass did pass, building tarballs."
37 makeTarballs ii
73 makeTarballs ii