@@ -11,13 +11,30 @@ import qualified Codec.Archive.Tar as Tar
1111import qualified Data.ByteString.Lazy as L
1212import Control.Arrow (second)
1313import Distribution.Text (display)
14−import System.IO (Handle, hPutStrLn)
14+import System.Directory (doesFileExist)
15+import System.FilePath ((</>), (<.>))
16+import System.IO (Handle, hPutStrLn, hPutStr)
1517
16−createHackageFile :: InstallInfo -> Handle -> IO ()
17−createHackageFile ii h = do
18+createHackageFile :: Bool -- ^ inclusive?
19+ -> InstallInfo
20+ -> String -- ^ GHC version
21+ -> String -- ^ date
22+ -> Handle -- ^ hackage
23+ -> Handle -- ^ tarballs
24+ -> IO ()
25+createHackageFile isInc ii ghcVer date hackageH tarballH = do
26+ hPutStr tarballH $ concat
27+ [ "#!/bin/bash -ex\n\ntar czfv ../ghc-"
28+ , ghcVer
29+ , "-"
30+ , date
31+ , if isInc then "-inclusive" else "-exclusive"
32+ , ".stackage hackage desc"
33+ ]
1834 indextargz <- getTarballName
1935 indexLBS <- L.readFile indextargz
2036 loop $ Tar.read indexLBS
37+ hPutStrLn tarballH ""
2138 where
2239 selected = Map.fromList . map toStrs . Map.toList $
2340 fmap spiVersion (iiPackages ii)
@@ -35,8 +52,21 @@ createHackageFile ii h = do
3552 Nothing -> return ()
3653 Just (name, version) ->
3754 case Map.lookup name selected of
38− Just version' | version /= version' -> return ()
39− _ -> hPutStrLn h $ concat [name, "-", version]
55+ Just version'
56+ | version == version' -> emit True name version
57+ | otherwise -> return ()
58+ Nothing
59+ | isInc -> emit False name version
60+ | otherwise -> return ()
61+
62+ emit usePatch name version = do
63+ exists <- if usePatch then doesFileExist tarball else return False
64+ if exists
65+ then hPutStr tarballH $ ' ' : ".." </> tarball
66+ else hPutStrLn hackageH base
67+ where
68+ base = concat [name, "-", version]
69+ tarball = "patching" </> "tarballs" </> base <.> "tar" <.> "gz"
4070
4171parsePair :: String -> Maybe (String, String)
4272parsePair s =