Commit 1509bff8 authored by Vaibhav Sagar's avatar Vaibhav Sagar

IHaskell.Eval.Evaluate: don't support libraries for testing

parent bfa80bce
...@@ -142,7 +142,7 @@ runKernel kOpts profileSrc = do ...@@ -142,7 +142,7 @@ runKernel kOpts profileSrc = do
kernelState { kernelDebug = debug } kernelState { kernelDebug = debug }
-- Receive and reply to all messages on the shell socket. -- Receive and reply to all messages on the shell socket.
interpret libdir True $ \hasSupportLibraries -> do interpret libdir True True $ \hasSupportLibraries -> do
-- Ignore Ctrl-C the first time. This has to go inside the `interpret`, because GHC API resets the -- Ignore Ctrl-C the first time. This has to go inside the `interpret`, because GHC API resets the
-- signal handlers for some reason (completely unknown to me). -- signal handlers for some reason (completely unknown to me).
_ <- liftIO ignoreCtrlC _ <- liftIO ignoreCtrlC
......
...@@ -119,19 +119,21 @@ hiddenPackageNames = Set.fromList ["ghc-lib", "ghc-lib-parser"] ...@@ -119,19 +119,21 @@ hiddenPackageNames = Set.fromList ["ghc-lib", "ghc-lib-parser"]
-- | Interpreting function for testing. -- | Interpreting function for testing.
testInterpret :: Interpreter a -> IO a testInterpret :: Interpreter a -> IO a
testInterpret v = interpret GHC.Paths.libdir False (const v) testInterpret v = interpret GHC.Paths.libdir False False (const v)
-- | Evaluation function for testing. -- | Evaluation function for testing.
testEvaluate :: String -> IO () testEvaluate :: String -> IO ()
testEvaluate str = void $ testInterpret $ testEvaluate str = void $ testInterpret $
evaluate defaultKernelState str (\_ _ -> return ()) (\state _ -> return state) evaluate defaultKernelState str (\_ _ -> return ()) (\state _ -> return state)
-- | Run an interpreting action. This is effectively runGhc with initialization and importing. First -- | Run an interpreting action. This is effectively runGhc with initialization
-- argument indicates whether `stdin` is handled specially, which cannot be done in a testing -- and importing. The `allowedStdin` argument indicates whether `stdin` is
-- environment. The argument passed to the action indicates whether Haskell support libraries are -- handled specially, which cannot be done in a testing environment. The
-- available. -- `needsSupportLibraries` argument indicates whether we want support libraries
interpret :: String -> Bool -> (Bool -> Interpreter a) -> IO a -- to be imported, which is not the case during testing. The argument passed to
interpret libdir allowedStdin action = runGhc (Just libdir) $ do -- the action indicates whether the IHaskell library is available.
interpret :: String -> Bool -> Bool -> (Bool -> Interpreter a) -> IO a
interpret libdir allowedStdin needsSupportLibraries action = runGhc (Just libdir) $ do
-- If we're in a sandbox, add the relevant package database -- If we're in a sandbox, add the relevant package database
sandboxPackages <- liftIO getSandboxPackageConf sandboxPackages <- liftIO getSandboxPackageConf
initGhci sandboxPackages initGhci sandboxPackages
...@@ -141,7 +143,7 @@ interpret libdir allowedStdin action = runGhc (Just libdir) $ do ...@@ -141,7 +143,7 @@ interpret libdir allowedStdin action = runGhc (Just libdir) $ do
void $ setSessionDynFlags $ dflags { verbosity = verb } void $ setSessionDynFlags $ dflags { verbosity = verb }
Nothing -> return () Nothing -> return ()
hasSupportLibraries <- initializeImports hasSupportLibraries <- initializeImports needsSupportLibraries
-- Close stdin so it can't be used. Otherwise it'll block the kernel forever. -- Close stdin so it can't be used. Otherwise it'll block the kernel forever.
dir <- liftIO getIHaskellDir dir <- liftIO getIHaskellDir
...@@ -173,9 +175,9 @@ getPackageConfigs dflags = ...@@ -173,9 +175,9 @@ getPackageConfigs dflags =
Just pkgDb = pkgDatabase dflags Just pkgDb = pkgDatabase dflags
-- | Initialize our GHC session with imports and a value for 'it'. Return whether the IHaskell -- | Initialize our GHC session with imports and a value for 'it'. Return whether the IHaskell
-- support libraries are available. -- library is available.
initializeImports :: Interpreter Bool initializeImports :: Bool -> Interpreter Bool
initializeImports = do initializeImports importSupportLibraries = do
-- Load packages that start with ihaskell-*, aren't just IHaskell, and depend directly on the right -- Load packages that start with ihaskell-*, aren't just IHaskell, and depend directly on the right
-- version of the ihaskell library. Also verify that the packages we load are not broken. -- version of the ihaskell library. Also verify that the packages we load are not broken.
dflags <- getSessionDynFlags dflags <- getSessionDynFlags
...@@ -229,10 +231,11 @@ initializeImports = do ...@@ -229,10 +231,11 @@ initializeImports = do
-- Import implicit prelude. -- Import implicit prelude.
importDecl <- parseImportDecl "import Prelude" importDecl <- parseImportDecl "import Prelude"
let implicitPrelude = importDecl { ideclImplicit = True } let implicitPrelude = importDecl { ideclImplicit = True }
displayImports' = if importSupportLibraries then displayImports else []
-- Import modules. -- Import modules.
imports <- mapM parseImportDecl $ requiredGlobalImports ++ if hasIHaskellPackage imports <- mapM parseImportDecl $ requiredGlobalImports ++ if hasIHaskellPackage
then ihaskellGlobalImports ++ displayImports then ihaskellGlobalImports ++ displayImports'
else [] else []
setContext $ map IIDecl $ implicitPrelude : imports setContext $ map IIDecl $ implicitPrelude : imports
......
...@@ -34,7 +34,7 @@ eval string = do ...@@ -34,7 +34,7 @@ eval string = do
getTemporaryDirectory >>= setCurrentDirectory getTemporaryDirectory >>= setCurrentDirectory
let state = defaultKernelState { getLintStatus = LintOff } let state = defaultKernelState { getLintStatus = LintOff }
_ <- interpret GHC.Paths.libdir False $ const $ _ <- interpret GHC.Paths.libdir False False $ const $
IHaskell.Eval.Evaluate.evaluate state string publish noWidgetHandling IHaskell.Eval.Evaluate.evaluate state string publish noWidgetHandling
out <- readIORef outputAccum out <- readIORef outputAccum
pagerout <- readIORef pagerAccum pagerout <- readIORef pagerAccum
......
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