@@ -14,6 +14,8 @@
14module Development.IDE.UtilGHC where
14module Development.IDE.UtilGHC where
16import "ghc-lib-parser" Config
16import "ghc-lib-parser" Config
17+import qualified "ghc-lib-parser" CmdLineParser as Cmd (warnMsg)
18+import "ghc-lib-parser" DynFlags (parseDynamicFilePragma)
17import "ghc-lib-parser" Fingerprint
19import "ghc-lib-parser" Fingerprint
18import "ghc-lib" GHC hiding (convertLit)
20import "ghc-lib" GHC hiding (convertLit)
19import "ghc-lib-parser" GHC.LanguageExtensions.Type
21import "ghc-lib-parser" GHC.LanguageExtensions.Type
@@ -21,11 +23,13 @@ import "ghc-lib-parser" GhcMonad
21import "ghc-lib" GhcPlugins as GHC hiding (PackageState, fst3, (<>))
23import "ghc-lib" GhcPlugins as GHC hiding (PackageState, fst3, (<>))
22import "ghc-lib" HscMain
24import "ghc-lib" HscMain
23import qualified "ghc-lib-parser" Packages
25import qualified "ghc-lib-parser" Packages
26+import "ghc-lib-parser" Panic (throwGhcExceptionIO)
24import "ghc-lib-parser" Platform
27import "ghc-lib-parser" Platform
25import qualified "ghc-lib-parser" StringBuffer as SB
28import qualified "ghc-lib-parser" StringBuffer as SB
26import qualified "ghc-lib-parser" EnumSet
29import qualified "ghc-lib-parser" EnumSet
28import Control.DeepSeq
31import Control.DeepSeq
29import Data.IORef
33import Data.IORef
30import Data.List
34import Data.List
31import qualified Data.Text as T
35import qualified Data.Text as T
@@ -185,9 +189,26 @@ instance NFData PackageState where
185-- * Installs a custom log action;
189-- * Installs a custom log action;
186-- * Sets up the package databases;
190-- * Sets up the package databases;
187-- * Sets the import paths to the given list of 'FilePath'.
191-- * Sets the import paths to the given list of 'FilePath'.
192+-- * if present, parses and applies custom options for GHC
193+-- (may fail if the custom options are inconsistent with std DAML ones)
188−setupDamlGHC :: GhcMonad m => [FilePath] -> Maybe String -> PackageState -> m ()
194+setupDamlGHC :: GhcMonad m => [FilePath] -> Maybe String -> PackageState -> [String] -> m ()
189−setupDamlGHC importPaths mbPackageName packageState = do
195+setupDamlGHC importPaths mbPackageName packageState [] =
190 modifyDynFlags $ adjustDynFlags importPaths packageState mbPackageName
196 modifyDynFlags $ adjustDynFlags importPaths packageState mbPackageName
197+-- if custom options are given, add them after the standard DAML flag setup
198+setupDamlGHC importPaths mbPackageName packageState customOpts = do
199+ setupDamlGHC importPaths mbPackageName packageState []
200+ damlDFlags <- getSessionDynFlags
201+ (dflags', leftover, warns) <- parseDynamicFilePragma damlDFlags $ map noLoc customOpts
203+ let leftoverError = CmdLineError $
204+ (unlines . ("Unable to parse custom flags:":) . map unLoc) leftover
205+ unless (null leftover) $ liftIO $ throwGhcExceptionIO leftoverError
207+ unless (null warns) $
208+ liftIO $ putStrLn $ unlines $ "Warnings:" : map (unLoc . Cmd.warnMsg) warns
210+ modifySession $ \h ->
211+ h { hsc_dflags = dflags', hsc_IC = (hsc_IC h) {ic_dflags = dflags' } }
192-- | A version of `showSDoc` that uses default flags (to avoid uses of
213-- | A version of `showSDoc` that uses default flags (to avoid uses of
193-- `showSDocUnsafe`).
214-- `showSDocUnsafe`).