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

Stack init and solver overhaul #1583

Merged
merged 29 commits into from
Jan 8, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3676559
Track the best snapshot by the number of deperrors
harendra-kumar Dec 31, 2015
a6ff6dd
Track dependency errors for GHC wired in packages
harendra-kumar Dec 31, 2015
95a9ffe
Improve the build plan selection error messages
harendra-kumar Dec 31, 2015
6b0c4d0
Allow solver to be used with any resolver
harendra-kumar Dec 31, 2015
643e24b
Reverse dependency between Init and Config modules
harendra-kumar Jan 1, 2016
434e300
Ensure, use specified compiler for new/init/solver
harendra-kumar Jan 1, 2016
b15c626
Solver: Use snapshot instead of compiler resolver
harendra-kumar Jan 1, 2016
59cb11b
Solver: retry with relaxed contraints if failed
harendra-kumar Jan 1, 2016
afbc92c
Fix - ignore certain subdirs for stack init
harendra-kumar Jan 1, 2016
26cfaa4
Solver: perform compiler compatibility check
harendra-kumar Jan 1, 2016
611ddfb
init/solver improve and share error checking code
harendra-kumar Jan 1, 2016
7a1f282
init/solver handle duplicate cabal package case
harendra-kumar Jan 1, 2016
5c10d9a
Tweak solver error messages
harendra-kumar Jan 1, 2016
cdbfa10
Solver: expunge unnecessary dependencies and flags
harendra-kumar Jan 2, 2016
c666434
nitfix solver error messages
harendra-kumar Jan 3, 2016
dd7f1e4
Correctly parse the flags in cabal solver output
harendra-kumar Jan 3, 2016
3c6fa73
Override snapshot with local versions for solver
harendra-kumar Jan 3, 2016
02ae47c
Remove redundant status message
harendra-kumar Jan 4, 2016
f91eac2
Force write an incomplete config when solver fails
harendra-kumar Jan 4, 2016
d90251f
Solver: handle src packages not having version set
harendra-kumar Jan 4, 2016
62faff0
Fix GHC 7.8.4 compilation
harendra-kumar Jan 5, 2016
2ddf64c
Solver: Update resolver when updating config
harendra-kumar Jan 5, 2016
5126e68
Solver: change option name --modify-stack-yaml
harendra-kumar Jan 5, 2016
86334c6
Take flags into account to compute extra deps
harendra-kumar Jan 5, 2016
551ce58
Do not write empty flags with stack init --force
harendra-kumar Jan 6, 2016
f71f80e
Show flags along with dep errors in debug mode
harendra-kumar Jan 6, 2016
2713606
Solver: report missing packages
harendra-kumar Jan 6, 2016
99002f1
init: Cleanup default flag values before writing
harendra-kumar Jan 6, 2016
885a354
Lay down corrective actions at each solver failure
harendra-kumar Jan 7, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
429 changes: 302 additions & 127 deletions src/Stack/BuildPlan.hs

Large diffs are not rendered by default.

89 changes: 86 additions & 3 deletions src/Stack/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,20 @@ module Stack.Config
,resolvePackageEntry
,getImplicitGlobalProjectDir
,getIsGMP4
,getSnapshots
,makeConcreteResolver
) where

import qualified Codec.Archive.Tar as Tar
import qualified Codec.Compression.GZip as GZip
import Control.Applicative
import Control.Arrow ((***))
import Control.Exception (assert)
import Control.Monad
import Control.Monad.Catch (MonadThrow, MonadCatch, catchAll, throwM)
import Control.Monad.IO.Class
import Control.Monad.Logger hiding (Loc)
import Control.Monad.Reader (MonadReader, ask, runReaderT)
import Control.Monad.Reader (MonadReader, ask, asks, runReaderT)
import Control.Monad.Trans.Control (MonadBaseControl)
import qualified Crypto.Hash.SHA256 as SHA256
import Data.Aeson.Extended
Expand All @@ -58,7 +61,7 @@ import qualified Distribution.Text
import Distribution.Version (simplifyVersionRange)
import GHC.Conc (getNumProcessors)
import Network.HTTP.Client.Conduit (HasHttpManager, getHttpManager, Manager, parseUrl)
import Network.HTTP.Download (download)
import Network.HTTP.Download (download, downloadJSON)
import Options.Applicative (Parser, strOption, long, help)
import Path
import Path.Extra (toFilePathNoTrailingSep)
Expand All @@ -70,7 +73,6 @@ import Stack.Config.Docker
import Stack.Config.Nix
import Stack.Constants
import qualified Stack.Image as Image
import Stack.Init
import Stack.PackageIndex
import Stack.Types
import Stack.Types.Internal
Expand All @@ -79,6 +81,87 @@ import System.Environment
import System.IO
import System.Process.Read

-- | If deprecated path exists, use it and print a warning.
-- Otherwise, return the new path.
tryDeprecatedPath
:: (MonadIO m, MonadLogger m)
=> Maybe T.Text -- ^ Description of file for warning (if Nothing, no deprecation warning is displayed)
-> (Path Abs a -> m Bool) -- ^ Test for existence
-> Path Abs a -- ^ New path
-> Path Abs a -- ^ Deprecated path
-> m (Path Abs a, Bool) -- ^ (Path to use, whether it already exists)
tryDeprecatedPath mWarningDesc exists new old = do
newExists <- exists new
if newExists
then return (new, True)
else do
oldExists <- exists old
if oldExists
then do
case mWarningDesc of
Nothing -> return ()
Just desc ->
$logWarn $ T.concat
[ "Warning: Location of ", desc, " at '"
, T.pack (toFilePath old)
, "' is deprecated; rename it to '"
, T.pack (toFilePath new)
, "' instead" ]
return (old, True)
else return (new, False)

-- | Get the location of the implicit global project directory.
-- If the directory already exists at the deprecated location, its location is returned.
-- Otherwise, the new location is returned.
getImplicitGlobalProjectDir
:: (MonadIO m, MonadLogger m)
=> Config -> m (Path Abs Dir)
getImplicitGlobalProjectDir config =
--TEST no warning printed
liftM fst $ tryDeprecatedPath
Nothing
dirExists
(implicitGlobalProjectDir stackRoot)
(implicitGlobalProjectDirDeprecated stackRoot)
where
stackRoot = configStackRoot config

-- | Download the 'Snapshots' value from stackage.org.
getSnapshots :: (MonadThrow m, MonadIO m, MonadReader env m, HasHttpManager env, HasStackRoot env, HasConfig env)
=> m Snapshots
getSnapshots = askLatestSnapshotUrl >>= parseUrl . T.unpack >>= downloadJSON

-- | Turn an 'AbstractResolver' into a 'Resolver'.
makeConcreteResolver :: (MonadIO m, MonadReader env m, HasConfig env, MonadThrow m, HasHttpManager env, MonadLogger m)
=> AbstractResolver
-> m Resolver
makeConcreteResolver (ARResolver r) = return r
makeConcreteResolver ar = do
snapshots <- getSnapshots
r <-
case ar of
ARResolver r -> assert False $ return r
ARGlobal -> do
config <- asks getConfig
implicitGlobalDir <- getImplicitGlobalProjectDir config
let fp = implicitGlobalDir </> stackDotYaml
(ProjectAndConfigMonoid project _, _warnings) <-
liftIO (Yaml.decodeFileEither $ toFilePath fp)
>>= either throwM return
return $ projectResolver project
ARLatestNightly -> return $ ResolverSnapshot $ Nightly $ snapshotsNightly snapshots
ARLatestLTSMajor x ->
case IntMap.lookup x $ snapshotsLts snapshots of
Nothing -> error $ "No LTS release found with major version " ++ show x
Just y -> return $ ResolverSnapshot $ LTS x y
ARLatestLTS
| IntMap.null $ snapshotsLts snapshots -> error "No LTS releases found"
| otherwise ->
let (x, y) = IntMap.findMax $ snapshotsLts snapshots
in return $ ResolverSnapshot $ LTS x y
$logInfo $ "Selected resolver: " <> resolverName r
return r

-- | Get the latest snapshot resolver available.
getLatestResolver
:: (MonadIO m, MonadThrow m, MonadReader env m, HasConfig env, HasHttpManager env, MonadLogger m)
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/ConfigCmd.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import qualified Data.Yaml as Yaml
import Network.HTTP.Client.Conduit (HasHttpManager)
import Path
import Stack.BuildPlan
import Stack.Init
import Stack.Config (makeConcreteResolver)
import Stack.Types

data ConfigCmdSet = ConfigCmdSetResolver AbstractResolver
Expand Down
Loading