Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show resolver being used when stack ghci is invoked outside of a project directory #4521

Merged
merged 13 commits into from
Feb 10, 2019
2 changes: 2 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ Other enhancements:
[#4463](https://github.com/commercialhaskell/stack/issues/4463)
* Add `--cabal-files` flag to `stack ide targets` command.
* Add `--stdout` flag to all `stack ide` subcommands.
* Show resolver being used when `stack ghci` is invoked outside of a project directory. See
[#3651](https://github.com/commercialhaskell/stack/issues/3651)

Bug fixes:

Expand Down
22 changes: 18 additions & 4 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import qualified Data.ByteString.Char8 as S8
import qualified Data.ByteString.Lazy as LBS
import Data.List
import qualified Data.Map.Strict as M
import Data.Maybe
import qualified Data.Set as S
import qualified Data.Text as T
import qualified Data.Text.Lazy as TL
Expand All @@ -41,7 +42,9 @@ import Stack.Ghci.Script
import Stack.Package
import Stack.PrettyPrint
import Stack.Setup (withNewLocalBuildTargets)
import Stack.Snapshot (loadResolver)
import Stack.Types.Build
import Stack.Types.BuildPlan (sdResolverName)
import Stack.Types.Compiler
import Stack.Types.Config
import Stack.Types.NamedComponent
Expand Down Expand Up @@ -186,8 +189,12 @@ ghci opts@GhciOpts{..} = do
figureOutMainFile bopts mainIsTargets localTargets pkgs0
-- Build required dependencies and setup local packages.
stackYaml <- view stackYamlL

mproject <- view $ configL.to configMaybeProject

buildDepsAndInitialSteps opts (map (T.pack . packageNameString . fst) localTargets)
targetWarnings stackYaml localTargets nonLocalTargets mfileTargets

wafelj marked this conversation as resolved.
Show resolved Hide resolved
targetWarnings stackYaml localTargets nonLocalTargets mfileTargets mproject
-- Load the list of modules _after_ building, to catch changes in
-- unlisted dependencies (#1180)
pkgs <- getGhciPkgInfos installMap addPkgs (fmap fst mfileTargets) pkgDescs
Expand Down Expand Up @@ -836,13 +843,14 @@ checkForDuplicateModules pkgs = do
pretty fp <+> parens (fillSep (punctuate "," (map displayPkgComponent (S.toList comps))))

targetWarnings
:: HasRunner env
:: HasEnvConfig env
=> Path Abs File
-> [(PackageName, (Path Abs File, Target))]
-> [PackageName]
-> Maybe (Map PackageName [Path Abs File], [Path Abs File])
-> Maybe (Project, Path Abs File)
-> RIO env ()
targetWarnings stackYaml localTargets nonLocalTargets mfileTargets = do
targetWarnings stackYaml localTargets nonLocalTargets mfileTargets mproject = do
wafelj marked this conversation as resolved.
Show resolved Hide resolved
unless (null nonLocalTargets) $
prettyWarnL
[ flow "Some targets"
Expand All @@ -853,10 +861,16 @@ targetWarnings stackYaml localTargets nonLocalTargets mfileTargets = do
, "."
, flow "It can still be useful to specify these, as they will be passed to ghci via -package flags."
]
when (null localTargets && isNothing mfileTargets) $

when (null localTargets && isNothing mfileTargets) $ do
let project = fst $ fromJust mproject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if there is no currently known way for this to be Nothing, there could possibly be a way now or in the future, and the error thrown by fromJust is pretty frustratingly vague.

How about instead, for the Nothing case, using something like error "Invariant violated: no project". One nice thing about using error is that it will show where in stack's code the error occurred.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, ignoring the Nothing case is pretty ugly. I was thinking about this some more and decided to try something else: simply not print the resolver version if the project is Nothing. Would this work? I can do the error instead, but it's basically the same thing I had before, except it has a more useful error message.

resolver <- loadResolver (projectResolver project) (projectCompiler project)

prettyNote $ vsep
[ flow "No local targets specified, so a plain ghci will be started with no package hiding or package options."
, ""
, flow $ "You are using resolver: " ++ T.unpack (sdResolverName resolver)
, ""
, flow "If you want to use package hiding and options, then you can try one of the following:"
, ""
, bulletedList
Expand Down