on 360b181 help sign in
stackage/Stackage/Types.hs
140 lines 5.5 kB history raw
1module Stackage.Types
2 ( module X
3 , module Stackage.Types
4 ) where
6import Data.Map as X (Map)
7import Data.Map (unionWith)
8import Data.Monoid (Monoid (..))
9import Data.Set as X (Set)
10import Data.Version as X (Version)
11import Distribution.Package as X (PackageIdentifier (..),
12 PackageName (..))
13import Distribution.PackageDescription (GenericPackageDescription)
14import Distribution.Version as X (VersionRange (..))
15import Distribution.Version (intersectVersionRanges)
17newtype PackageDB = PackageDB (Map PackageName PackageInfo)
18 deriving (Show, Eq)
20instance Monoid PackageDB where
21 mempty = PackageDB mempty
22 PackageDB x `mappend` PackageDB y =
23 PackageDB $ unionWith newest x y
24 where
25 newest pi1 pi2
26 | piVersion pi1 > piVersion pi2 = pi1
27 | otherwise = pi2
29data PackageInfo = PackageInfo
30 { piVersion :: Version
31 , piDeps :: Map PackageName VersionRange
32 , piHasTests :: Bool
33 , piBuildTools :: Set Executable
34 , piGPD :: Maybe GenericPackageDescription
35 , piExecs :: Set Executable
36 , piGithubUser :: Maybe String
37 }
38 deriving (Show, Eq)
40newtype Executable = Executable String
41 deriving (Show, Eq, Ord)
43-- | Information on a package we're going to build.
44data BuildInfo = BuildInfo
45 { biVersion :: Version
46 , biUsers :: [PackageName]
47 , biMaintainer :: Maintainer
48 , biDeps :: Map PackageName VersionRange
49 , biGithubUser :: Maybe String
50 , biHasTests :: Bool
51 }
53data HaskellPlatform = HaskellPlatform
54 { hpcore :: Set PackageIdentifier
55 , hplibs :: Set PackageIdentifier
56 }
57 deriving (Show, Eq, Ord)
58instance Monoid HaskellPlatform where
59 mempty = HaskellPlatform mempty mempty
60 HaskellPlatform a x `mappend` HaskellPlatform b y = HaskellPlatform (mappend a b) (mappend x y)
62data InstallInfo = InstallInfo
63 { iiCore :: Set PackageName
64 , iiPackages :: Map PackageName SelectedPackageInfo
65 , iiOptionalCore :: Map PackageName Version
66 -- ^ This is intended to hold onto packages which might be automatically
67 -- provided in the global package database. In practice, this would be
68 -- Haskell Platform packages provided by distributions.
69 , iiPackageDB :: PackageDB
70 }
72data SelectedPackageInfo = SelectedPackageInfo
73 { spiVersion :: Version
74 , spiMaintainer :: Maintainer
75 , spiGithubUser :: Maybe String
76 , spiHasTests :: Bool
77 }
78 deriving (Show, Read)
80data BuildPlan = BuildPlan
81 { bpTools :: [String]
82 , bpPackages :: Map PackageName SelectedPackageInfo
83 , bpCore :: Set PackageName
84 , bpOptionalCore :: Map PackageName Version
85 -- ^ See 'iiOptionalCore'
86 }
88-- | Email address of a Stackage maintainer.
89newtype Maintainer = Maintainer { unMaintainer :: String }
90 deriving (Show, Eq, Ord, Read)
92data SelectSettings = SelectSettings
93 { haskellPlatformCabal :: FilePath
94 , flags :: Map PackageName Version -> Set String
95 -- ^ Compile flags which should be turned on. Takes a Map providing the
96 -- core packages so that flags can be set appropriately.
97 , disabledFlags :: Set String
98 -- ^ Compile flags which should always be disabled.
99 , extraCore :: Set PackageName
100 , requireHaskellPlatform :: Bool
101 , allowedPackage :: GenericPackageDescription -> Either String ()
102 -- ^ Checks if a package is allowed into the distribution. By default, we
103 -- allow all packages in, though this could be used to filter out certain
104 -- untrusted packages, or packages with an unacceptable license.
105 --
106 -- Returns a reason for stripping in Left, or Right if the package is
107 -- allowed.
108 , expectedFailuresSelect :: Set PackageName
109 , excludedPackages :: Set PackageName
110 -- ^ Packages which should be dropped from the list of stable packages,
111 -- even if present via the Haskell Platform or @stablePackages@. If these
112 -- packages are dependencies of others, they will still be included.
113 , stablePackages :: Map PackageName (VersionRange, Maintainer)
114 , useGlobalDatabase :: Bool
115 -- ^ Instead of checking the Haskell Platform file for core packages, query
116 -- the global database. For this to be reliable, you should only have
117 -- default packages in your global database. Default is @False@.
118 }
120data BuildStage = BSBuild | BSTest
122data BuildSettings = BuildSettings
123 { sandboxRoot :: FilePath
124 , extraArgs :: BuildStage -> [String]
125 , expectedFailuresBuild :: Set PackageName
126 , testWorkerThreads :: Int
127 -- ^ How many threads to spawn for running test suites.
128 , buildDocs :: Bool
129 -- ^ Build docs as part of the test procedure.
130 }
132-- | A wrapper around a @Map@ providing a better @Monoid@ instance.
133newtype PackageMap = PackageMap { unPackageMap :: Map PackageName (VersionRange, Maintainer) }
135instance Monoid PackageMap where
136 mempty = PackageMap mempty
137 PackageMap x `mappend` PackageMap y =
138 PackageMap $ unionWith go x y
139 where
140 go (r1, m1) (r2, _) = (intersectVersionRanges r1 r2, m1)