on b804e37 help sign in
stackage/Stackage/Types.hs
165 lines 6.8 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 , piBuildToolsExe :: Set Executable -- ^ required just for building executable/lib
34 , piBuildToolsAll :: Set Executable -- ^ required for all stanzas
35 , piGPD :: Maybe GenericPackageDescription
36 , piExecs :: Set Executable
37 , piGithubUser :: [String]
38 }
39 deriving (Show, Eq)
41newtype Executable = Executable String
42 deriving (Show, Eq, Ord)
44-- | Information on a package we're going to build.
45data BuildInfo = BuildInfo
46 { biVersion :: Version
47 , biUsers :: [PackageName]
48 , biMaintainer :: Maintainer
49 , biDeps :: Map PackageName VersionRange
50 , biGithubUser :: [String]
51 , biHasTests :: Bool
52 }
54data HaskellPlatform = HaskellPlatform
55 { hpcore :: Set PackageIdentifier
56 , hplibs :: Set PackageIdentifier
57 }
58 deriving (Show, Eq, Ord)
59instance Monoid HaskellPlatform where
60 mempty = HaskellPlatform mempty mempty
61 HaskellPlatform a x `mappend` HaskellPlatform b y = HaskellPlatform (mappend a b) (mappend x y)
63data InstallInfo = InstallInfo
64 { iiCore :: Map PackageName (Maybe Version)
65 , iiPackages :: Map PackageName SelectedPackageInfo
66 , iiOptionalCore :: Map PackageName Version
67 -- ^ This is intended to hold onto packages which might be automatically
68 -- provided in the global package database. In practice, this would be
69 -- Haskell Platform packages provided by distributions.
70 , iiPackageDB :: PackageDB
71 }
73data SelectedPackageInfo = SelectedPackageInfo
74 { spiVersion :: Version
75 , spiMaintainer :: Maintainer
76 , spiGithubUser :: [String]
77 , spiHasTests :: Bool
78 }
79 deriving (Show, Read)
81data BuildPlan = BuildPlan
82 { bpTools :: [String]
83 , bpPackages :: Map PackageName SelectedPackageInfo
84 , bpCore :: Map PackageName (Maybe Version)
85 , bpOptionalCore :: Map PackageName Version
86 -- ^ See 'iiOptionalCore'
87 , bpSkippedTests :: Set PackageName
88 , bpExpectedFailures :: Set PackageName
89 -- ^ Expected test failures. Unlike SkippedTests, we should still try to
90 -- build them.
91 }
93-- | Email address of a Stackage maintainer.
94newtype Maintainer = Maintainer { unMaintainer :: String }
95 deriving (Show, Eq, Ord, Read)
97data SelectSettings = SelectSettings
98 { haskellPlatformDir :: FilePath
99 , flags :: Map PackageName Version -> Set String
100 -- ^ Compile flags which should be turned on. Takes a Map providing the
101 -- core packages so that flags can be set appropriately.
102 , disabledFlags :: Set String
103 -- ^ Compile flags which should always be disabled.
104 , extraCore :: Set PackageName
105 , ignoreUpgradeableCore :: Bool
106 -- ^ Do not pin down the versions of upgradeable core packages.
107 , requireHaskellPlatform :: Bool
108 , allowedPackage :: GenericPackageDescription -> Either String ()
109 -- ^ Checks if a package is allowed into the distribution. By default, we
110 -- allow all packages in, though this could be used to filter out certain
111 -- untrusted packages, or packages with an unacceptable license.
112 --
113 -- Returns a reason for stripping in Left, or Right if the package is
114 -- allowed.
115 , expectedFailures :: Set PackageName
116 , excludedPackages :: Set PackageName
117 -- ^ Packages which should be dropped from the list of stable packages,
118 -- even if present via the Haskell Platform or @stablePackages@. If these
119 -- packages are dependencies of others, they will still be included.
120 , stablePackages :: Bool -- require Haskell Platform?
121 -> Map PackageName (VersionRange, Maintainer)
122 , useGlobalDatabase :: Bool
123 -- ^ Instead of checking the Haskell Platform file for core packages, query
124 -- the global database. For this to be reliable, you should only have
125 -- default packages in your global database. Default is @False@.
126 , skippedTests :: Set PackageName
127 -- ^ Do not build or run test suites, usually in order to avoid a
128 -- dependency.
129 , selectGhcVersion :: GhcMajorVersion
130 , selectTarballDir :: FilePath
131 -- ^ Directory containing replacement tarballs.
132 , selectUnderlayPackageDirs :: [FilePath]
133 -- ^ Additional package directories to reference
134 }
136data BuildStage = BSTools | BSBuild | BSTest
138data BuildSettings = BuildSettings
139 { sandboxRoot :: FilePath
140 , extraArgs :: BuildStage -> [String]
141 , testWorkerThreads :: Int
142 -- ^ How many threads to spawn for running test suites.
143 , buildDocs :: Bool
144 -- ^ Build docs as part of the test procedure.
145 , tarballDir :: FilePath
146 -- ^ Directory containing replacement tarballs.
147 , cabalFileDir :: Maybe FilePath
148 -- ^ Directory to place cabal files in
149 , underlayPackageDirs :: [FilePath]
150 -- ^ Additional package directories to reference
151 }
153-- | A wrapper around a @Map@ providing a better @Monoid@ instance.
154newtype PackageMap = PackageMap { unPackageMap :: Map PackageName (VersionRange, Maintainer) }
156instance Monoid PackageMap where
157 mempty = PackageMap mempty
158 PackageMap x `mappend` PackageMap y =
159 PackageMap $ unionWith go x y
160 where
161 go (r1, m1) (r2, _) = (intersectVersionRanges r1 r2, m1)
163-- | GHC major version. For example, for GHC 7.4.2, this would be 7 4.
164data GhcMajorVersion = GhcMajorVersion Int Int
165 deriving (Show, Ord, Eq)