@@ -1,9 +1,8 @@
1{-# LANGUAGE OverloadedStrings, Rank2Types #-}
1{-# LANGUAGE OverloadedStrings, Rank2Types #-}
2module Deps.Solver
2module Deps.Solver
4 , Details(..)
5 , Details(..)
@@ -11,6 +10,7 @@ module Deps.Solver
11import Control.Monad (foldM)
10import Control.Monad (foldM)
12import qualified Data.Map as Map
11import qualified Data.Map as Map
13import qualified System.Directory as Dir
12import qualified System.Directory as Dir
13+import System.FilePath ((</>))
15import qualified Deps.Registry as Registry
15import qualified Deps.Registry as Registry
16import qualified Deps.Website as Website
16import qualified Deps.Website as Website
@@ -25,6 +25,48 @@ import qualified Stuff
31+online :: Stuff.PackageCache -> Http.Manager -> Registry.Registry -> Map.Map Pkg.Name C.Constraint -> IO (Either [Problem] (Map.Map Pkg.Name Details))
32+online cache manager registry constraints =
33+ solve cache (Online manager) registry constraints
36+offline :: Stuff.PackageCache -> Registry.Registry -> Map.Map Pkg.Name C.Constraint -> IO (Either [Problem] (Map.Map Pkg.Name Details))
37+offline cache registry constraints =
38+ solve cache Offline registry constraints
46+ Details V.Version (Map.Map Pkg.Name C.Constraint)
49+solve :: Stuff.PackageCache -> Connection -> Registry.Registry -> Map.Map Pkg.Name C.Constraint -> IO (Either [Problem] (Map.Map Pkg.Name Details))
50+solve cache connection registry constraints =
52+ (Solver solver) = exploreGoals (Goals constraints Map.empty)
54+ solver (State cache connection registry Map.empty [])
55+ (\(State _ _ _ cs _) vs _ -> return $ Right $ Map.mapWithKey (toDetails cs) vs)
56+ (\(State _ _ _ _ ps) -> return $ Left ps)
59+toDetails :: Map.Map (Pkg.Name, V.Version) Constraints -> Pkg.Name -> V.Version -> Details
60+toDetails constraints name vsn =
61+ case Map.lookup (name, vsn) constraints of
62+ Just (Constraints _ deps) ->
66+ error "compiler bug in Deps.Solver manifesting in toDetails"
@@ -39,6 +81,10 @@ newtype Solver a =
42data State =
88data State =
44 { _cache :: Stuff.PackageCache
90 { _cache :: Stuff.PackageCache
@@ -71,39 +117,6 @@ data Problem
78− Details V.Version [Pkg.Name]
81−solve :: Stuff.PackageCache -> Connection -> Registry.Registry -> Map.Map Pkg.Name C.Constraint -> IO (Either [Problem] (Map.Map Pkg.Name Details))
82−solve cache connection registry constraints =
84− (Solver solver) = exploreGoals (Goals constraints Map.empty)
86− solver (State cache connection registry Map.empty [])
87− (\(State _ _ _ cs _) vs _ -> return $ Right $ getDetails vs cs)
88− (\(State _ _ _ _ ps) -> return $ Left ps)
91−getDetails :: Map.Map Pkg.Name V.Version -> Map.Map (Pkg.Name, V.Version) Constraints -> Map.Map Pkg.Name Details
92−getDetails solution constraints =
93− Map.mapWithKey (getDetailsHelp constraints) solution
96−getDetailsHelp :: Map.Map (Pkg.Name, V.Version) Constraints -> Pkg.Name -> V.Version -> Details
97−getDetailsHelp constraints name vsn =
98− case Map.lookup (name, vsn) constraints of
99− Just (Constraints _ deps) ->
100− Details vsn (Map.keys deps)
103− error "compiler bug in Deps.Solver manifesting in getDetailsHelp"
107-- EXPLORE GOALS
120-- EXPLORE GOALS
@@ -207,7 +220,7 @@ getConstraints name version =
208getConstraintsHelp :: Stuff.PackageCache -> Connection -> Pkg.Name -> V.Version -> IO (Either Problem Constraints)
221getConstraintsHelp :: Stuff.PackageCache -> Connection -> Pkg.Name -> V.Version -> IO (Either Problem Constraints)
209getConstraintsHelp cache connection name version =
222getConstraintsHelp cache connection name version =
210− do let path = Stuff.metadata cache name version "elm.json"
223+ do let path = Stuff.package cache name version </> "elm.json"
211 outlineExists <- File.exists path
224 outlineExists <- File.exists path
212 if outlineExists
225 if outlineExists
@@ -219,7 +232,7 @@ getConstraintsHelp cache connection name version =
219 return $ Right cs
232 return $ Right cs
221 Offline ->
234 Offline ->
222− do srcExists <- Dir.doesDirectoryExist (Stuff.metadata cache name version "src")
235+ do srcExists <- Dir.doesDirectoryExist (Stuff.package cache name version </> "src")
223 if srcExists
236 if srcExists
224 then return $ Right cs
237 then return $ Right cs
225 else return $ Left (UnavailableOffline name version)
238 else return $ Left (UnavailableOffline name version)