Skip to content

Commit

Permalink
Don't have "stack solver" suggest --omit-packages #2031
Browse files Browse the repository at this point in the history
  • Loading branch information
mgsloan committed May 15, 2016
1 parent fd473da commit cbbfb95
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 30 deletions.
32 changes: 18 additions & 14 deletions src/Stack/Init.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,12 @@ initProject
, MonadReader env m, HasConfig env , HasGHCVariant env
, HasHttpManager env , HasLogLevel env , HasReExec env
, HasTerminal env)
=> Path Abs Dir
=> WhichSolverCmd
-> Path Abs Dir
-> InitOpts
-> Maybe AbstractResolver
-> m ()
initProject currDir initOpts mresolver = do
initProject whichCmd currDir initOpts mresolver = do
let dest = currDir </> stackDotYaml

reldest <- toFilePath `liftM` makeRelativeToCurrentDir dest
Expand All @@ -79,7 +80,7 @@ initProject currDir initOpts mresolver = do
cabalfps <- liftM concat $ mapM find dirs'
(bundle, dupPkgs) <- cabalPackagesCheck cabalfps noPkgMsg Nothing

(r, flags, extraDeps, rbundle) <- getDefaultResolver dest initOpts
(r, flags, extraDeps, rbundle) <- getDefaultResolver whichCmd dest initOpts
mresolver bundle

let ignored = Map.difference bundle rbundle
Expand Down Expand Up @@ -331,7 +332,8 @@ getDefaultResolver
, MonadReader env m, HasConfig env , HasGHCVariant env
, HasHttpManager env , HasLogLevel env , HasReExec env
, HasTerminal env)
=> Path Abs File -- ^ stack.yaml
=> WhichSolverCmd
-> Path Abs File -- ^ stack.yaml
-> InitOpts
-> Maybe AbstractResolver
-> Map PackageName (Path Abs File, C.GenericPackageDescription)
Expand All @@ -344,9 +346,9 @@ getDefaultResolver
-- , Flags for src packages and extra deps
-- , Extra dependencies
-- , Src packages actually considered)
getDefaultResolver stackYaml initOpts mresolver bundle =
getDefaultResolver whichCmd stackYaml initOpts mresolver bundle =
maybe selectSnapResolver makeConcreteResolver mresolver
>>= getWorkingResolverPlan stackYaml initOpts bundle
>>= getWorkingResolverPlan whichCmd stackYaml initOpts bundle
where
-- TODO support selecting best across regular and custom snapshots
selectSnapResolver = do
Expand All @@ -355,15 +357,16 @@ getDefaultResolver stackYaml initOpts mresolver bundle =
(s, r) <- selectBestSnapshot gpds snaps
case r of
BuildPlanCheckFail {} | not (omitPackages initOpts)
-> throwM (NoMatchingSnapshot snaps)
-> throwM (NoMatchingSnapshot whichCmd snaps)
_ -> return $ ResolverSnapshot s

getWorkingResolverPlan
:: ( MonadBaseControl IO m, MonadIO m, MonadLogger m, MonadMask m
, MonadReader env m, HasConfig env , HasGHCVariant env
, HasHttpManager env , HasLogLevel env , HasReExec env
, HasTerminal env)
=> Path Abs File -- ^ stack.yaml
=> WhichSolverCmd
-> Path Abs File -- ^ stack.yaml
-> InitOpts
-> Map PackageName (Path Abs File, C.GenericPackageDescription)
-- ^ Src package name: cabal dir, cabal package description
Expand All @@ -376,12 +379,12 @@ getWorkingResolverPlan
-- , Flags for src packages and extra deps
-- , Extra dependencies
-- , Src packages actually considered)
getWorkingResolverPlan stackYaml initOpts bundle resolver = do
getWorkingResolverPlan whichCmd stackYaml initOpts bundle resolver = do
$logInfo $ "Selected resolver: " <> resolverName resolver
go bundle
where
go info = do
eres <- checkBundleResolver stackYaml initOpts info resolver
eres <- checkBundleResolver whichCmd stackYaml initOpts info resolver
-- if some packages failed try again using the rest
case eres of
Right (f, edeps)-> return (resolver, f, edeps, info)
Expand Down Expand Up @@ -413,14 +416,15 @@ checkBundleResolver
, MonadReader env m, HasConfig env , HasGHCVariant env
, HasHttpManager env , HasLogLevel env , HasReExec env
, HasTerminal env)
=> Path Abs File -- ^ stack.yaml
=> WhichSolverCmd
-> Path Abs File -- ^ stack.yaml
-> InitOpts
-> Map PackageName (Path Abs File, C.GenericPackageDescription)
-- ^ Src package name: cabal dir, cabal package description
-> Resolver
-> m (Either [PackageName] ( Map PackageName (Map FlagName Bool)
, Map PackageName Version))
checkBundleResolver stackYaml initOpts bundle resolver = do
checkBundleResolver whichCmd stackYaml initOpts bundle resolver = do
result <- checkResolverSpec gpds Nothing resolver
case result of
BuildPlanCheckOk f -> return $ Right (f, Map.empty)
Expand All @@ -432,14 +436,14 @@ checkBundleResolver stackYaml initOpts bundle resolver = do
warnPartial result
$logWarn "*** Omitting packages with unsatisfied dependencies"
return $ Left $ failedUserPkgs e
| otherwise -> throwM $ ResolverPartial resolver (show result)
| otherwise -> throwM $ ResolverPartial whichCmd resolver (show result)
BuildPlanCheckFail _ e _
| omitPackages initOpts -> do
$logWarn $ "*** Resolver compiler mismatch: "
<> resolverName resolver
$logWarn $ indent $ T.pack $ show result
return $ Left $ failedUserPkgs e
| otherwise -> throwM $ ResolverMismatch resolver (show result)
| otherwise -> throwM $ ResolverMismatch whichCmd resolver (show result)
where
indent t = T.unlines $ fmap (" " <>) (T.lines t)
warnPartial res = do
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Solver.hs
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ solveExtraDeps modStackYaml = do
-- packages
return $ either (const Nothing) Just eres
BuildPlanCheckFail {} ->
throwM $ ResolverMismatch resolver (show resolverResult)
throwM $ ResolverMismatch IsSolverCmd resolver (show resolverResult)

(srcs, edeps) <- case resultSpecs of
Nothing -> throwM (SolverGiveUp giveUpMsg)
Expand Down
38 changes: 25 additions & 13 deletions src/Stack/Types/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ module Stack.Types.Config
,ApplyGhcOptions(..)
-- ** ConfigException
,ConfigException(..)
-- ** WhichSolverCmd
,WhichSolverCmd(..)
-- ** ConfigMonoid
,ConfigMonoid(..)
-- ** EnvSettings
Expand Down Expand Up @@ -1076,9 +1078,9 @@ data ConfigException
| UnexpectedArchiveContents [Path Abs Dir] [Path Abs File]
| UnableToExtractArchive Text (Path Abs File)
| BadStackVersionException VersionRange
| NoMatchingSnapshot (NonEmpty SnapName)
| forall l. ResolverMismatch (ResolverThat's l) String
| ResolverPartial Resolver String
| NoMatchingSnapshot WhichSolverCmd (NonEmpty SnapName)
| forall l. ResolverMismatch WhichSolverCmd (ResolverThat's l) String
| ResolverPartial WhichSolverCmd Resolver String
| NoSuchDirectory FilePath
| ParseGHCVariantException String
| BadStackRoot (Path Abs Dir)
Expand Down Expand Up @@ -1133,31 +1135,27 @@ instance Show ConfigException where
,"version range specified in stack.yaml ("
, T.unpack (versionRangeText requiredRange)
, ")." ]
show (NoMatchingSnapshot names) = concat
show (NoMatchingSnapshot whichCmd names) = concat $
[ "None of the following snapshots provides a compiler matching "
, "your package(s):\n"
, unlines $ map (\name -> " - " <> T.unpack (renderSnapName name))
(NonEmpty.toList names)
, "\nYou can try the following options:\n"
, " - Use '--omit-packages to exclude mismatching package(s).\n"
, " - Use '--resolver' to specify a matching snapshot/resolver\n"
, showOptions whichCmd
]
show (ResolverMismatch resolver errDesc) = concat
show (ResolverMismatch whichCmd resolver errDesc) = concat
[ "Resolver '"
, T.unpack (resolverName resolver)
, "' does not have a matching compiler to build some or all of your "
, "package(s).\n"
, errDesc
, "\nHowever, you can try '--omit-packages to exclude mismatching "
, "package(s)."
, showOptions whichCmd
]
show (ResolverPartial resolver errDesc) = concat
show (ResolverPartial whichCmd resolver errDesc) = concat
[ "Resolver '"
, T.unpack (resolverName resolver)
, "' does not have all the packages to match your requirements.\n"
, unlines $ fmap (" " <>) (lines errDesc)
, "\nHowever, you can try '--solver' to use external packages."
, "\nUse '--omit-packages' if you want to create a config anyway."
, showOptions whichCmd
]
show (NoSuchDirectory dir) = concat
["No directory could be located matching the supplied path: "
Expand Down Expand Up @@ -1189,6 +1187,20 @@ instance Show ConfigException where
]
instance Exception ConfigException

showOptions :: WhichSolverCmd -> String
showOptions whichCmd = unlines $ ["\nThis may be resolved by:"] ++ options
where
options =
case whichCmd of
IsSolverCmd -> [useResolver]
IsInitCmd -> both

This comment has been minimized.

Copy link
@harendra-kumar

harendra-kumar May 23, 2016

Collaborator

Just found it out that stack init is no longer suggesting --solver.

Also, the messaging was context sensitive earlier to suggest only the right options e.g. --resolver was suggested in NoMatchingSnapshot case only and --solver was being suggested in the ResolverPartial case.

This comment has been minimized.

Copy link
@mgsloan

mgsloan May 23, 2016

Author Contributor

Ah, yeah, oversight on my part probably confused --solver and --resolver and thought this was handling all the original messages.

IsNewCmd -> both
both = [omitPackages, useResolver]
omitPackages = " - Using '--omit-packages to exclude mismatching package(s)."
useResolver = " - Using '--resolver' to specify a matching snapshot/resolver"

data WhichSolverCmd = IsInitCmd | IsSolverCmd | IsNewCmd

-- | Helper function to ask the environment and apply getConfig
askConfig :: (MonadReader env m, HasConfig env) => m Config
askConfig = liftM getConfig ask
Expand Down
4 changes: 2 additions & 2 deletions src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1227,14 +1227,14 @@ withMiniConfigAndLock go@GlobalOpts{..} inner = do
initCmd :: InitOpts -> GlobalOpts -> IO ()
initCmd initOpts go = do
pwd <- getCurrentDir
withMiniConfigAndLock go (initProject pwd initOpts (globalResolver go))
withMiniConfigAndLock go (initProject IsInitCmd pwd initOpts (globalResolver go))

-- | Create a project directory structure and initialize the stack config.
newCmd :: (NewOpts,InitOpts) -> GlobalOpts -> IO ()
newCmd (newOpts,initOpts) go@GlobalOpts{..} = do
withMiniConfigAndLock go $ do
dir <- new newOpts (forceOverwrite initOpts)
initProject dir initOpts globalResolver
initProject IsNewCmd dir initOpts globalResolver

-- | List the available templates.
templatesCmd :: () -> GlobalOpts -> IO ()
Expand Down

0 comments on commit cbbfb95

Please sign in to comment.