Skip to content

Commit

Permalink
Use http-client for downloading
Browse files Browse the repository at this point in the history
Motivation: simply requirements on build system to avoid the wget.exe binary.
Added bonus: we can actually check host certificates now.
  • Loading branch information
snoyberg committed May 6, 2015
1 parent fd38995 commit 85bfde5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
28 changes: 22 additions & 6 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import Data.List.Extra
import System.Directory.Extra
import Installer
import Config
import Network.HTTP.Client
import Network.HTTP.Client.TLS
import System.IO
import qualified Data.ByteString as S
import Control.Monad

data Flags = Flag64 deriving Eq
flags =
Expand All @@ -18,17 +23,28 @@ flags =

main :: IO ()
main = do
man <- newManager tlsManagerSettings
createDirectoryIfMissing True ".build/bin/bin"
withCurrentDirectory ".build" $ shakeArgsWith shakeOptions flags $ \flags ver -> return $ Just $ do
let arch = if Flag64 `elem` flags then Arch64 else Arch32
want ["minghc-" ++ v ++ "-" ++ showArch arch ++ ".exe" | v <- if null ver then [defaultVersion GHC] else ver]

let wget from to = unit $ cmd "wget --no-check-certificate" [from] "-O" [to]
"ghc-*.7z" %> \out -> wget (source arch GHC $ extractVersion out) out
"minghcbin-*.7z" %> \out -> wget (source arch Minghcbin $ extractVersion out) out
"PortableGit-*.7z.exe" %> \out -> wget (source arch Git $ extractVersion out) out
"7z.exe" %> \out -> wget (source arch SevenZexe $ extractVersion out) out
"7z.dll" %> \out -> wget (source arch SevenZdll $ extractVersion out) out
let fetch from to = liftIO $ do
req <- parseUrl from
withResponse req man $
\res -> withBinaryFile to WriteMode $
\h -> do
let loop = do
bs <- brRead $ responseBody res
unless (S.null bs) $ do
S.hPut h bs
loop
loop
"ghc-*.7z" %> \out -> fetch (source arch GHC $ extractVersion out) out
"minghcbin-*.7z" %> \out -> fetch (source arch Minghcbin $ extractVersion out) out
"PortableGit-*.7z.exe" %> \out -> fetch (source arch Git $ extractVersion out) out
"7z.exe" %> \out -> fetch (source arch SevenZexe $ extractVersion out) out
"7z.dll" %> \out -> fetch (source arch SevenZdll $ extractVersion out) out

".sevenzexe-*" %> \out -> do
let ver = extractVersion out
Expand Down
5 changes: 4 additions & 1 deletion minghc.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ executable minghc-generate
directory,
extra >= 0.8,
shake >= 0.14,
nsis >= 0.2.4
nsis >= 0.2.4,
bytestring,
http-client,
http-client-tls

other-modules:
Installer
Expand Down

0 comments on commit 85bfde5

Please sign in to comment.