@@ -16,7 +16,6 @@ module Stack.Ghci
1616 , ghci
1717
1818 -- TODO: Address what should and should not be exported.
19- , renderLegacyGhciScript
2019 , renderScriptGhci
2120 , renderScriptIntero
2221 ) where
@@ -35,7 +34,6 @@ import Data.Either
3534import Data.Function
3635import Data.List
3736import Data.List.Extra (nubOrd )
38- import Data.List.Split (splitOn )
3937import Data.Map.Strict (Map )
4038import qualified Data.Map.Strict as M
4139import Data.Maybe
@@ -64,7 +62,6 @@ import Stack.Ghci.Script
6462import Stack.Package
6563import Stack.Types
6664import Stack.Types.Internal
67- import System.FilePath (takeBaseName )
6865import Text.Read (readMaybe )
6966
7067#ifndef WINDOWS
@@ -142,25 +139,8 @@ ghci opts@GhciOpts{..} = do
142139 $ logWarn
143140 (" The following GHC options are incompatible with GHCi and have not been passed to it: " <>
144141 T. unwords (map T. pack (nubOrd omittedOpts)))
145- allModules <- checkForDuplicateModules ghciNoLoadModules pkgs
142+ mainFile <- figureOutMainFile bopts mainIsTargets targets pkgs
146143 oiDir <- objectInterfaceDir bconfig
147- (modulesToLoad, mainFile) <- if ghciNoLoadModules then return ([] , Nothing ) else do
148- mmainFile <- figureOutMainFile bopts mainIsTargets targets pkgs
149- modulesToLoad <- case mmainFile of
150- Just mainFile -> do
151- let (_, mfDirs, mfName) = filePathPieces mainFile
152- mainPathPieces = map toFilePath mfDirs ++ [takeBaseName (toFilePath mfName)]
153- liftM catMaybes $ forM allModules $ \ mn -> do
154- let matchesModule = splitOn " ." mn `isSuffixOf` mainPathPieces
155- if matchesModule
156- then do
157- $ logWarn $ " Warning: Omitting load of module " <> T. pack mn <>
158- " , because it matches the filepath of the Main target, " <>
159- T. pack (toFilePath mainFile)
160- return Nothing
161- else return (Just mn)
162- Nothing -> return allModules
163- return (modulesToLoad, mmainFile)
164144 let odir =
165145 [ " -odir=" <> toFilePathNoTrailingSep oiDir
166146 , " -hidir=" <> toFilePathNoTrailingSep oiDir ]
@@ -182,6 +162,7 @@ ghci opts@GhciOpts{..} = do
182162 if ghciNoLoadModules
183163 then execGhci macrosOptions
184164 else do
165+ checkForDuplicateModules pkgs
185166 scriptPath <- writeGhciScript tmpDirectory (renderScriptGhci pkgs mainFile)
186167 execGhci (macrosOptions ++ [" -ghci-script=" <> toFilePath scriptPath])
187168
@@ -201,17 +182,6 @@ writeGhciScript tmpDirectory script = do
201182 scriptPath = tmpDirectory </> $ (mkRelFile " ghci-script" )
202183 scriptFilePath = toFilePath scriptPath
203184
204- renderLegacyGhciScript :: [String ] -> Maybe (Path b t ) -> String
205- renderLegacyGhciScript modulesToLoad mainFile =
206- let loadModules = " :add" <> case unwords (map quoteFileName modulesToLoad) of
207- [] -> " "
208- xs -> " " <> xs
209- addMainFile = maybe " " ((" :add " <> ) . quoteFileName . toFilePath) mainFile
210- bringIntoScope = " :module +" <> case unwords modulesToLoad of
211- [] -> " "
212- xs -> " " <> xs
213- in unlines [loadModules,addMainFile,bringIntoScope]
214-
215185findOwningPackageForMain :: [GhciPkgInfo ] -> Path Abs File -> Maybe GhciPkgInfo
216186findOwningPackageForMain pkgs mainFile =
217187 find (\ pkg -> toFilePath (ghciPkgDir pkg) `isPrefixOf` toFilePath mainFile) pkgs
@@ -554,15 +524,14 @@ borderedWarning f = do
554524 $ logWarn " "
555525 return x
556526
557- checkForDuplicateModules :: (MonadThrow m , MonadLogger m ) => Bool -> [GhciPkgInfo ] -> m [ String ]
558- checkForDuplicateModules noLoadModules pkgs = do
527+ checkForDuplicateModules :: (MonadThrow m , MonadLogger m ) => [GhciPkgInfo ] -> m ()
528+ checkForDuplicateModules pkgs = do
559529 unless (null duplicates) $ do
560530 borderedWarning $ do
561531 $ logWarn " The following modules are present in multiple packages:"
562532 forM_ duplicates $ \ (mn, pns) -> do
563533 $ logWarn (" * " <> T. pack mn <> " (in " <> T. intercalate " , " (map packageNameText pns) <> " )" )
564- unless noLoadModules $ throwM LoadingDuplicateModules
565- return (map fst allModules)
534+ throwM LoadingDuplicateModules
566535 where
567536 duplicates , allModules :: [(String , [PackageName ])]
568537 duplicates = filter (not . null . tail . snd ) allModules
@@ -635,13 +604,6 @@ setScriptPerms fp = do
635604 ]
636605#endif
637606
638- filePathPieces :: Path Abs File -> (Path Abs Dir , [Path Rel Dir ], Path Rel File )
639- filePathPieces x0 = go (parent x0, [] , filename x0)
640- where
641- go (x, dirs, fp)
642- | parent x == x = (x, dirs, fp)
643- | otherwise = (parent x, dirname x : dirs, fp)
644-
645607{- Copied from Stack.Ide, may be useful in the future
646608
647609-- | Get options and target files for the given package info.
@@ -683,10 +645,3 @@ targetsCmd target go@GlobalOpts{..} =
683645 (mapM (getPackageOptsAndTargetFiles pwd) pkgs)
684646 forM_ targets (liftIO . putStrLn)
685647-}
686-
687- -- | Make sure that a filename with spaces in it gets the proper quotes.
688- quoteFileName :: String -> String
689- quoteFileName x =
690- if any (== ' ' ) x
691- then show x
692- else x
0 commit comments