@@ -1,11 +1,13 @@
1+{-# LANGUAGE RecordWildCards #-}
1{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE DeriveGeneric #-}
3{-# LANGUAGE DeriveGeneric #-}
3{-# OPTIONS_GHC -fno-warn-orphans #-}
4{-# OPTIONS_GHC -fno-warn-orphans #-}
5−module Configuration ( Configuration(..) ) where
6+module Configuration ( Configuration(..), readConfiguration, assertConsistency ) where
7import Control.DeepSeq.Generics
8import Control.DeepSeq.Generics
8import Control.Lens
9import Control.Lens
9import Data.Map as Map
11import Data.Map as Map
10import Data.Set as Set
12import Data.Set as Set
11import Data.Text as T
13import Data.Text as T
@@ -66,3 +68,19 @@ instance (Ord k, FromJSON k, FromJSON v) => FromJSON (Map k v) where
67 parseKey :: FromJSON k => Text -> k
69 parseKey :: FromJSON k => Text -> k
68 parseKey s = either error id (parseEither parseJSON (String s))
70 parseKey s = either error id (parseEither parseJSON (String s))
72+readConfiguration :: FilePath -> IO Configuration
73+readConfiguration path =
74+ decodeFile path >>= maybe (fail ("invalid config file at " ++ show path)) assertConsistency
76+assertConsistency :: Monad m => Configuration -> m Configuration
77+assertConsistency cfg@(Configuration {..}) = do
78+ let report msg = fail ("*** configuration error: " ++ msg)
80+ maintainedPackages = Set.unions (Map.elems packageMaintainers)
81+ disabledPackages = Map.keysSet dontDistributePackages
82+ disabledMaintainedPackages = maintainedPackages `Set.intersection` disabledPackages
83+ when (not (Set.null disabledMaintainedPackages)) $
84+ report ("disabled packages that have a maintainer: " ++ show disabledMaintainedPackages)