Commit 5aa13920 authored by Ben Gamari's avatar Ben Gamari

Move sandbox setup into initGhci

As it turns out, setSessionDynFlags calls initPackage. Unfortunately,
initPackage only reads the package database the first time it is called.
Therefore, we need to set extraPkgConfs before we call
setSessionDynFlags for the first time in order for the sandbox to be
used. Since initGhci is the first caller of setSessionDynFlags, we make
it responsible for this.
parent 65c7a044
......@@ -119,18 +119,9 @@ globalImports =
-- is handled specially, which cannot be done in a testing environment.
interpret :: Bool -> Interpreter a -> IO a
interpret allowedStdin action = runGhc (Just libdir) $ do
initGhci
-- If we're in a sandbox, add the relevant package database
dflags <- getSessionDynFlags
sandboxPackages <- liftIO getSandboxPackageConf
let pkgConfs = case sandboxPackages of
Nothing -> extraPkgConfs dflags
Just path ->
let pkg = PkgConfFile path in
(pkg:) . extraPkgConfs dflags
void $ setSessionDynFlags $ dflags { extraPkgConfs = pkgConfs }
initGhci sandboxPackages
initializeImports
......
......@@ -131,18 +131,28 @@ doc sdoc = do
-- @NoMonomorphismRestriction@), sets the target to interpreted, link in
-- memory, sets a reasonable output width, and potentially a few other
-- 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.
-- Start with -XExtendedDefaultRules and -XNoMonomorphismRestriction.
originalFlags <- getSessionDynFlags
let flag = flip xopt_set
unflag = flip xopt_unset
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,
ghcLink = LinkInMemory,
pprCols = 300 }
pprCols = 300,
extraPkgConfs = pkgConfs }
-- | Evaluate a single import statement.
-- 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