on ec2b67d help sign in
stackage/Stackage/Tarballs.hs
45 lines 1.8 kB history raw
1module Stackage.Tarballs
2 ( makeTarballs
3 ) where
5import qualified Codec.Archive.Tar as Tar
6import qualified Data.ByteString.Lazy as L
7import qualified Data.Map as Map
8import qualified Data.Set as Set
9import Stackage.Types
10import Stackage.Util
11import System.Directory (createDirectoryIfMissing)
12import System.FilePath (takeDirectory)
14makeTarballs :: BuildPlan -> IO ()
15makeTarballs bp = do
16 putStrLn "Building tarballs"
17 tarName <- getTarballName
18 origEntries <- fmap Tar.read $ L.readFile tarName
19 (stableEntries, extraEntries) <- loop id id origEntries
21 (stableTar, extraTar) <- getStackageTarballNames
23 createDirectoryIfMissing True $ takeDirectory stableTar
24 L.writeFile stableTar $ Tar.write stableEntries
26 createDirectoryIfMissing True $ takeDirectory extraTar
27 L.writeFile extraTar $ Tar.write extraEntries
28 where
29 -- Using "error . show" for compatibility with tar 0.3 and 0.4
30 loop _ _ (Tar.Fail err) = error $ show err
31 loop stable extra Tar.Done = return (stable [], extra [])
32 loop stable extra (Tar.Next e es) =
33 loop stable' extra' es
34 where
35 (stable', extra') =
36 case getPackageVersion e of
37 Nothing -> (stable, extra)
38 Just (package, version) ->
39 case Map.lookup package $ bpPackages bp of
40 Just spi
41 | version == spiVersion spi -> (stable . (e:), extra)
42 | otherwise -> (stable, extra)
43 Nothing
44 | package `Map.member` bpCore bp -> (stable, extra)
45 | otherwise -> (stable, extra . (e:))