on 56b9967 help sign in
stackage/Stackage/Types.hs
155 lines 6.2 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 , bpSkippedTests :: Set PackageName
87 }
89-- | Email address of a Stackage maintainer.
90newtype Maintainer = Maintainer { unMaintainer :: String }
91 deriving (Show, Eq, Ord, Read)
93data SelectSettings = SelectSettings
94 { haskellPlatformDir :: FilePath
95 , flags :: Map PackageName Version -> Set String
96 -- ^ Compile flags which should be turned on. Takes a Map providing the
97 -- core packages so that flags can be set appropriately.
98 , disabledFlags :: Set String
99 -- ^ Compile flags which should always be disabled.
100 , extraCore :: Set PackageName
101 , requireHaskellPlatform :: Bool
102 , allowedPackage :: GenericPackageDescription -> Either String ()
103 -- ^ Checks if a package is allowed into the distribution. By default, we
104 -- allow all packages in, though this could be used to filter out certain
105 -- untrusted packages, or packages with an unacceptable license.
106 --
107 -- Returns a reason for stripping in Left, or Right if the package is
108 -- allowed.
109 , expectedFailuresSelect :: Set PackageName
110 , excludedPackages :: Set PackageName
111 -- ^ Packages which should be dropped from the list of stable packages,
112 -- even if present via the Haskell Platform or @stablePackages@. If these
113 -- packages are dependencies of others, they will still be included.
114 , stablePackages :: Map PackageName (VersionRange, Maintainer)
115 , useGlobalDatabase :: Bool
116 -- ^ Instead of checking the Haskell Platform file for core packages, query
117 -- the global database. For this to be reliable, you should only have
118 -- default packages in your global database. Default is @False@.
119 , skippedTests :: Set PackageName
120 -- ^ Do not build or run test suites, usually in order to avoid a
121 -- dependency.
122 , selectGhcVersion :: GhcMajorVersion
123 , selectTarballDir :: FilePath
124 -- ^ Directory containing replacement tarballs.
125 }
127data BuildStage = BSTools | BSBuild | BSTest
129data BuildSettings = BuildSettings
130 { sandboxRoot :: FilePath
131 , extraArgs :: BuildStage -> [String]
132 , expectedFailuresBuild :: Set PackageName
133 , testWorkerThreads :: Int
134 -- ^ How many threads to spawn for running test suites.
135 , buildDocs :: Bool
136 -- ^ Build docs as part of the test procedure.
137 , tarballDir :: FilePath
138 -- ^ Directory containing replacement tarballs.
139 , cabalFileDir :: Maybe FilePath
140 -- ^ Directory to place cabal files in
141 }
143-- | A wrapper around a @Map@ providing a better @Monoid@ instance.
144newtype PackageMap = PackageMap { unPackageMap :: Map PackageName (VersionRange, Maintainer) }
146instance Monoid PackageMap where
147 mempty = PackageMap mempty
148 PackageMap x `mappend` PackageMap y =
149 PackageMap $ unionWith go x y
150 where
151 go (r1, m1) (r2, _) = (intersectVersionRanges r1 r2, m1)
153-- | GHC major version. For example, for GHC 7.4.2, this would be 7 4.
154data GhcMajorVersion = GhcMajorVersion Int Int
155 deriving (Show, Ord, Eq)