Skip to content

Commit

Permalink
Detect resolver change in stack solver
Browse files Browse the repository at this point in the history
  • Loading branch information
sjakobi committed Jun 22, 2016
1 parent 5bd2b36 commit 284dc58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import Data.Aeson.Extended ( WithJSONWarnings(..), object, (.=
import qualified Data.ByteString as S
import Data.Char (isSpace)
import Data.Either
import Data.Foldable (forM_)
import Data.Function (on)
import qualified Data.HashMap.Strict as HashMap
import Data.List ( (\\), isSuffixOf, intercalate
Expand Down Expand Up @@ -679,6 +680,8 @@ solveExtraDeps modStackYaml = do
Nothing -> throwM (SolverGiveUp giveUpMsg)
Just x -> return x

moldResolver <- asks (fmap (projectResolver . fst) . configMaybeProject . getConfig)

let
flags = removeSrcPkgDefaultFlags gpds (fmap snd (Map.union srcs edeps))
versions = fmap fst edeps
Expand All @@ -695,14 +698,14 @@ solveExtraDeps modStackYaml = do

changed = any (not . Map.null) [newVersions, goneVersions]
|| any (not . Map.null) [newFlags, goneFlags]
|| any (/= resolver') moldResolver

if changed then do
$logInfo ""
$logInfo $ "The following changes will be made to "
<> T.pack relStackYaml <> ":"

-- TODO print whether resolver changed from previous
$logInfo $ "* Resolver is " <> resolverName resolver
printResolver moldResolver resolver'

printFlags newFlags "* Flags to be added"
printDeps newVersions "* Dependencies to be added"
Expand All @@ -723,6 +726,16 @@ solveExtraDeps modStackYaml = do
where
indent t = T.unlines $ fmap (" " <>) (T.lines t)

printResolver moldRes res = do
forM_ moldRes $ \oldRes ->
when (res /= oldRes) $ do
$logInfo $ T.concat
[ "* Resolver changes from "
, resolverName oldRes
, " to "
, resolverName res
]

printFlags fl msg = do
when ((not . Map.null) fl) $ do
$logInfo $ T.pack msg
Expand Down
1 change: 1 addition & 0 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,7 @@ data ResolverThat's (l :: IsLoaded) where
-- files are stored for the resolver.
ResolverCustomLoaded :: !Text -> !Text -> !SnapshotHash -> ResolverThat's 'Loaded

deriving instance Eq (ResolverThat's k)
deriving instance Show (ResolverThat's k)

instance ToJSON (ResolverThat's k) where
Expand Down

0 comments on commit 284dc58

Please sign in to comment.