@@ -4,31 +4,17 @@ module Stackage.Build
4 , BuildSettings (..)
4 , BuildSettings (..)
7−import Control.Exception (assert)
7+import Control.Monad (unless)
8−import Control.Monad (unless, when)
9−import qualified Data.Map as Map
10−import Data.Maybe (mapMaybe)
11−import Data.Set (empty)
12−import qualified Data.Set as Set
13−import Distribution.Text (simpleParse)
14−import Distribution.Version (withinRange)
15import Prelude hiding (pi)
8import Prelude hiding (pi)
16−import Stackage.CheckPlan
17import Stackage.Config
9import Stackage.Config
18import Stackage.InstallInfo
10import Stackage.InstallInfo
19−import Stackage.Tarballs
21import Stackage.Types
11import Stackage.Types
22import Stackage.Util
12import Stackage.Util
23−import System.Directory (canonicalizePath,
24− createDirectoryIfMissing,
26import System.Exit (ExitCode (ExitSuccess), exitWith)
13import System.Exit (ExitCode (ExitSuccess), exitWith)
27import System.IO (IOMode (WriteMode), hPutStrLn,
14import System.IO (IOMode (WriteMode), hPutStrLn,
28 withBinaryFile)
15 withBinaryFile)
29−import System.Process (rawSystem, readProcess, runProcess,
16+import System.Process (rawSystem, runProcess,
30 waitForProcess)
17 waitForProcess)
31−import Stackage.Select (select)
32import Stackage.CheckCabalVersion (checkCabalVersion)
18import Stackage.CheckCabalVersion (checkCabalVersion)
34defaultBuildSettings :: BuildSettings
20defaultBuildSettings :: BuildSettings
@@ -74,10 +60,10 @@ build settings' bp = do
75 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
61 hPutStrLn handle ("cabal " ++ unwords (map (\s -> "'" ++ s ++ "'") args))
76 runCabal args handle
62 runCabal args handle
77− ec1 <- waitForProcess ph1
63+ ec2 <- waitForProcess ph1
78− unless (ec1 == ExitSuccess) $ do
64+ unless (ec2 == ExitSuccess) $ do
79 putStrLn "Building of build tools failed, please see build-tools.log"
65 putStrLn "Building of build tools failed, please see build-tools.log"
80− exitWith ec1
66+ exitWith ec2
81 putStrLn "Build tools built"
67 putStrLn "Build tools built"
83 ph <- withBinaryFile "build.log" WriteMode $ \handle -> do
69 ph <- withBinaryFile "build.log" WriteMode $ \handle -> do
@@ -96,33 +82,3 @@ build settings' bp = do
96 unless (ec == ExitSuccess) $ do
82 unless (ec == ExitSuccess) $ do
97 putStrLn "Build failed, please see build.log"
83 putStrLn "Build failed, please see build.log"
98 exitWith ec
84 exitWith ec
100−-- | Get all of the build tools required.
101−iiBuildTools :: InstallInfo -> [String]
102−iiBuildTools InstallInfo { iiPackageDB = PackageDB m, iiPackages = packages } =
103− -- FIXME possible improvement: track the dependencies between the build
104− -- tools themselves, and install them in the correct order.
106− $ filter (flip Set.notMember coreTools)
107− $ mapMaybe (flip Map.lookup buildToolMap)
112− $ Map.filterWithKey isSelected m
114− unPackageName (PackageName pn) = pn
115− isSelected name _ = name `Set.member` selected
116− selected = Set.fromList $ Map.keys packages
118− -- Build tools shipped with GHC which we should not attempt to build
120− coreTools = Set.fromList $ map PackageName $ words "hsc2hs"
122− -- The map from build tool name to the package it comes from.
123− buildToolMap = Map.unions $ map toBuildToolMap $ Map.toList m
124− toBuildToolMap :: (PackageName, PackageInfo) -> Map Executable PackageName
125− toBuildToolMap (pn, pi) = Map.unions
126− $ map (flip Map.singleton pn)