halive 0.1.2 → 0.1.3
raw patch · 4 files changed
+40/−21 lines, 4 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
+ Halive.FindPackageDBs: updateDynFlagsWithGlobalDB :: MonadIO m => DynFlags -> m DynFlags
+ Halive.SubHalive: [gscMainThreadID] :: GHCSessionConfig -> Maybe ThreadId
- Halive.SubHalive: GHCSessionConfig :: FixDebounce -> [FilePath] -> [FilePath] -> FilePath -> [Extension] -> CompliationMode -> Maybe (FilePath, String) -> Int -> GHCSessionConfig
+ Halive.SubHalive: GHCSessionConfig :: FixDebounce -> [FilePath] -> [FilePath] -> FilePath -> [Extension] -> CompliationMode -> Maybe (FilePath, String) -> Int -> Maybe ThreadId -> GHCSessionConfig
Files
- halive.cabal +5/−1
- src/Halive/FindPackageDBs.hs +19/−11
- src/Halive/Recompiler.hs +4/−2
- src/Halive/SubHalive.hs +12/−7
halive.cabal view
@@ -2,7 +2,7 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: halive-version: 0.1.2+version: 0.1.3 synopsis: A live recompiler description: Live recompiler for Haskell@@ -71,6 +71,10 @@ -- Shouldn't ghc-prof-options override it anyway? Who knows. if !os(windows) ghc-options: -dynamic+ -- This overrides -dynamic when building for profiling,+ -- probably breaking the executable but at least it lets us build+ -- halive as a dependency.+ ghc-prof-options: -static -- ^ Required on Mac due to https://ghc.haskell.org/trac/ghc/ticket/9278 -- (does GHCi use this??) other-modules:
src/Halive/FindPackageDBs.hs view
@@ -1,17 +1,17 @@- {-# LANGUAGE LambdaCase #-}+{-# LANGUAGE ScopedTypeVariables #-} module Halive.FindPackageDBs where import Data.Maybe +import Control.Monad.IO.Class+import Data.Char+import Data.List import System.Directory import System.FilePath import System.Process-import Data.List-import Data.Char-import Control.Monad.IO.Class--import GHC+import Control.Exception import DynFlags+import GHC -- | Extract the sandbox package db directory from the cabal.sandbox.config file. -- Exception is thrown if the sandbox config file is broken.@@ -29,10 +29,10 @@ return $ if exists then (Just f) else (Nothing) addExtraPkgConfs :: DynFlags -> [FilePath] -> DynFlags-addExtraPkgConfs dflags pkgConfs = dflags - { extraPkgConfs = +addExtraPkgConfs dflags pkgConfs = dflags+ { extraPkgConfs = let newPkgConfs = map PkgConfFile pkgConfs- in (newPkgConfs ++) . extraPkgConfs dflags + in (newPkgConfs ++) . extraPkgConfs dflags } @@ -48,7 +48,7 @@ return $ (extractKey "package-db:" =<< config) updateDynFlagsWithCabalSandbox :: MonadIO m => DynFlags -> m DynFlags-updateDynFlagsWithCabalSandbox dflags = +updateDynFlagsWithCabalSandbox dflags = liftIO getSandboxDb >>= \case Nothing -> return dflags Just sandboxDB -> do@@ -70,9 +70,17 @@ return . Just . catMaybes $ map (flip extractKey pathInfo) ["local-pkg-db:", "snapshot-pkg-db:"] updateDynFlagsWithStackDB :: MonadIO m => DynFlags -> m DynFlags-updateDynFlagsWithStackDB dflags = +updateDynFlagsWithStackDB dflags = liftIO getStackDb >>= \case Nothing -> return dflags Just stackDBs -> do let pkgs = map PkgConfFile stackDBs return dflags { extraPkgConfs = (pkgs ++) . extraPkgConfs dflags }++updateDynFlagsWithGlobalDB :: MonadIO m => DynFlags -> m DynFlags+updateDynFlagsWithGlobalDB dflags = do+ xs <- liftIO $ lines <$> readProcess "ghc" ["--print-global-package-db"] ""+ `catch` (\(e :: SomeException) -> return [])+ case xs of+ [pkgconf] -> return dflags { extraPkgConfs = (PkgConfFile pkgconf :) . extraPkgConfs dflags }+ _ -> return dflags
src/Halive/Recompiler.hs view
@@ -40,7 +40,9 @@ ghcChan <- newTChanIO -- Grab this thread's ID (need to run this on the main thread, of course)- mainThreadID <- myThreadId+ mainThreadID <- case gscMainThreadID ghcSessionConfig of+ Just threadID -> return threadID+ Nothing -> myThreadId initialFileLock <- liftIO newEmptyMVar @@ -112,7 +114,7 @@ writeTChanIO ghcChan compilationRequest -- Recompile on file event notifications- fileEventListener <- case rccWatchAll of + fileEventListener <- case rccWatchAll of Nothing -> eventListenerForFile rccFilePath JustReportEvents Just (watchDir, fileTypes) -> eventListenerForDirectory watchDir fileTypes listenerThread <- forkIO . forever $ do
src/Halive/SubHalive.hs view
@@ -58,6 +58,7 @@ -- to work around a bug where the GHC API crashes while loading libraries -- if the main thread is doing work (possibly due to accessing said libraries in some way) , gscVerbosity :: Int+ , gscMainThreadID :: Maybe ThreadId } @@ -72,6 +73,7 @@ , gscCompilationMode = Interpreted , gscStartupFile = Nothing , gscVerbosity = 0+ , gscMainThreadID = Nothing } --pkgConfRefToString = \case@@ -88,9 +90,11 @@ withGHCSession :: ThreadId -> GHCSessionConfig -> Ghc a -> IO a withGHCSession mainThreadID GHCSessionConfig{..} action = do -- Work around https://ghc.haskell.org/trac/ghc/ticket/4162- let restoreControlC f = do+ let+ restoreControlC f = do liftIO $ installHandler sigINT (\_signal -> killThread mainThreadID) f+ -- defaultErrorHandler defaultFatalMessager defaultFlushOut $ runGhc (Just libdir) $ do runGhc (Just gscLibDir) . restoreControlC $ do -- Get the default dynFlags@@ -101,9 +105,10 @@ dflags2 <- updateDynFlagsWithCabalSandbox dflags1 -- If this is a stack project, add its package DBs dflags3 <- updateDynFlagsWithStackDB dflags2+ dflags4 <- updateDynFlagsWithGlobalDB dflags3 -- Make sure we're configured for live-reload- let dflags4 = dflags3 { hscTarget = if gscCompilationMode == Compiled then HscAsm else HscInterpreted+ let dflags5 = dflags4 { hscTarget = if gscCompilationMode == Compiled then HscAsm else HscInterpreted , optLevel = if gscCompilationMode == Compiled then 2 else 0 , ghcLink = LinkInMemory , ghcMode = CompManager@@ -121,13 +126,13 @@ -- about a half second (i.e., it won't recompile) -- This fixes that, but probably isn't quite what we want -- since it will cause extra files to be recompiled...- dflags5 = if gscFixDebounce == DebounceFix- then dflags4 `gopt_set` Opt_ForceRecomp- else dflags4- dflags6 = foldl xopt_set dflags5 gscLanguageExtensions+ dflags6 = if gscFixDebounce == DebounceFix+ then dflags5 `gopt_set` Opt_ForceRecomp+ else dflags5+ dflags7 = foldl xopt_set dflags6 gscLanguageExtensions -- We must call setSessionDynFlags before calling initPackages or any other GHC API- packageIDs <- setSessionDynFlags dflags6+ packageIDs <- setSessionDynFlags dflags7 -- Works around a yet-unidentified segfault when loading