Skip to content

Commit 7e5b030

Browse files
committed
Use ghc-options settings with ghci #1353
1 parent bfc0d04 commit 7e5b030

File tree

2 files changed

+23
-25
lines changed

2 files changed

+23
-25
lines changed

src/Stack/Ghci.hs

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ data GhciOpts = GhciOpts
6666
data GhciPkgInfo = GhciPkgInfo
6767
{ ghciPkgName :: !PackageName
6868
, ghciPkgOpts :: ![(NamedComponent, BuildInfoOpts)]
69-
, ghciPkgOmittedOpts :: ![String]
7069
, ghciPkgDir :: !(Path Abs Dir)
7170
, ghciPkgModules :: !(Set ModuleName)
7271
, ghciPkgModFiles :: !(Set (Path Abs File)) -- ^ Module file paths.
@@ -87,14 +86,26 @@ ghci GhciOpts{..} = do
8786
, boptsBenchmarkOpts = (boptsBenchmarkOpts ghciBuildOpts) { beoDisableRun = True }
8887
}
8988
(targets,mainIsTargets,pkgs) <- ghciSetup bopts ghciNoBuild ghciMainIs
89+
config <- asks getConfig
9090
bconfig <- asks getBuildConfig
9191
mainFile <- figureOutMainFile bopts mainIsTargets targets pkgs
9292
wc <- getWhichCompiler
93-
let pkgopts =
94-
(if null pkgs then [] else ["-hide-all-packages"]) ++
95-
nubOrd (concatMap (concatMap (bioGeneratedOpts . snd) . ghciPkgOpts) pkgs) ++
96-
concatMap (concatMap (bioGhcOpts . snd) . ghciPkgOpts) pkgs
97-
modulesToLoad = nubOrd $
93+
let pkgopts = hidePkgOpt ++ genOpts ++ ghcOpts
94+
hidePkgOpt = if null pkgs then [] else ["-hide-all-packages"]
95+
genOpts = nubOrd (concatMap (concatMap (bioGeneratedOpts . snd) . ghciPkgOpts) pkgs)
96+
(omittedOpts, ghcOpts) = partition badForGhci $
97+
concatMap (concatMap (bioGhcOpts . snd) . ghciPkgOpts) pkgs ++
98+
getUserOptions Nothing ++
99+
concatMap (getUserOptions . Just . ghciPkgName) pkgs
100+
getUserOptions mpkg =
101+
map T.unpack (M.findWithDefault [] mpkg (configGhcOptions config))
102+
badForGhci x =
103+
isPrefixOf "-O" x || elem x (words "-debug -threaded -ticky -static")
104+
unless (null omittedOpts) $
105+
$logWarn
106+
("The following GHC options are incompatible with GHCi and have not been passed to it: " <>
107+
T.unwords (map T.pack (nubOrd omittedOpts)))
108+
let modulesToLoad = nubOrd $
98109
maybe [] (return . toFilePath) mainFile <>
99110
concatMap (map display . S.toList . ghciPkgModules) pkgs
100111
odir =
@@ -269,30 +280,23 @@ makeGhciPkgInfo bopts sourceMap installedMap locals name cabalfp target = do
269280
, packageConfigPlatform = configPlatform (getConfig bconfig)
270281
}
271282
(warnings,pkg) <- readPackage config cabalfp
272-
let filterWanted = M.filterWithKey (\k _ -> k `S.member` allWanted)
273-
allWanted = wantedPackageComponents bopts target pkg
274283
mapM_ (printCabalFileWarning cabalfp) warnings
275284
(mods,files,opts) <- getPackageOpts (packageOpts pkg) sourceMap installedMap locals cabalfp
276285
let filteredOpts = filterWanted opts
277-
omitUnwanted bio = bio { bioGhcOpts = filter (not . badForGhci) (bioGhcOpts bio) }
278-
omitted = filter badForGhci $ concatMap bioGhcOpts (M.elems filteredOpts)
286+
filterWanted = M.filterWithKey (\k _ -> k `S.member` allWanted)
287+
allWanted = wantedPackageComponents bopts target pkg
288+
setMapMaybe f = S.fromList . mapMaybe f . S.toList
279289
return
280290
GhciPkgInfo
281291
{ ghciPkgName = packageName pkg
282-
, ghciPkgOpts = M.toList (M.map omitUnwanted filteredOpts)
283-
, ghciPkgOmittedOpts = omitted
292+
, ghciPkgOpts = M.toList filteredOpts
284293
, ghciPkgDir = parent cabalfp
285294
, ghciPkgModules = mconcat (M.elems (filterWanted mods))
286295
, ghciPkgModFiles = mconcat (M.elems (filterWanted (M.map (setMapMaybe dotCabalModulePath) files)))
287296
, ghciPkgMainIs = M.map (setMapMaybe dotCabalMainPath) files
288297
, ghciPkgCFiles = mconcat (M.elems (filterWanted (M.map (setMapMaybe dotCabalCFilePath) files)))
289298
, ghciPkgPackage = pkg
290299
}
291-
where
292-
badForGhci :: String -> Bool
293-
badForGhci x =
294-
isPrefixOf "-O" x || elem x (words "-debug -threaded -ticky -static")
295-
setMapMaybe f = S.fromList . mapMaybe f . S.toList
296300

297301
-- NOTE: this should make the same choices as the components code in
298302
-- 'loadLocalPackage'. Unfortunately for now we reiterate this logic
@@ -308,11 +312,6 @@ wantedPackageComponents _ _ _ = S.empty
308312

309313
checkForIssues :: (MonadThrow m, MonadLogger m) => [GhciPkgInfo] -> m ()
310314
checkForIssues pkgs = do
311-
let omitted = concatMap ghciPkgOmittedOpts pkgs
312-
unless (null omitted) $
313-
$logWarn
314-
("The following GHC options are incompatible with GHCi and have not been passed to it: " <>
315-
T.unwords (map T.pack (nubOrd omitted)))
316315
unless (null issues) $ borderedWarning $ do
317316
$logWarn "There are issues with this project which may prevent GHCi from working properly."
318317
$logWarn ""

src/Stack/Types/Build.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,9 @@ configureOptsNoDir econfig bco deps wanted isLocal package = concat
724724
where
725725
PackageIdentifier name version = ident
726726

727-
ghcOptionsMap = configGhcOptions $ getConfig econfig
728727
allGhcOptions = concat
729-
[ Map.findWithDefault [] Nothing ghcOptionsMap
730-
, Map.findWithDefault [] (Just $ packageName package) ghcOptionsMap
728+
[ Map.findWithDefault [] Nothing (configGhcOptions config)
729+
, Map.findWithDefault [] (Just $ packageName package) (configGhcOptions config)
731730
, if includeExtraOptions
732731
then boptsGhcOptions bopts
733732
else []

0 commit comments

Comments
 (0)