@@ -104,9 +104,6 @@ module Stack.Types.Config
104
104
,readColorWhen
105
105
-- ** SCM
106
106
,SCM (.. )
107
- -- ** GhcOptions
108
- ,GhcOptions (.. )
109
- ,ghcOptionsFor
110
107
-- * Paths
111
108
,bindirSuffix
112
109
,configInstalledCache
@@ -172,11 +169,11 @@ module Stack.Types.Config
172
169
173
170
import Stack.Prelude
174
171
import Data.Aeson.Extended
175
- (ToJSON , toJSON , FromJSON , parseJSON , withText , object ,
172
+ (ToJSON , toJSON , FromJSON , FromJSONKey ( .. ), parseJSON , withText , object ,
176
173
(.=) , (..:) , (..:?) , (..!=) , Value (Bool , String ),
177
174
withObjectWarnings , WarningParser , Object , jsonSubWarnings ,
178
- jsonSubWarningsT , jsonSubWarningsTT , WithJSONWarnings (.. ), noJSONWarnings )
179
- import Data.Attoparsec.Args
175
+ jsonSubWarningsT , jsonSubWarningsTT , WithJSONWarnings (.. ), noJSONWarnings ,
176
+ FromJSONKeyFunction ( FromJSONKeyTextParser ))
180
177
import qualified Data.ByteString.Char8 as S8
181
178
import Data.List (stripPrefix )
182
179
import Data.List.NonEmpty (NonEmpty )
@@ -314,9 +311,10 @@ data Config =
314
311
-- ^ Parameters for templates.
315
312
,configScmInit :: ! (Maybe SCM )
316
313
-- ^ Initialize SCM (e.g. git) when creating new projects.
317
- ,configGhcOptions :: ! GhcOptions
318
- -- ^ Additional GHC options to apply to either all packages (Nothing)
319
- -- or a specific package (Just).
314
+ ,configGhcOptionsByName :: ! (Map PackageName [Text ])
315
+ -- ^ Additional GHC options to apply to specific packages.
316
+ ,configGhcOptionsAll :: ! [Text ]
317
+ -- ^ Additional GHC options to apply to all packages
320
318
,configSetupInfoLocations :: ! [SetupInfoLocation ]
321
319
-- ^ Additional SetupInfo (inline or remote) to use to find tools.
322
320
,configPvpBounds :: ! PvpBounds
@@ -709,8 +707,10 @@ data ConfigMonoid =
709
707
-- ^ Template parameters.
710
708
,configMonoidScmInit :: ! (First SCM )
711
709
-- ^ Initialize SCM (e.g. git init) when making new projects?
712
- ,configMonoidGhcOptions :: ! GhcOptions
713
- -- ^ See 'configGhcOptions'
710
+ ,configMonoidGhcOptionsByName :: ! (Map PackageName [Text ])
711
+ -- ^ See 'configGhcOptionsByName'
712
+ ,configMonoidGhcOptionsAll :: ! [Text ]
713
+ -- ^ See 'configGhcOptionsAll'
714
714
,configMonoidExtraPath :: ! [Path Abs Dir ]
715
715
-- ^ Additional paths to search for executables in
716
716
,configMonoidSetupInfoLocations :: ! [SetupInfoLocation ]
@@ -795,6 +795,14 @@ parseConfigMonoidObject rootDir obj = do
795
795
configMonoidCompilerCheck <- First <$> obj ..:? configMonoidCompilerCheckName
796
796
797
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
805
+
798
806
configMonoidExtraPath <- obj ..:? configMonoidExtraPathName ..!= []
799
807
configMonoidSetupInfoLocations <-
800
808
maybeToList <$> jsonSubWarningsT (obj ..:? configMonoidSetupInfoLocationsName)
@@ -1713,43 +1721,16 @@ data DockerUser = DockerUser
1713
1721
, duUmask :: FileMode -- ^ File creation mask }
1714
1722
} deriving (Read ,Show )
1715
1723
1716
- newtype GhcOptions = GhcOptions
1717
- { unGhcOptions :: Map (Maybe PackageName ) [Text ] }
1718
- deriving Show
1719
-
1720
- instance FromJSON GhcOptions where
1721
- parseJSON val = do
1722
- ghcOptions <- parseJSON val
1723
- fmap (GhcOptions . Map. fromList) $ mapM handleGhcOptions $ Map. toList ghcOptions
1724
- where
1725
- handleGhcOptions :: Monad m => (Text , Text ) -> m (Maybe PackageName , [Text ])
1726
- handleGhcOptions (name', vals') = do
1727
- name <-
1728
- if name' == " *"
1729
- then return Nothing
1730
- else case parsePackageNameFromString $ T. unpack name' of
1731
- Left e -> fail $ show e
1732
- Right x -> return $ Just x
1733
-
1734
- case parseArgs Escaping vals' of
1735
- Left e -> fail e
1736
- Right vals -> return (name, map T. pack vals)
1737
-
1738
- instance Monoid GhcOptions where
1739
- mempty = GhcOptions mempty
1740
- -- FIXME: Should GhcOptions really monoid like this? Keeping it this
1741
- -- way preserves the behavior of the ConfigMonoid. However, this
1742
- -- means there isn't the ability to fully override snapshot
1743
- -- ghc-options in the same way there is for flags. Do we want to
1744
- -- change the semantics here? (particularly for extensible
1745
- -- snapshots)
1746
- mappend (GhcOptions l) (GhcOptions r) =
1747
- GhcOptions (Map. unionWith (++) l r)
1748
-
1749
- ghcOptionsFor :: PackageName -> GhcOptions -> [Text ]
1750
- ghcOptionsFor name (GhcOptions mp) =
1751
- M. findWithDefault [] Nothing mp ++
1752
- M. findWithDefault [] (Just name) mp
1724
+ data GhcOptionKey = GOKAll | GOKPackage ! PackageName
1725
+ deriving (Eq , Ord )
1726
+ instance FromJSONKey GhcOptionKey where
1727
+ 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
1733
+ fromJSONKeyList = FromJSONKeyTextParser $ \ _ -> fail " GhcOptionKey.fromJSONKeyList"
1753
1734
1754
1735
-----------------------------------
1755
1736
-- Lens classes
0 commit comments