1{-# LANGUAGE DeriveDataTypeable #-}
2{-# LANGUAGE NoImplicitPrelude #-}
3{-# LANGUAGE OverloadedStrings #-}
4{-# LANGUAGE RecordWildCards #-}
5{-# LANGUAGE ScopedTypeVariables #-}
6module Stackage.InstallBuild
12import qualified Codec.Archive.Tar as Tar
13import qualified Codec.Compression.GZip as GZip
14import qualified Data.Yaml as Yaml
15import Network.HTTP.Client
16import Network.HTTP.Client.TLS (tlsManagerSettings)
17import Stackage.BuildPlan
18import Stackage.CheckBuildPlan
19import Stackage.PerformBuild
20import Stackage.Prelude
21import System.IO (BufferMode (LineBuffering), hSetBuffering)
23-- | Flags passed in from the command line.
24data InstallFlags = InstallFlags
25 { ifPlanSource :: !BuildPlanSource
26 , ifInstallDest :: !FilePath
27 , ifLogDir :: !(Maybe FilePath)
29 , ifGlobalInstall :: !Bool
30 , ifEnableTests :: !Bool
31 , ifEnableHaddock :: !Bool
32 , ifEnableLibProfiling :: !Bool
33 , ifEnableExecDyn :: !Bool
35 , ifSkipCheck :: !Bool
36 , ifBuildHoogle :: !Bool
39-- | Source for build plan.
40data BuildPlanSource = BPSBundleWeb String
44getPerformBuild :: BuildPlan -> InstallFlags -> PerformBuild
45getPerformBuild plan InstallFlags{..} =
48 , pbInstallDest = ifInstallDest
49 , pbLogDir = fromMaybe (ifInstallDest </> "logs") ifLogDir
52 , pbGlobalInstall = ifGlobalInstall
53 , pbEnableTests = ifEnableTests
54 , pbEnableHaddock = ifEnableHaddock
55 , pbEnableLibProfiling = ifEnableLibProfiling
56 , pbEnableExecDyn = ifEnableExecDyn
57 , pbVerbose = ifVerbose
58 , pbAllowNewer = ifSkipCheck
59 , pbBuildHoogle = ifBuildHoogle
62-- | Install stackage from an existing build plan.
63installBuild :: InstallFlags -> IO ()
64installBuild installFlags@InstallFlags{..} = do
65 hSetBuffering stdout LineBuffering
67 putStrLn $ "Loading build plan"
68 plan <- case ifPlanSource of
69 BPSBundleWeb url -> withManager tlsManagerSettings $ \man -> do
71 res <- httpLbs req man
72 planBSL <- getPlanEntry $ Tar.read $ GZip.decompress (responseBody res)
73 decodeBuildPlan planBSL
74 BPSFile path -> Yaml.decodeFileEither (fpToString path) >>= either throwM return
77 then putStrLn "Skipping build plan check"
79 putStrLn "Checking build plan"
82 putStrLn "Performing build"
83 performBuild (getPerformBuild plan installFlags) >>= mapM_ putStrLn
86 getPlanEntry Tar.Done = throwIO NoBuildPlanException
87 getPlanEntry (Tar.Fail e) = throwIO e
88 getPlanEntry (Tar.Next entry entries)
89 | Tar.entryPath entry == "build-plan.yaml" =
90 case Tar.entryContent entry of
91 Tar.NormalFile bs _ -> return bs
92 _ -> throwIO NoBuildPlanException
93 | otherwise = getPlanEntry entries
96 either throwIO return . Yaml.decodeEither' . toStrict
98data InstallBuildException = NoBuildPlanException
100instance Exception InstallBuildException
101instance Show InstallBuildException where
102 show NoBuildPlanException = "Bundle has missing or invalid build-plan.yaml"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list