@@ -167,13 +167,15 @@ module Stack.Types.Config
167167 ,to
168168 ) where
169169
170+ import Control.Monad.Writer (tell )
170171import Stack.Prelude
171172import Data.Aeson.Extended
172173 (ToJSON , toJSON , FromJSON , FromJSONKey (.. ), parseJSON , withText , object ,
173174 (.=) , (..:) , (..:?) , (..!=) , Value (Bool , String ),
174175 withObjectWarnings , WarningParser , Object , jsonSubWarnings ,
175176 jsonSubWarningsT , jsonSubWarningsTT , WithJSONWarnings (.. ), noJSONWarnings ,
176177 FromJSONKeyFunction (FromJSONKeyTextParser ))
178+ import Data.Attoparsec.Args (parseArgs , EscapingMode (Escaping ))
177179import qualified Data.ByteString.Char8 as S8
178180import Data.List (stripPrefix )
179181import Data.List.NonEmpty (NonEmpty )
@@ -313,8 +315,8 @@ data Config =
313315 -- ^ Initialize SCM (e.g. git) when creating new projects.
314316 ,configGhcOptionsByName :: ! (Map PackageName [Text ])
315317 -- ^ Additional GHC options to apply to specific packages.
316- ,configGhcOptionsAll :: ! [Text ]
317- -- ^ Additional GHC options to apply to all packages
318+ ,configGhcOptionsByCat :: ! ( Map ApplyGhcOptions [Text ])
319+ -- ^ Additional GHC options to apply to categories of packages
318320 ,configSetupInfoLocations :: ! [SetupInfoLocation ]
319321 -- ^ Additional SetupInfo (inline or remote) to use to find tools.
320322 ,configPvpBounds :: ! PvpBounds
@@ -709,7 +711,7 @@ data ConfigMonoid =
709711 -- ^ Initialize SCM (e.g. git init) when making new projects?
710712 ,configMonoidGhcOptionsByName :: ! (Map PackageName [Text ])
711713 -- ^ See 'configGhcOptionsByName'
712- ,configMonoidGhcOptionsAll :: ! [Text ]
714+ ,configMonoidGhcOptionsByCat :: ! ( Map ApplyGhcOptions [Text ])
713715 -- ^ See 'configGhcOptionsAll'
714716 ,configMonoidExtraPath :: ! [Path Abs Dir ]
715717 -- ^ Additional paths to search for executables in
@@ -794,14 +796,25 @@ parseConfigMonoidObject rootDir obj = do
794796 return (First scmInit,fromMaybe M. empty params)
795797 configMonoidCompilerCheck <- First <$> obj ..:? configMonoidCompilerCheckName
796798
797- configMonoidGhcOptions <- obj ..:? configMonoidGhcOptionsName ..!= mempty
798- let configMonoidGhcOptionsByName = Map. unions (map
799- (\ (mname, opts) ->
800- case mname of
801- GOKAll -> Map. empty
802- GOKPackage name -> Map. singleton name opts)
803- (Map. toList configMonoidGhcOptions))
804- configMonoidGhcOptionsAll = Map. findWithDefault [] GOKAll configMonoidGhcOptions
799+ options <- Map. map unGhcOptions <$> obj ..:? configMonoidGhcOptionsName ..!= mempty
800+
801+ optionsEverything <-
802+ case (Map. lookup GOKOldEverything options, Map. lookup GOKEverything options) of
803+ (Just _, Just _) -> fail " Cannot specify both `*` and `$everything` GHC options"
804+ (Nothing , Just x) -> return x
805+ (Just x, Nothing ) -> do
806+ tell " The `*` ghc-options key is not recommended. Consider using $locals, or if really needed, $everything"
807+ return x
808+ (Nothing , Nothing ) -> return []
809+
810+ let configMonoidGhcOptionsByCat = Map. fromList
811+ [ (AGOEverything , optionsEverything)
812+ , (AGOLocals , Map. findWithDefault [] GOKLocals options)
813+ , (AGOTargets , Map. findWithDefault [] GOKTargets options)
814+ ]
815+
816+ configMonoidGhcOptionsByName = Map. fromList
817+ [(name, opts) | (GOKPackage name, opts) <- Map. toList options]
805818
806819 configMonoidExtraPath <- obj ..:? configMonoidExtraPathName ..!= []
807820 configMonoidSetupInfoLocations <-
@@ -1721,17 +1734,35 @@ data DockerUser = DockerUser
17211734 , duUmask :: FileMode -- ^ File creation mask }
17221735 } deriving (Read ,Show )
17231736
1724- data GhcOptionKey = GOKAll | GOKPackage ! PackageName
1737+ data GhcOptionKey
1738+ = GOKOldEverything
1739+ | GOKEverything
1740+ | GOKLocals
1741+ | GOKTargets
1742+ | GOKPackage ! PackageName
17251743 deriving (Eq , Ord )
1744+
17261745instance FromJSONKey GhcOptionKey where
17271746 fromJSONKey = FromJSONKeyTextParser $ \ t ->
1728- if t == " *"
1729- then return GOKAll
1730- else case parsePackageName t of
1731- Left e -> fail $ show e
1732- Right x -> return $ GOKPackage x
1747+ case t of
1748+ " *" -> return GOKOldEverything
1749+ " $everything" -> return GOKEverything
1750+ " $locals" -> return GOKLocals
1751+ " $targets" -> return GOKTargets
1752+ _ ->
1753+ case parsePackageName t of
1754+ Left e -> fail $ show e
1755+ Right x -> return $ GOKPackage x
17331756 fromJSONKeyList = FromJSONKeyTextParser $ \ _ -> fail " GhcOptionKey.fromJSONKeyList"
17341757
1758+ newtype GhcOptions = GhcOptions { unGhcOptions :: [Text ] }
1759+
1760+ instance FromJSON GhcOptions where
1761+ parseJSON = withText " GhcOptions" $ \ t ->
1762+ case parseArgs Escaping t of
1763+ Left e -> fail e
1764+ Right opts -> return $ GhcOptions $ map T. pack opts
1765+
17351766-----------------------------------
17361767-- Lens classes
17371768-----------------------------------
0 commit comments