Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 18 additions & 5 deletions src/Network/Gitit/Plugins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ import System.Log.Logger (logM, Priority(..))
#ifdef _PLUGINS
import Data.List (isInfixOf, isPrefixOf)
import GHC
import Control.Monad.IO.Class (liftIO)
import GHC.Driver.Session (PackageFlag(..), PackageArg(..), ModRenaming(..))
import GHC.Platform.Ways (Way(WayDyn), addWay, hostIsDynamic)
import GHC.Paths
import Unsafe.Coerce

Expand All @@ -37,15 +40,25 @@ loadPlugin pluginName = do
logM "gitit" WARNING ("Loading plugin '" ++ pluginName ++ "'...")
runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
setSessionDynFlags dflags
-- Honour package environment files (GHC_ENVIRONMENT or the default
-- environment), which only parseDynamicFlags reads otherwise.
logger <- getLogger
dflags' <- liftIO $ interpretPackageEnv logger dflags
-- Plugins always import Network.Gitit.Interface, so expose gitit even
-- when a package environment hides packages it does not list.
let exposeGitit = ExposePackage "-package gitit" (PackageArg "gitit")
(ModRenaming True [])
dflags'' = dflags' { packageFlags = exposeGitit : packageFlags dflags' }
-- A dynamically linked gitit can only load dynamic code, so look for
-- dynamic interface files and objects, as GHCi does.
setSessionDynFlags $
if hostIsDynamic
then dflags'' { targetWays_ = addWay WayDyn (targetWays_ dflags'') }
else dflags''
-- initDynFlags
unless ("Network.Gitit.Plugin." `isPrefixOf` pluginName)
$ do
#if __GLASGOW_HASKELL__ >= 904
addTarget =<< guessTarget pluginName Nothing Nothing
#else
addTarget =<< guessTarget pluginName Nothing
#endif
r <- load LoadAllTargets
case r of
Failed -> error $ "Error loading plugin: " ++ pluginName
Expand Down
Loading