From 10106966a7b415acc0da60288a87bb0685e47b7b Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Sun, 20 Jan 2019 13:28:26 +0100 Subject: [PATCH 01/11] Print resolver when using GHCi with global project --- src/Stack/Ghci.hs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 3443b22a2a..3c1ac24b3d 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -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 @@ -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 (SnapshotDef, sdResolverName) import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.NamedComponent @@ -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 + + 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 @@ -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 unless (null nonLocalTargets) $ prettyWarnL [ flow "Some targets" @@ -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 + 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 From 3ff4da87462be3a86d825daf94c4cbd6206e93d4 Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Sun, 20 Jan 2019 13:31:35 +0100 Subject: [PATCH 02/11] Updated ChangeLog.md --- ChangeLog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index df1a21bbff..68a7b91f0f 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -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: From f2ebbcd86b55b07d2d7d5ae1cd232bcd679e901f Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Sun, 20 Jan 2019 13:43:21 +0100 Subject: [PATCH 03/11] hlint style fix --- src/Stack/Ghci.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 3c1ac24b3d..6885c8097b 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -869,7 +869,7 @@ targetWarnings stackYaml localTargets nonLocalTargets mfileTargets mproject = do 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 $ "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:" , "" From 2f15af67bc399f6bbd879231c7e908146c701ccd Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Sun, 20 Jan 2019 14:39:48 +0100 Subject: [PATCH 04/11] Removed redundant import --- src/Stack/Ghci.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 6885c8097b..4e9f08f27f 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -44,7 +44,7 @@ import Stack.PrettyPrint import Stack.Setup (withNewLocalBuildTargets) import Stack.Snapshot (loadResolver) import Stack.Types.Build -import Stack.Types.BuildPlan (SnapshotDef, sdResolverName) +import Stack.Types.BuildPlan (sdResolverName) import Stack.Types.Compiler import Stack.Types.Config import Stack.Types.NamedComponent From 0b557b9b97a376e51e4b06e3dbf083b63361f030 Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Mon, 21 Jan 2019 20:40:27 +0100 Subject: [PATCH 05/11] Moved getters to targetWarnings function --- src/Stack/Ghci.hs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 4e9f08f27f..9081397241 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -188,13 +188,8 @@ ghci opts@GhciOpts{..} = do pkgs0 <- getGhciPkgInfos installMap addPkgs (fmap fst mfileTargets) pkgDescs 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 mproject + targetWarnings localTargets nonLocalTargets mfileTargets -- Load the list of modules _after_ building, to catch changes in -- unlisted dependencies (#1180) pkgs <- getGhciPkgInfos installMap addPkgs (fmap fst mfileTargets) pkgDescs @@ -844,13 +839,11 @@ checkForDuplicateModules pkgs = do targetWarnings :: HasEnvConfig env - => Path Abs File - -> [(PackageName, (Path Abs File, Target))] + => [(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 mproject = do +targetWarnings localTargets nonLocalTargets mfileTargets = do unless (null nonLocalTargets) $ prettyWarnL [ flow "Some targets" @@ -861,11 +854,11 @@ targetWarnings stackYaml localTargets nonLocalTargets mfileTargets mproject = 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) $ do + stackYaml <- view stackYamlL + mproject <- view $ configL.to configMaybeProject let project = fst $ fromJust mproject 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." , "" From 8d7aa01eab987f1d87ccd3915bdb7c61e94f219b Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Mon, 21 Jan 2019 21:39:59 +0100 Subject: [PATCH 06/11] Don't print resolver if project is Nothing --- src/Stack/Ghci.hs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 9081397241..9de65b8dc4 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -857,14 +857,21 @@ targetWarnings localTargets nonLocalTargets mfileTargets = do when (null localTargets && isNothing mfileTargets) $ do stackYaml <- view stackYamlL mproject <- view $ configL.to configMaybeProject - let project = fst $ fromJust mproject - resolver <- loadResolver (projectResolver project) (projectCompiler project) - prettyNote $ vsep + resolverMsg <- + case mproject of + Just (p, _) -> do + resolver <- loadResolver (projectResolver p) (projectCompiler p) + return [ flow $ "You are using resolver: " ++ T.unpack (sdResolverName resolver) + , "" + ] + Nothing -> + return [] + 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:" + ] ++ + resolverMsg ++ + [ flow "If you want to use package hiding and options, then you can try one of the following:" , "" , bulletedList [ fillSep From b04491534a179f33ec62c251c2d1c4e7234215db Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Tue, 22 Jan 2019 21:35:35 +0100 Subject: [PATCH 07/11] Fixed merge --- src/Stack/Ghci.hs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 671bf52a7c..5a4ea4c660 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -839,6 +839,7 @@ checkForDuplicateModules pkgs = do targetWarnings :: HasEnvConfig env + => [(PackageName, (Path Abs File, Target))] -> [PackageName] -> Maybe (Map PackageName [Path Abs File], [Path Abs File]) -> RIO env () From 98d7c01d163cb4c0b7014ff2d5ecd9675d5a9da0 Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Tue, 22 Jan 2019 21:52:16 +0100 Subject: [PATCH 08/11] Removed redundant import --- src/Stack/Ghci.hs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 5a4ea4c660..5ee7c35f83 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -21,7 +21,6 @@ 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 From f84590616764b1b4d30c1d1c7c174a8b60b67214 Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Wed, 23 Jan 2019 21:28:14 +0100 Subject: [PATCH 09/11] Read resolver name from sourcemap instead of project --- src/Stack/Build/Source.hs | 1 + src/Stack/Config.hs | 1 + src/Stack/Ghci.hs | 22 ++++++---------------- src/Stack/SourceMap.hs | 1 + src/Stack/Types/SourceMap.hs | 3 +++ 5 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/Stack/Build/Source.hs b/src/Stack/Build/Source.hs index 29a09d6d9e..428d736c01 100644 --- a/src/Stack/Build/Source.hs +++ b/src/Stack/Build/Source.hs @@ -116,6 +116,7 @@ loadSourceMap smt boptsCli sma = do , smDeps = deps , smGlobal = globals , smHash = smh + , smName = smaName sma } -- | Get a 'SourceMapHash' for a given 'SourceMap' diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index 4e1bbee76d..3f72fc1f27 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -641,6 +641,7 @@ loadBuildConfig mproject maresolver mcompiler = do { smwCompiler = fromMaybe (snapshotCompiler snapshot) mcompiler , smwProject = packages , smwDeps = deps + , smwName = snapshotName snapshot } return BuildConfig diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 5ee7c35f83..48d6558391 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -41,9 +41,7 @@ import Stack.Constants.Config import Stack.Ghci.Script import Stack.Package 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 @@ -151,6 +149,7 @@ ghci opts@GhciOpts{..} = do , smaProject = smProject sourceMap , smaDeps = smDeps sourceMap , smaGlobal = smGlobal sourceMap + , smaName = smName sourceMap } -- Parse --main-is argument. mainIsTargets <- parseMainIsTargets buildOptsCLI sma ghciMainIs @@ -854,23 +853,14 @@ targetWarnings 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) $ do + sourceMap <- view $ envConfigL.to envConfigSourceMap stackYaml <- view stackYamlL - mproject <- view $ configL.to configMaybeProject - resolverMsg <- - case mproject of - Just (p, _) -> do - resolver <- loadResolver (projectResolver p) (projectCompiler p) - return [ flow $ "You are using resolver: " ++ T.unpack (sdResolverName resolver) - , "" - ] - Nothing -> - return [] - prettyNote $ vsep $ + prettyNote $ vsep [ flow "No local targets specified, so a plain ghci will be started with no package hiding or package options." , "" - ] ++ - resolverMsg ++ - [ flow "If you want to use package hiding and options, then you can try one of the following:" + , flow $ "You are using resolver: " ++ T.unpack (smName sourceMap) + , "" + , flow "If you want to use package hiding and options, then you can try one of the following:" , "" , bulletedList [ fillSep diff --git a/src/Stack/SourceMap.hs b/src/Stack/SourceMap.hs index 830efd2134..ae7420ae55 100644 --- a/src/Stack/SourceMap.hs +++ b/src/Stack/SourceMap.hs @@ -163,6 +163,7 @@ toActual smw downloadCompiler ac = do , smaProject = smwProject smw , smaDeps = smwDeps smw , smaGlobal = globals + , smaName = smwName smw } checkFlagsUsedThrowing :: diff --git a/src/Stack/Types/SourceMap.hs b/src/Stack/Types/SourceMap.hs index a2f94196a5..60f3abde61 100644 --- a/src/Stack/Types/SourceMap.hs +++ b/src/Stack/Types/SourceMap.hs @@ -78,6 +78,7 @@ data SMWanted = SMWanted { smwCompiler :: !WantedCompiler , smwProject :: !(Map PackageName ProjectPackage) , smwDeps :: !(Map PackageName DepPackage) + , smwName :: !Text } -- | Adds in actual compiler information to 'SMWanted', in particular @@ -89,6 +90,7 @@ data SMActual = SMActual , smaProject :: !(Map PackageName ProjectPackage) , smaDeps :: !(Map PackageName DepPackage) , smaGlobal :: !(Map PackageName GlobalPackage) + , smaName :: !Text } -- | How a package is intended to be built @@ -134,6 +136,7 @@ data SourceMap = SourceMap , smHash :: !SourceMapHash -- ^ hash of the source map calculated once as an expensive -- operation + , smName :: !Text } -- | A unique hash for the immutable portions of a 'SourceMap'. From 3dfd3b19f41ac1111465ce76ed4576eb147ca545 Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Thu, 24 Jan 2019 20:37:52 +0100 Subject: [PATCH 10/11] Read snapshot name directly from BuildConfig --- ChangeLog.md | 2 +- src/Stack/Build/Source.hs | 1 - src/Stack/Config.hs | 2 +- src/Stack/Ghci.hs | 5 ++--- src/Stack/SourceMap.hs | 1 - src/Stack/Types/SourceMap.hs | 4 +--- 6 files changed, 5 insertions(+), 10 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 68a7b91f0f..1e6d22fd3b 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -81,7 +81,7 @@ 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 +* Show snapshot being used when `stack ghci` is invoked outside of a project directory. See [#3651](https://github.com/commercialhaskell/stack/issues/3651) Bug fixes: diff --git a/src/Stack/Build/Source.hs b/src/Stack/Build/Source.hs index 428d736c01..29a09d6d9e 100644 --- a/src/Stack/Build/Source.hs +++ b/src/Stack/Build/Source.hs @@ -116,7 +116,6 @@ loadSourceMap smt boptsCli sma = do , smDeps = deps , smGlobal = globals , smHash = smh - , smName = smaName sma } -- | Get a 'SourceMapHash' for a given 'SourceMap' diff --git a/src/Stack/Config.hs b/src/Stack/Config.hs index 3f72fc1f27..e9133decea 100644 --- a/src/Stack/Config.hs +++ b/src/Stack/Config.hs @@ -641,7 +641,7 @@ loadBuildConfig mproject maresolver mcompiler = do { smwCompiler = fromMaybe (snapshotCompiler snapshot) mcompiler , smwProject = packages , smwDeps = deps - , smwName = snapshotName snapshot + , smwSnapshotName = snapshotName snapshot } return BuildConfig diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 48d6558391..446a854f1a 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -149,7 +149,6 @@ ghci opts@GhciOpts{..} = do , smaProject = smProject sourceMap , smaDeps = smDeps sourceMap , smaGlobal = smGlobal sourceMap - , smaName = smName sourceMap } -- Parse --main-is argument. mainIsTargets <- parseMainIsTargets buildOptsCLI sma ghciMainIs @@ -853,12 +852,12 @@ targetWarnings 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) $ do - sourceMap <- view $ envConfigL.to envConfigSourceMap + smWanted <- view $ buildConfigL.to bcSMWanted stackYaml <- view stackYamlL 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 (smName sourceMap) + , flow $ "You are using snapshot: " ++ T.unpack (smwSnapshotName smWanted) , "" , flow "If you want to use package hiding and options, then you can try one of the following:" , "" diff --git a/src/Stack/SourceMap.hs b/src/Stack/SourceMap.hs index ae7420ae55..830efd2134 100644 --- a/src/Stack/SourceMap.hs +++ b/src/Stack/SourceMap.hs @@ -163,7 +163,6 @@ toActual smw downloadCompiler ac = do , smaProject = smwProject smw , smaDeps = smwDeps smw , smaGlobal = globals - , smaName = smwName smw } checkFlagsUsedThrowing :: diff --git a/src/Stack/Types/SourceMap.hs b/src/Stack/Types/SourceMap.hs index 60f3abde61..d858c4da37 100644 --- a/src/Stack/Types/SourceMap.hs +++ b/src/Stack/Types/SourceMap.hs @@ -78,7 +78,7 @@ data SMWanted = SMWanted { smwCompiler :: !WantedCompiler , smwProject :: !(Map PackageName ProjectPackage) , smwDeps :: !(Map PackageName DepPackage) - , smwName :: !Text + , smwSnapshotName :: !Text } -- | Adds in actual compiler information to 'SMWanted', in particular @@ -90,7 +90,6 @@ data SMActual = SMActual , smaProject :: !(Map PackageName ProjectPackage) , smaDeps :: !(Map PackageName DepPackage) , smaGlobal :: !(Map PackageName GlobalPackage) - , smaName :: !Text } -- | How a package is intended to be built @@ -136,7 +135,6 @@ data SourceMap = SourceMap , smHash :: !SourceMapHash -- ^ hash of the source map calculated once as an expensive -- operation - , smName :: !Text } -- | A unique hash for the immutable portions of a 'SourceMap'. From 18bf3642e637a5a4b4433fa424ef3501231ebace Mon Sep 17 00:00:00 2001 From: Florjan Bartol Date: Thu, 24 Jan 2019 20:44:20 +0100 Subject: [PATCH 11/11] Changed constraint to HasBuildConfig --- src/Stack/Ghci.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Stack/Ghci.hs b/src/Stack/Ghci.hs index 446a854f1a..89fea3064f 100644 --- a/src/Stack/Ghci.hs +++ b/src/Stack/Ghci.hs @@ -835,7 +835,7 @@ checkForDuplicateModules pkgs = do pretty fp <+> parens (fillSep (punctuate "," (map displayPkgComponent (S.toList comps)))) targetWarnings - :: HasEnvConfig env + :: HasBuildConfig env => [(PackageName, (Path Abs File, Target))] -> [PackageName] -> Maybe (Map PackageName [Path Abs File], [Path Abs File])