@@ -115,6 +115,11 @@ runWatch = withProjectRoot "." $ \root -> do
115115 withGhciScript pkgs root $ \dotGhciPath ->
116116 runGhcid root True dotGhciPath pkgs Nothing
117117
118+exportGhciConfig :: MonadObelisk m => m [String]
119+exportGhciConfig = withProjectRoot "." $ \root -> do
120+ pkgs <- fmap toList . parsePackagesOrFail =<< getLocalPkgs root
121+ getGhciSessionSettings pkgs "."
122+
118123-- | Relative paths to local packages of an obelisk project.
119124--
120125-- These are a combination of the obelisk predefined local packages,
@@ -274,7 +279,7 @@ withGhciScript
274279 -> (FilePath -> m ()) -- ^ Action to run with the path to generated temporary .ghci
275280 -> m ()
276281withGhciScript packageInfos pathBase f = do
277− selfExe <- liftIO getExecutablePath
282+ ghciSettings <- getGhciSessionSettings packageInfos pathBase
278283 let
279284 packageNames = Set.fromList $ map _cabalPackageInfo_packageName packageInfos
280285 modulesToLoad = mconcat
@@ -283,9 +288,7 @@ withGhciScript packageInfos pathBase f = do
283288 , [ "Frontend" | "frontend" `Set.member` packageNames ]
284289 ]
285290 dotGhci = unlines
286− -- TODO: Shell escape
287− [ ":set -F -pgmF " <> selfExe <> " -optF " <> preprocessorIdentifier <> " " <> unwords (map (("-optF " <>) . makeRelative pathBase . _cabalPackageInfo_packageFile) packageInfos)
288− , ":set -i" <> intercalate ":" (packageInfos >>= rootedSourceDirs)
291+ [ ":set " <> unwords ghciSettings -- TODO: Shell escape
289292 , if null modulesToLoad then "" else ":load " <> unwords modulesToLoad
290293 , "import qualified Obelisk.Run"
291294 , "import qualified Frontend"
@@ -296,6 +299,20 @@ withGhciScript packageInfos pathBase f = do
296299 liftIO $ writeFile dotGhciPath dotGhci
297300 f dotGhciPath
298301
302+-- | Builds a list of options to pass to ghci or set in .ghci file that configures
303+-- the preprocessor and source includes.
304+getGhciSessionSettings
305+ :: MonadObelisk m
306+ => [CabalPackageInfo] -- ^ List of packages to load into ghci
307+ -> FilePath -- ^ All paths written to the .ghci file will be relative to this path
308+ -> m [String]
309+getGhciSessionSettings packageInfos pathBase = do
310+ selfExe <- liftIO getExecutablePath
311+ -- TODO: Shell escape
312+ pure
313+ $ ["-F", "-pgmF", selfExe, "-optF", preprocessorIdentifier]
314+ <> concatMap (\p -> ["-optF", makeRelative pathBase $ _cabalPackageInfo_packageFile p]) packageInfos
315+ <> [ "-i" <> intercalate ":" (packageInfos >>= rootedSourceDirs) ]
299316 where
300317 rootedSourceDirs pkg = NE.toList $
301318 makeRelative pathBase . (_cabalPackageInfo_packageRoot pkg </>) <$> _cabalPackageInfo_sourceDirs pkg