@@ -28,6 +28,7 @@ import Gren.Package qualified as Pkg
28
28
import Gren.Platform qualified as Platform
29
29
import Gren.Version qualified as V
30
30
import Json.Decode qualified as D
31
+ import Reporting qualified
31
32
import Reporting.Exit qualified as Exit
32
33
import System.FilePath ((</>) )
33
34
@@ -67,13 +68,14 @@ data Details
67
68
= Details V. Version (Map. Map Pkg. Name C. Constraint )
68
69
69
70
verify ::
71
+ Reporting. DKey ->
70
72
Dirs. PackageCache ->
71
73
Platform. Platform ->
72
74
Map. Map Pkg. Name C. Constraint ->
73
75
IO (Result (Map. Map Pkg. Name Details ))
74
- verify cache rootPlatform constraints =
76
+ verify key cache rootPlatform constraints =
75
77
Dirs. withRegistryLock cache $
76
- case try rootPlatform constraints of
78
+ case try key rootPlatform constraints of
77
79
Solver solver ->
78
80
solver
79
81
(State cache Map. empty)
@@ -96,17 +98,19 @@ data AppSolution = AppSolution
96
98
}
97
99
98
100
addToApp ::
101
+ Reporting. DKey ->
99
102
Dirs. PackageCache ->
100
103
Pkg. Name ->
101
104
V. Version ->
102
105
Outline. AppOutline ->
103
106
IO (Result AppSolution )
104
- addToApp cache pkg compatibleVsn outline@ (Outline. AppOutline _ rootPlatform _ direct indirect) =
107
+ addToApp key cache pkg compatibleVsn outline@ (Outline. AppOutline _ rootPlatform _ direct indirect) =
105
108
Dirs. withRegistryLock cache $
106
109
let allDeps = Map. union direct indirect
107
110
108
111
attempt toConstraint deps =
109
112
try
113
+ key
110
114
rootPlatform
111
115
(Map. insert pkg (C. untilNextMajor compatibleVsn) (Map. map toConstraint deps))
112
116
in case oneOf
@@ -145,9 +149,9 @@ getTransitive constraints solution unvisited visited =
145
149
146
150
-- TRY
147
151
148
- try :: Platform. Platform -> Map. Map Pkg. Name C. Constraint -> Solver (Map. Map Pkg. Name V. Version )
149
- try rootPlatform constraints =
150
- exploreGoals (Goals rootPlatform constraints Map. empty)
152
+ try :: Reporting. DKey -> Platform. Platform -> Map. Map Pkg. Name C. Constraint -> Solver (Map. Map Pkg. Name V. Version )
153
+ try key rootPlatform constraints =
154
+ exploreGoals key (Goals rootPlatform constraints Map. empty)
151
155
152
156
-- EXPLORE GOALS
153
157
@@ -157,22 +161,22 @@ data Goals = Goals
157
161
_solved :: Map. Map Pkg. Name V. Version
158
162
}
159
163
160
- exploreGoals :: Goals -> Solver (Map. Map Pkg. Name V. Version )
161
- exploreGoals (Goals rootPlatform pending solved) =
164
+ exploreGoals :: Reporting. DKey -> Goals -> Solver (Map. Map Pkg. Name V. Version )
165
+ exploreGoals key (Goals rootPlatform pending solved) =
162
166
case Map. minViewWithKey pending of
163
167
Nothing ->
164
168
return solved
165
169
Just ((name, constraint), otherPending) ->
166
170
do
167
171
let goals1 = Goals rootPlatform otherPending solved
168
172
let lowestVersion = C. lowerBound constraint
169
- goals2 <- addVersion goals1 name lowestVersion
170
- exploreGoals goals2
173
+ goals2 <- addVersion key goals1 name lowestVersion
174
+ exploreGoals key goals2
171
175
172
- addVersion :: Goals -> Pkg. Name -> V. Version -> Solver Goals
173
- addVersion (Goals rootPlatform pending solved) name version =
176
+ addVersion :: Reporting. DKey -> Goals -> Pkg. Name -> V. Version -> Solver Goals
177
+ addVersion reportKey (Goals rootPlatform pending solved) name version =
174
178
do
175
- (Constraints gren platform deps) <- getConstraints name version
179
+ (Constraints gren platform deps) <- getConstraints reportKey name version
176
180
if C. goodGren gren
177
181
then
178
182
if Platform. compatible rootPlatform platform
@@ -209,8 +213,8 @@ addConstraint sourcePkg solved unsolved (name, newConstraint) =
209
213
210
214
-- GET CONSTRAINTS
211
215
212
- getConstraints :: Pkg. Name -> V. Version -> Solver Constraints
213
- getConstraints pkg vsn =
216
+ getConstraints :: Reporting. DKey -> Pkg. Name -> V. Version -> Solver Constraints
217
+ getConstraints reportKey pkg vsn =
214
218
Solver $ \ state@ (State cache cDict) ok back err ->
215
219
do
216
220
let key = (pkg, vsn)
@@ -219,24 +223,43 @@ getConstraints pkg vsn =
219
223
ok state cs back
220
224
Nothing ->
221
225
do
222
- let toNewState cs = State cache (Map. insert key cs cDict)
223
- let home = Dirs. package cache pkg vsn
224
- packageInstalResult <- Package. installPackageVersion cache pkg vsn
225
- case packageInstalResult of
226
- Left gitErr ->
227
- err $ Exit. SolverBadGitOperationVersionedPkg pkg vsn gitErr
228
- Right () -> do
229
- let path = home </> " gren.json"
230
- outlineExists <- File. exists path
231
- if outlineExists
232
- then do
233
- bytes <- File. readUtf8 path
234
- case D. fromByteString constraintsDecoder bytes of
226
+ isPackageInCache <- Package. isPackageInCache cache pkg vsn
227
+ if isPackageInCache
228
+ then do
229
+ Reporting. report reportKey Reporting. DCached
230
+ constraintsDecodeResult <- getConstraintsHelper cache pkg vsn
231
+ case constraintsDecodeResult of
232
+ Left exitMsg ->
233
+ err exitMsg
234
+ Right cs ->
235
+ ok (State cache (Map. insert key cs cDict)) cs back
236
+ else do
237
+ Reporting. report reportKey Reporting. DRequested
238
+ packageInstalResult <- Package. installPackageVersion cache pkg vsn
239
+ case packageInstalResult of
240
+ Left gitErr ->
241
+ do
242
+ Reporting. report reportKey $ Reporting. DFailed pkg vsn
243
+ err $ Exit. SolverBadGitOperationVersionedPkg pkg vsn gitErr
244
+ Right () -> do
245
+ Reporting. report reportKey $ Reporting. DReceived pkg vsn
246
+ constraintsDecodeResult <- getConstraintsHelper cache pkg vsn
247
+ case constraintsDecodeResult of
248
+ Left exitMsg ->
249
+ err exitMsg
235
250
Right cs ->
236
- ok (toNewState cs) cs back
237
- Left _ ->
238
- err (Exit. SolverBadCacheData pkg vsn)
239
- else err (Exit. SolverBadCacheData pkg vsn)
251
+ ok (State cache (Map. insert key cs cDict)) cs back
252
+
253
+ getConstraintsHelper :: Dirs. PackageCache -> Pkg. Name -> V. Version -> IO (Either Exit. Solver Constraints )
254
+ getConstraintsHelper cache pkg vsn =
255
+ do
256
+ let path = Dirs. package cache pkg vsn </> " gren.json"
257
+ bytes <- File. readUtf8 path
258
+ case D. fromByteString constraintsDecoder bytes of
259
+ Right cs ->
260
+ return $ Right cs
261
+ Left _ ->
262
+ return $ Left $ Exit. SolverBadCacheData pkg vsn
240
263
241
264
constraintsDecoder :: D. Decoder () Constraints
242
265
constraintsDecoder =
0 commit comments