Commit cb342e53 authored by Andrew Gibiansky's avatar Andrew Gibiansky

Merge pull request #255 from bgamari/ghc7.8

GHC 7.8: Fix sandbox support  and some debugging conveniences
parents 0e6dc7e5 bb5fa60a
#!/bin/sh -e #!/bin/bash -e
# Called from Setup.hs. # Called from Setup.hs.
function make_parser { function make_parser {
......
...@@ -77,9 +77,14 @@ import Data.Version (versionBranch) ...@@ -77,9 +77,14 @@ import Data.Version (versionBranch)
data ErrorOccurred = Success | Failure deriving (Show, Eq) data ErrorOccurred = Success | Failure deriving (Show, Eq)
-- | Enable debugging output
debug :: Bool debug :: Bool
debug = False debug = False
-- | Set GHC's verbosity for debugging
ghcVerbosity :: Maybe Int
ghcVerbosity = Nothing -- Just 5
ignoreTypePrefixes :: [String] ignoreTypePrefixes :: [String]
ignoreTypePrefixes = ["GHC.Types", "GHC.Base", "GHC.Show", "System.IO", ignoreTypePrefixes = ["GHC.Types", "GHC.Base", "GHC.Show", "System.IO",
"GHC.Float", ":Interactive", "GHC.Num", "GHC.IO", "GHC.Float", ":Interactive", "GHC.Num", "GHC.IO",
...@@ -119,18 +124,13 @@ globalImports = ...@@ -119,18 +124,13 @@ globalImports =
-- is handled specially, which cannot be done in a testing environment. -- is handled specially, which cannot be done in a testing environment.
interpret :: Bool -> Interpreter a -> IO a interpret :: Bool -> Interpreter a -> IO a
interpret allowedStdin action = runGhc (Just libdir) $ do interpret allowedStdin action = runGhc (Just libdir) $ do
initGhci
-- If we're in a sandbox, add the relevant package database -- If we're in a sandbox, add the relevant package database
dflags <- getSessionDynFlags
sandboxPackages <- liftIO getSandboxPackageConf sandboxPackages <- liftIO getSandboxPackageConf
let pkgConfs = case sandboxPackages of initGhci sandboxPackages
Nothing -> extraPkgConfs dflags case ghcVerbosity of
Just path -> Just verb -> do dflags <- getSessionDynFlags
let pkg = PkgConfFile path in void $ setSessionDynFlags $ dflags { verbosity = verb }
(pkg:) . extraPkgConfs dflags Nothing -> return ()
void $ setSessionDynFlags $ dflags { extraPkgConfs = pkgConfs }
initializeImports initializeImports
......
...@@ -131,18 +131,28 @@ doc sdoc = do ...@@ -131,18 +131,28 @@ doc sdoc = do
-- @NoMonomorphismRestriction@), sets the target to interpreted, link in -- @NoMonomorphismRestriction@), sets the target to interpreted, link in
-- memory, sets a reasonable output width, and potentially a few other -- memory, sets a reasonable output width, and potentially a few other
-- things. It should be invoked before other functions from this module. -- things. It should be invoked before other functions from this module.
initGhci :: GhcMonad m => m () --
initGhci = do -- We also require that the sandbox PackageConf (if any) is passed here
-- as setSessionDynFlags will read the package database the first time
-- (and only the first time) it is called.
initGhci :: GhcMonad m => Maybe String -> m ()
initGhci sandboxPackages = do
-- Initialize dyn flags. -- Initialize dyn flags.
-- Start with -XExtendedDefaultRules and -XNoMonomorphismRestriction. -- Start with -XExtendedDefaultRules and -XNoMonomorphismRestriction.
originalFlags <- getSessionDynFlags originalFlags <- getSessionDynFlags
let flag = flip xopt_set let flag = flip xopt_set
unflag = flip xopt_unset unflag = flip xopt_unset
dflags = flag Opt_ExtendedDefaultRules . unflag Opt_MonomorphismRestriction $ originalFlags dflags = flag Opt_ExtendedDefaultRules . unflag Opt_MonomorphismRestriction $ originalFlags
pkgConfs = case sandboxPackages of
Nothing -> extraPkgConfs originalFlags
Just path ->
let pkg = PkgConfFile path in
(pkg:) . extraPkgConfs originalFlags
void $ setSessionDynFlags $ dflags { hscTarget = HscInterpreted, void $ setSessionDynFlags $ dflags { hscTarget = HscInterpreted,
ghcLink = LinkInMemory, ghcLink = LinkInMemory,
pprCols = 300 } pprCols = 300,
extraPkgConfs = pkgConfs }
-- | Evaluate a single import statement. -- | Evaluate a single import statement.
-- If this import statement is importing a module which was previously -- If this import statement is importing a module which was previously
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment