@@ -1,11 +1,13 @@
1+{-# LANGUAGE RecordWildCards #-}
12{-# LANGUAGE OverloadedStrings #-}
23{-# LANGUAGE DeriveGeneric #-}
34{-# OPTIONS_GHC -fno-warn-orphans #-}
45
5−module Configuration ( Configuration(..) ) where
6+module Configuration ( Configuration(..), readConfiguration, assertConsistency ) where
67
78import Control.DeepSeq.Generics
89import Control.Lens
10+import Control.Monad
911import Data.Map as Map
1012import Data.Set as Set
1113import Data.Text as T
@@ -66,3 +68,19 @@ instance (Ord k, FromJSON k, FromJSON v) => FromJSON (Map k v) where
6668 where
6769 parseKey :: FromJSON k => Text -> k
6870 parseKey s = either error id (parseEither parseJSON (String s))
71+
72+readConfiguration :: FilePath -> IO Configuration
73+readConfiguration path =
74+ decodeFile path >>= maybe (fail ("invalid config file at " ++ show path)) assertConsistency
75+
76+assertConsistency :: Monad m => Configuration -> m Configuration
77+assertConsistency cfg@(Configuration {..}) = do
78+ let report msg = fail ("*** configuration error: " ++ msg)
79+
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)
85+
86+ return cfg