Skip to content
This repository was archived by the owner on Aug 23, 2018. It is now read-only.

Add --verbose arg and show how package dependency is being solved #177

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions elm-package.cabal
Original file line number Diff line number Diff line change
@@ -48,6 +48,7 @@ Library
Install.Fetch,
Install.Plan,
Install.Solver,
Logger,
Manager,
Paths_elm_package,
Store,
@@ -63,6 +64,7 @@ Library
directory >= 1.0 && < 2.0,
elm-compiler >= 0.16 && < 0.17,
filepath >= 1 && < 2.0,
hslogger >= 1.2.9 && < 1.3,
HTTP >= 4000.2.5 && < 4000.3,
http-client >= 0.4.15 && < 0.5,
http-client-tls >= 0.2 && < 0.3,
@@ -105,6 +107,7 @@ Executable elm-package
Install.Fetch,
Install.Plan,
Install.Solver,
Logger,
Manager,
Publish,
Store,
@@ -123,6 +126,7 @@ Executable elm-package
directory >= 1.0 && < 2.0,
elm-compiler >= 0.16 && < 0.17,
filepath >= 1 && < 2.0,
hslogger >= 1.2.9 && < 1.3,
HTTP >= 4000.2.5 && < 4000.3,
http-client >= 0.3 && < 0.5,
http-client-tls >= 0.2 && < 0.3,
19 changes: 14 additions & 5 deletions src/CommandLine/Arguments.hs
Original file line number Diff line number Diff line change
@@ -88,18 +88,18 @@ installInfo =
Opt.info args infoModifier
where
args =
installWith <$> optional package <*> optional version <*> yes
installWith <$> optional package <*> optional version <*> yes <*> verbose

installWith maybeName maybeVersion autoYes =
installWith maybeName maybeVersion autoYes verbose =
case (maybeName, maybeVersion) of
(Nothing, Nothing) ->
Install.install autoYes Install.Everything
Install.install verbose autoYes Install.Everything

(Just name, Nothing) ->
Install.install autoYes (Install.Latest name)
Install.install verbose autoYes (Install.Latest name)

(Just name, Just version) ->
Install.install autoYes (Install.Exactly name version)
Install.install verbose autoYes (Install.Exactly name version)

(Nothing, Just version) ->
throwError $
@@ -152,6 +152,15 @@ yes =
]


verbose :: Opt.Parser Bool
verbose =
Opt.switch $
mconcat
[ Opt.long "verbose"
, Opt.help "Print out detailed log so that you can trace back what went wrong at which point."
]


customReader :: String -> (String -> Either String a) -> Opt.ReadM a
customReader argType fromString =
let reader arg =
11 changes: 6 additions & 5 deletions src/Elm/Package/Initialize.hs
Original file line number Diff line number Diff line change
@@ -11,20 +11,21 @@ import qualified Install
import qualified Manager


solution :: (MonadError String m, MonadIO m) => Bool -> m S.Solution
solution autoYes =
runInstall autoYes Install.Everything
solution :: (MonadError String m, MonadIO m) => Bool -> Bool -> m S.Solution
solution verbose autoYes =
runInstall verbose autoYes Install.Everything


runInstall
:: (MonadError String m, MonadIO m)
=> Bool
-> Bool
-> Install.Args
-> m S.Solution
runInstall autoYes args =
runInstall verbose autoYes args =
do either <- liftIO $ do
env <- Manager.defaultEnvironment
Manager.run env (Install.install autoYes args)
Manager.run env (Install.install verbose autoYes args)

case either of
Left err -> throwError err
8 changes: 5 additions & 3 deletions src/Install.hs
Original file line number Diff line number Diff line change
@@ -19,6 +19,7 @@ import qualified Install.Plan as Plan
import qualified Install.Solver as Solver
import qualified Manager
import qualified Store
import qualified Logger


data Args
@@ -27,9 +28,10 @@ data Args
| Exactly Package.Name Package.Version


install :: Bool -> Args -> Manager.Manager ()
install autoYes args =
do exists <- liftIO (doesFileExist Path.description)
install :: Bool -> Bool -> Args -> Manager.Manager ()
install verbose autoYes args =
do liftIO (Logger.configure verbose)
exists <- liftIO (doesFileExist Path.description)

description <-
case exists of
57 changes: 53 additions & 4 deletions src/Install/Solver.hs
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ import qualified Elm.Package as Package
import qualified Elm.Package.Solution as S
import qualified Manager
import qualified Store
import Logger


solve :: [(Package.Name, C.Constraint)] -> Manager.Manager S.Solution
@@ -70,7 +71,9 @@ exploreVersion name version solution remainingPackages =
do (elmVersion, constraints) <- Store.getConstraints name version
if C.isSatisfied elmVersion Compiler.version
then explore constraints
else return Nothing
else
do infoM $ (displayNameAndVersion name version) ++ " requires Elm version " ++ (C.toString elmVersion) ++ " but we are on " ++ (Package.versionToString Compiler.version)
return Nothing

where
explore constraints =
@@ -80,7 +83,12 @@ exploreVersion name version solution remainingPackages =
case all (satisfiedBy solution) overlappingConstraints of
False -> return Nothing
True ->
do maybePackages <- addConstraints remainingPackages newConstraints
do case newConstraints of
[] -> return Nothing
someConstraints ->
do infoM $ (displayNameAndVersion name version) ++ " depends on " ++ (displayConstraints someConstraints)
return Nothing
maybePackages <- addConstraints remainingPackages newConstraints
case maybePackages of
Nothing -> return Nothing
Just extendedPackages ->
@@ -102,5 +110,46 @@ addConstraints packages constraints =
(name, constraint) : rest ->
do versions <- Store.getVersions name
case filter (C.isSatisfied constraint) versions of
[] -> return Nothing
vs -> addConstraints (Map.insert name vs packages) rest
[] ->
do infoM $ (Package.toString name) ++ " (" ++ (displayVersions versions) ++ ") has no package version that satisfies " ++ (C.toString constraint)
return Nothing
vs ->
do infoM $ (Package.toString name) ++ " = " ++ (displayVersions vs) ++ (displayNewerVersions (head vs) versions)
addConstraints (Map.insert name vs packages) rest


-- LOGGING


displayNamedConstraint :: (Package.Name, C.Constraint) -> String
displayNamedConstraint (name, constraint) =
(Package.toString name) ++ ": " ++ (C.toString constraint)


displayNameAndVersion :: Package.Name -> Package.Version -> String
displayNameAndVersion name version =
(Package.toString name) ++ " = " ++ (Package.versionToString version)


displayConstraints :: [(Package.Name, C.Constraint)] -> String
displayConstraints constraints =
List.intercalate ", " (map displayNamedConstraint constraints)


displayVersions :: [Package.Version] -> String
displayVersions versions =
List.intercalate ", " (map Package.versionToString versions)


displayNewerVersions :: Package.Version -> [Package.Version] -> String
displayNewerVersions current versions =
do case newerVersions of
[] ->
""

versions ->
" < " ++ (displayVersions versions)

where
newerVersions =
filter (\v -> v > current) versions
21 changes: 21 additions & 0 deletions src/Logger.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Logger where

import Control.Monad.Trans (MonadIO(..), liftIO)
import System.Log.Logger (updateGlobalLogger,
Priority(..),
rootLoggerName,
setLevel)
import qualified System.Log.Logger as L


configure :: Bool -> IO ()
configure verbose =
do liftIO $ updateGlobalLogger rootLoggerName (setLevel logLevel)
where logLevel = if verbose
then DEBUG
else WARNING


infoM :: MonadIO m => String -> m ()
infoM message =
liftIO $ L.infoM rootLoggerName message