-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEnvSetup.hs
More file actions
49 lines (46 loc) · 1.66 KB
/
EnvSetup.hs
File metadata and controls
49 lines (46 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
{-# LANGUAGE NoRebindableSyntax, NoOverloadedStrings, ImplicitPrelude #-}
module Main where
import Distribution.PackageDescription
import Distribution.PackageDescription.Parse
import Distribution.Compiler
import Distribution.Verbosity
import Data.Maybe
import Language.Haskell.Extension
import System.IO
import Control.Monad
main :: IO ()
main = do
p <- readPackageDescription silent "maam.cabal"
let bi = libBuildInfo $ condTreeData $ fromJust $ condLibrary p
-- EXTENSIONS --
let extensions = catMaybes $ map enabledOnly $ defaultExtensions bi
-- write out a file listing all extensions
withFile ".extensions" WriteMode $ \ h -> do
forM_ extensions $ \ e -> do
hPutStrLn h $ show e
-- write out a file for ghci to load extensions
withFile ".extensions.ghci" WriteMode $ \ h -> do
forM_ extensions $ \ e -> do
hPutStrLn h $ ":set -X" ++ show e
-- write out a file for hdevtools to load extensions
withFile ".extensions.hdev" WriteMode $ \ h -> do
forM_ extensions $ \ e -> do
hPutStrLn h $ "-g-X" ++ show e
-- write out a file for ghc to load extensions
withFile ".extensions.ghc" WriteMode $ \ h -> do
forM_ extensions $ \ e -> do
hPutStr h $ " -X" ++ show e
-- OPTIONS --
let ops = fromJust $ lookup GHC $ options bi
-- write out a file for ghci to load options
withFile ".ghc_options.ghci" WriteMode $ \ h -> do
forM_ ops $ \ o -> do
hPutStrLn h $ ":set " ++ o
-- write out a file for hdevtools to load options
withFile ".ghc_options.hdev" WriteMode $ \ h -> do
forM_ ops $ \ o -> do
hPutStrLn h $ "-g" ++ o
return ()
where
enabledOnly (EnableExtension s) = Just s
enabledOnly _ = Nothing