@@ -115,6 +115,11 @@ runWatch = withProjectRoot "." $ \root -> do
115 withGhciScript pkgs root $ \dotGhciPath ->
115 withGhciScript pkgs root $ \dotGhciPath ->
116 runGhcid root True dotGhciPath pkgs Nothing
116 runGhcid root True dotGhciPath pkgs Nothing
118+exportGhciConfig :: MonadObelisk m => m [String]
119+exportGhciConfig = withProjectRoot "." $ \root -> do
120+ pkgs <- fmap toList . parsePackagesOrFail =<< getLocalPkgs root
121+ getGhciSessionSettings pkgs "."
118-- | Relative paths to local packages of an obelisk project.
123-- | Relative paths to local packages of an obelisk project.
120-- These are a combination of the obelisk predefined local packages,
125-- These are a combination of the obelisk predefined local packages,
@@ -274,7 +279,7 @@ withGhciScript
274 -> (FilePath -> m ()) -- ^ Action to run with the path to generated temporary .ghci
279 -> (FilePath -> m ()) -- ^ Action to run with the path to generated temporary .ghci
276withGhciScript packageInfos pathBase f = do
281withGhciScript packageInfos pathBase f = do
277− selfExe <- liftIO getExecutablePath
282+ ghciSettings <- getGhciSessionSettings packageInfos pathBase
279 packageNames = Set.fromList $ map _cabalPackageInfo_packageName packageInfos
284 packageNames = Set.fromList $ map _cabalPackageInfo_packageName packageInfos
280 modulesToLoad = mconcat
285 modulesToLoad = mconcat
@@ -283,9 +288,7 @@ withGhciScript packageInfos pathBase f = do
283 , [ "Frontend" | "frontend" `Set.member` packageNames ]
288 , [ "Frontend" | "frontend" `Set.member` packageNames ]
285 dotGhci = unlines
290 dotGhci = unlines
286− -- TODO: Shell escape
291+ [ ":set " <> unwords ghciSettings -- TODO: Shell escape
287− [ ":set -F -pgmF " <> selfExe <> " -optF " <> preprocessorIdentifier <> " " <> unwords (map (("-optF " <>) . makeRelative pathBase . _cabalPackageInfo_packageFile) packageInfos)
288− , ":set -i" <> intercalate ":" (packageInfos >>= rootedSourceDirs)
289 , if null modulesToLoad then "" else ":load " <> unwords modulesToLoad
292 , if null modulesToLoad then "" else ":load " <> unwords modulesToLoad
290 , "import qualified Obelisk.Run"
293 , "import qualified Obelisk.Run"
291 , "import qualified Frontend"
294 , "import qualified Frontend"
@@ -296,6 +299,20 @@ withGhciScript packageInfos pathBase f = do
296 liftIO $ writeFile dotGhciPath dotGhci
299 liftIO $ writeFile dotGhciPath dotGhci
297 f dotGhciPath
300 f dotGhciPath
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
306+ => [CabalPackageInfo] -- ^ List of packages to load into ghci
307+ -> FilePath -- ^ All paths written to the .ghci file will be relative to this path
309+getGhciSessionSettings packageInfos pathBase = do
310+ selfExe <- liftIO getExecutablePath
311+ -- TODO: Shell escape
313+ $ ["-F", "-pgmF", selfExe, "-optF", preprocessorIdentifier]
314+ <> concatMap (\p -> ["-optF", makeRelative pathBase $ _cabalPackageInfo_packageFile p]) packageInfos
315+ <> [ "-i" <> intercalate ":" (packageInfos >>= rootedSourceDirs) ]
300 rootedSourceDirs pkg = NE.toList $
317 rootedSourceDirs pkg = NE.toList $
301 makeRelative pathBase . (_cabalPackageInfo_packageRoot pkg </>) <$> _cabalPackageInfo_sourceDirs pkg
318 makeRelative pathBase . (_cabalPackageInfo_packageRoot pkg </>) <$> _cabalPackageInfo_sourceDirs pkg