git.iko.soy/typeable/cabal2nix
on faf50c2 help sign in
78 lines 2.5 kB history raw
1{-# LANGUAGE DeriveGeneric #-}
2{-# LANGUAGE StandaloneDeriving #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
5module Stackage where
7import Control.DeepSeq.Generics
8import Control.Monad
9import Control.Monad.Par.Combinator
10import Control.Monad.Par.IO
11import Control.Monad.Trans
12import Data.Map as Map
13import Data.Maybe
14import Data.Yaml ( decodeFile )
15import Distribution.Nixpkgs.Haskell.OrphanInstances ( )
16import Distribution.Package
17import Distribution.PackageDescription
18import Distribution.Version
19import GHC.Generics ( Generic )
20import Stackage.Types hiding ( display )
21import System.Directory
22import System.FilePath
23import Text.Show.Pretty
24import Distribution.Compiler
26yo :: IO ()
27yo = readView "/home/simons/src/cabal2nix/hackage2nix/stackage-nightly/nightly-2015-09-11.yaml" >>= putStrLn . ppShow
29data Spec = Spec
30 { version :: Version
31 , flagOverrides :: (Map FlagName Bool)
32 , runTests :: Bool
33 , runHaddock :: Bool
34 , runLinuxBuilds :: Bool
35 }
36 deriving (Show, Eq, Ord, Generic)
38data View = View
39 { compiler :: CompilerId
40 , corePackages :: Map PackageName Version
41 , packages :: Map PackageName Spec
42 }
43 deriving (Show, Generic)
45instance NFData Spec where
46instance NFData View where
48views :: IO [View]
49views = runParIO $ readStackage "lts-haskell"
51readStackage :: FilePath -> ParIO [View]
52readStackage dirPath = do
53 filePaths <- liftIO (listFiles dirPath)
54 parMapM (liftIO . readView) [ dirPath </> p | p <- filePaths, takeExtension p == ".yaml" ]
56readView :: FilePath -> IO View
57readView = fmap fromBuildPlan . readBuildPlan
59fromBuildPlan :: BuildPlan -> View
60fromBuildPlan bp = View (CompilerId GHC (siGhcVersion (bpSystemInfo bp)))
61 (siCorePackages (bpSystemInfo bp))
62 (Map.map fromPackagePlan (bpPackages bp))
64fromPackagePlan :: PackagePlan -> Spec
65fromPackagePlan pp = Spec (ppVersion pp)
66 (pcFlagOverrides ppc)
67 (pcTests ppc == ExpectSuccess)
68 (pcHaddocks ppc == ExpectSuccess)
69 (pcSkipBuild ppc)
70 where ppc = ppConstraints pp
72readBuildPlan :: FilePath -> IO BuildPlan
73readBuildPlan = fmap fromJust . decodeFile
75listFiles :: FilePath -> IO [FilePath]
76listFiles path = do
77 let isFile p = doesFileExist (path </> p)
78 getDirectoryContents path >>= filterM isFile . Prelude.filter (\x -> head x /= '.')