@@ -16,7 +16,6 @@ module Stack.SourceMap
16
16
, getPLIVersion
17
17
, loadGlobalHints
18
18
, actualFromGhc
19
- , actualFromHints
20
19
, globalCondCheck
21
20
, pruneGlobals
22
21
, globalsFromHints
@@ -39,7 +38,7 @@ import Stack.Constants ( stackProgName' )
39
38
import Stack.PackageDump ( conduitDumpPackage , ghcPkgDump )
40
39
import Stack.Prelude
41
40
import Stack.Types.Compiler
42
- ( ActualCompiler , actualToWanted , wantedToActual )
41
+ ( ActualCompiler , wantedToActual )
43
42
import Stack.Types.CompilerPaths
44
43
( CompilerPaths (.. ), GhcPkgExe , HasCompiler (.. ) )
45
44
import Stack.Types.Config ( HasConfig )
@@ -112,6 +111,8 @@ additionalDepPackage buildHaddocks location = do
112
111
}
113
112
}
114
113
114
+ -- | Given a t'PackageName' and its t'SnapshotPackage', yields the corresponding
115
+ -- t'DepPackage'.
115
116
snapToDepPackage ::
116
117
forall env . (HasPantryConfig env , HasLogFunc env , HasProcessContext env )
117
118
=> Bool
@@ -136,16 +137,22 @@ snapToDepPackage buildHaddocks name sp = do
136
137
}
137
138
}
138
139
140
+ -- | For the given t'CommonPackage', load its generic package description and
141
+ -- yield its version.
139
142
loadVersion :: MonadIO m => CommonPackage -> m Version
140
143
loadVersion common = do
141
144
gpd <- liftIO common. gpd
142
- pure (pkgVersion $ PD. package $ PD. packageDescription gpd)
145
+ pure gpd . packageDescription . package. pkgVersion
143
146
147
+ -- | For the given t'PackageLocationImmutable', yield the version of the
148
+ -- referenced package.
144
149
getPLIVersion :: PackageLocationImmutable -> Version
145
150
getPLIVersion (PLIHackage (PackageIdentifier _ v) _ _) = v
146
151
getPLIVersion (PLIArchive _ pm) = pkgVersion $ pmIdent pm
147
152
getPLIVersion (PLIRepo _ pm) = pkgVersion $ pmIdent pm
148
153
154
+ -- | For the given @ghc-pkg@ executable, yield the contents of the global
155
+ -- package database.
149
156
globalsFromDump ::
150
157
(HasProcessContext env , HasTerm env )
151
158
=> GhcPkgExe
@@ -157,21 +164,24 @@ globalsFromDump pkgexe = do
157
164
Map. fromList $ map (pkgName . (. packageIdent) &&& id ) $ Map. elems ds
158
165
toGlobals <$> ghcPkgDump pkgexe [] pkgConduit
159
166
167
+ -- | For the given wanted compiler, yield the global hints (if available).
160
168
globalsFromHints ::
161
169
HasConfig env
162
170
=> WantedCompiler
163
171
-> RIO env (Map PackageName Version )
164
- globalsFromHints compiler = do
165
- mglobalHints <- loadGlobalHints compiler
166
- case mglobalHints of
167
- Just hints -> pure hints
168
- Nothing -> do
172
+ globalsFromHints compiler = loadGlobalHints compiler >>= maybe
173
+ ( do
169
174
prettyWarnL
170
175
[ flow " Unable to load global hints for"
171
176
, fromString $ T. unpack $ textDisplay compiler
172
177
]
173
178
pure mempty
179
+ )
180
+ pure
174
181
182
+ -- | When the environment 'HasCompiler', for the
183
+ -- given t'Stack.Types.SourceMap.SMWanted' and 'ActualCompiler', yield
184
+ -- a t'SMActual' parameterised by t'DumpedGlobalPackage'.
175
185
actualFromGhc ::
176
186
(HasConfig env , HasCompiler env )
177
187
=> SMWanted
@@ -187,21 +197,6 @@ actualFromGhc smw compiler = do
187
197
, globals
188
198
}
189
199
190
- actualFromHints ::
191
- (HasConfig env )
192
- => SMWanted
193
- -> ActualCompiler
194
- -> RIO env (SMActual GlobalPackageVersion )
195
- actualFromHints smw compiler = do
196
- globals <- globalsFromHints (actualToWanted compiler)
197
- pure
198
- SMActual
199
- { compiler
200
- , project = smw. project
201
- , deps = smw. deps
202
- , globals = Map. map GlobalPackageVersion globals
203
- }
204
-
205
200
-- | Simple cond check for boot packages - checks only OS and Arch
206
201
globalCondCheck ::
207
202
(HasConfig env )
@@ -214,9 +209,12 @@ globalCondCheck = do
214
209
condCheck c = Left c
215
210
pure condCheck
216
211
212
+ -- | Prune the given packages from GHC's global package database.
217
213
pruneGlobals ::
218
214
Map PackageName DumpedGlobalPackage
215
+ -- ^ Packages in GHC's global package database.
219
216
-> Set PackageName
217
+ -- ^ Package names to prune.
220
218
-> Map PackageName GlobalPackage
221
219
pruneGlobals globals deps =
222
220
let (prunedGlobals, keptGlobals) =
@@ -225,9 +223,12 @@ pruneGlobals globals deps =
225
223
in Map. map (GlobalPackage . pkgVersion . (. packageIdent)) keptGlobals <>
226
224
Map. map ReplacedGlobalPackage prunedGlobals
227
225
226
+ -- | Get the output of @ghc --info@ for the compiler in the environment.
228
227
getCompilerInfo :: (HasConfig env , HasCompiler env ) => RIO env Builder
229
228
getCompilerInfo = view $ compilerPathsL . to (byteString . (. ghcInfo))
230
229
230
+ -- | For the given 'PackageLocationImmutable', yield its 256-bit cryptographic
231
+ -- hash.
231
232
immutableLocSha :: PackageLocationImmutable -> Builder
232
233
immutableLocSha = byteString . treeKeyToBs . locationTreeKey
233
234
where
@@ -236,9 +237,13 @@ immutableLocSha = byteString . treeKeyToBs . locationTreeKey
236
237
locationTreeKey (PLIRepo _ pm) = pmTreeKey pm
237
238
treeKeyToBs (TreeKey (BlobKey sha _)) = SHA256. toHexBytes sha
238
239
240
+ -- | Type synonym for functions that yield a t'SMActual' parameterised by
241
+ -- t'GlobalPackageVersion' for a given list of project package directories.
239
242
type SnapshotCandidate env
240
243
= [ResolvedPath Dir ] -> RIO env (SMActual GlobalPackageVersion )
241
244
245
+ -- | For the given raw snapshot location, yield a function to yield a
246
+ -- t'SMActual' from a list of project package directories.
242
247
loadProjectSnapshotCandidate ::
243
248
(HasConfig env )
244
249
=> RawSnapshotLocation
0 commit comments