forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponentFile.hs
More file actions
597 lines (568 loc) · 22.1 KB
/
ComponentFile.hs
File metadata and controls
597 lines (568 loc) · 22.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedRecordDot #-}
{-# LANGUAGE OverloadedStrings #-}
-- | A module which exports all component-level file-gathering logic. It also
-- includes utility functions for handling paths and directories.
module Stack.ComponentFile
( resolveOrWarn
, componentOutputDir
, componentBuildDir
, packageAutogenDir
, buildDir
, componentAutogenDir
, ComponentFile (..)
, stackLibraryFiles
, stackExecutableFiles
, stackTestSuiteFiles
, stackBenchmarkFiles
) where
import Control.Exception ( throw )
import Data.Foldable ( foldrM )
import Data.List ( find, isPrefixOf )
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import qualified Data.Text as T
import Distribution.ModuleName ( ModuleName )
import qualified Distribution.ModuleName as Cabal
import Distribution.PackageDescription
( BenchmarkInterface (..), TestSuiteInterface (..) )
import Distribution.Text ( display )
import Distribution.Utils.Path
( PackageDir, SourceDir, SymbolicPath, getSymbolicPath )
import Distribution.Version ( mkVersion )
import GHC.Records ( HasField )
import qualified HiFileParser as Iface
import Path
( (</>), filename, isProperPrefixOf, parent, parseRelDir
, stripProperPrefix
)
import Path.Extra
( forgivingResolveDir, forgivingResolveFile
, parseCollapsedAbsFile, rejectMissingDir, rejectMissingFile
)
import Path.IO
( doesDirExist, doesFileExist, getCurrentDir, listDir )
import Stack.Constants
( haskellDefaultPreprocessorExts, haskellFileExts
, relDirAutogen, relDirBuild, relDirGlobalAutogen
)
import Stack.Prelude hiding ( Display (..) )
import Stack.Types.Component
( StackBenchmark (..), StackBuildInfo (..)
, StackExecutable (..), StackLibrary (..)
, StackTestSuite (..), StackUnqualCompName (..)
)
import Stack.Types.Config
( Config (..), HasConfig (..), prettyStackDevL )
import Stack.Types.NamedComponent ( NamedComponent (..) )
import Stack.Types.Package ( PackageException (..), dotCabalModule )
import Stack.Types.PackageFile
( GetPackageFileContext (..), DotCabalDescriptor (..)
, DotCabalPath (..), PackageWarning (..)
)
import qualified System.Directory as D ( doesFileExist )
import qualified System.FilePath as FilePath
data ComponentFile = ComponentFile
{ moduleFileMap :: !(Map ModuleName (Path Abs File))
, otherFile :: ![DotCabalPath]
, packageWarning :: ![PackageWarning]
}
-- | Get all files referenced by the benchmark.
stackBenchmarkFiles ::
StackBenchmark
-> RIO GetPackageFileContext (NamedComponent, ComponentFile)
stackBenchmarkFiles bench =
resolveComponentFiles (CBench bench.name.unqualCompToText) build names
where
names = bnames <> exposed
exposed =
case bench.interface of
BenchmarkExeV10 _ fp -> [DotCabalMain fp]
BenchmarkUnsupported _ -> []
bnames = map DotCabalModule build.otherModules
build = bench.buildInfo
-- | Get all files referenced by the test.
stackTestSuiteFiles ::
StackTestSuite
-> RIO GetPackageFileContext (NamedComponent, ComponentFile)
stackTestSuiteFiles test =
resolveComponentFiles (CTest test.name.unqualCompToText) build names
where
names = bnames <> exposed
exposed =
case test.interface of
TestSuiteExeV10 _ fp -> [DotCabalMain fp]
TestSuiteLibV09 _ mn -> [DotCabalModule mn]
TestSuiteUnsupported _ -> []
bnames = map DotCabalModule build.otherModules
build = test.buildInfo
-- | Get all files referenced by the executable.
stackExecutableFiles ::
StackExecutable
-> RIO GetPackageFileContext (NamedComponent, ComponentFile)
stackExecutableFiles exe =
resolveComponentFiles (CExe exe.name.unqualCompToText) build names
where
build = exe.buildInfo
names =
map DotCabalModule build.otherModules ++ [DotCabalMain exe.modulePath]
-- | Get all files referenced by the library. Handle all libraries (CLib and
-- SubLib), based on empty name or not.
stackLibraryFiles ::
StackLibrary
-> RIO GetPackageFileContext (NamedComponent, ComponentFile)
stackLibraryFiles lib =
resolveComponentFiles componentName build names
where
componentRawName = lib.name.unqualCompToText
componentName
| componentRawName == mempty = CLib
| otherwise = CSubLib componentRawName
build = lib.buildInfo
names = bnames ++ exposed
exposed = map DotCabalModule lib.exposedModules
bnames = map DotCabalModule build.otherModules
-- | Get all files referenced by the component.
resolveComponentFiles ::
( CAndJsSources rec
, HasField "hsSourceDirs" rec [SymbolicPath PackageDir SourceDir]
)
=> NamedComponent
-> rec
-> [DotCabalDescriptor]
-> RIO GetPackageFileContext (NamedComponent, ComponentFile)
resolveComponentFiles component build names = do
dirs <- mapMaybeM (resolveDirOrWarn . getSymbolicPath) build.hsSourceDirs
dir <- asks (parent . (.file))
agdirs <- autogenDirs
(modules,files,warnings) <-
resolveFilesAndDeps
component
((if null dirs then [dir] else dirs) ++ agdirs)
names
cfiles <- buildOtherSources build
pure (component, ComponentFile modules (files <> cfiles) warnings)
where
autogenDirs = do
cabalVer <- asks (.cabalVer)
distDir <- asks (.distDir)
let compDir = componentAutogenDir cabalVer component distDir
pkgDir = maybeToList $ packageAutogenDir cabalVer distDir
filterM doesDirExist $ compDir : pkgDir
-- | Try to resolve the list of base names in the given directory by looking for
-- unique instances of base names applied with the given extensions, plus find
-- any of their module and TemplateHaskell dependencies.
resolveFilesAndDeps ::
NamedComponent -- ^ Package component name
-> [Path Abs Dir] -- ^ Directories to look in.
-> [DotCabalDescriptor] -- ^ Base names.
-> RIO
GetPackageFileContext
(Map ModuleName (Path Abs File), [DotCabalPath], [PackageWarning])
resolveFilesAndDeps component dirs names0 = do
(dotCabalPaths, foundModules, missingModules, _) <- loop names0 S.empty M.empty
warnings <-
liftM2 (++) (warnUnlisted foundModules) (warnMissing missingModules)
pure (foundModules, dotCabalPaths, warnings)
where
loop ::
[DotCabalDescriptor]
-> Set ModuleName
-> Map FilePath (Path Abs File)
-- ^ Known file usages, where the file path has already been resolved.
-> RIO
GetPackageFileContext
( [DotCabalPath]
, Map ModuleName (Path Abs File)
, [ModuleName]
, Map k a
)
loop [] _ _ = pure ([], M.empty, [], M.empty)
loop names doneModules0 knownUsages = do
resolved <- resolveFiles dirs names
let foundFiles = mapMaybe snd resolved
foundModules = mapMaybe toResolvedModule resolved
missingModules = mapMaybe toMissingModule resolved
getDependenciesFold c (ps, ku) = do
p <- getDependencies ku component dirs c
pure (p : ps, ku <> snd p)
(pairs, foundUsages) <- foldrM getDependenciesFold ([], knownUsages) foundFiles
let doneModules = S.union
doneModules0
(S.fromList (mapMaybe dotCabalModule names))
moduleDeps = S.unions (map fst pairs)
thDepFiles = concatMap (M.elems . snd) pairs
modulesRemaining = S.difference moduleDeps doneModules
-- Ignore missing modules discovered as dependencies - they may
-- have been deleted.
(resolvedFiles, resolvedModules, _, foundUsages') <-
loop (map DotCabalModule (S.toList modulesRemaining)) doneModules foundUsages
pure
( nubOrd $ foundFiles <> map DotCabalFilePath thDepFiles <> resolvedFiles
, M.union (M.fromList foundModules) resolvedModules
, missingModules
, foundUsages'
)
warnUnlisted foundModules = do
let unlistedModules =
foundModules `M.difference`
M.fromList (mapMaybe (fmap (, ()) . dotCabalModule) names0)
pure $
[ UnlistedModulesWarning
component
(map fst (M.toList unlistedModules))
| not (M.null unlistedModules)
]
warnMissing _missingModules =
pure []
-- TODO: bring this back - see
-- https://github.com/commercialhaskell/stack/issues/2649
{-
cabalfp <- asks ctxFile
pure $
if null missingModules
then []
else [ MissingModulesWarning
cabalfp
component
missingModules]
-}
-- TODO: In usages of toResolvedModule / toMissingModule, some sort
-- of map + partition would probably be better.
toResolvedModule ::
(DotCabalDescriptor, Maybe DotCabalPath)
-> Maybe (ModuleName, Path Abs File)
toResolvedModule (DotCabalModule mn, Just (DotCabalModulePath fp)) =
Just (mn, fp)
toResolvedModule _ =
Nothing
toMissingModule ::
(DotCabalDescriptor, Maybe DotCabalPath)
-> Maybe ModuleName
toMissingModule (DotCabalModule mn, Nothing) =
Just mn
toMissingModule _ =
Nothing
-- | Get the dependencies of a Haskell module file.
getDependencies ::
Map FilePath (Path Abs File)
-- ^ Known file usages, where the file path has already been resolved.
-> NamedComponent
-> [Path Abs Dir]
-> DotCabalPath
-> RIO GetPackageFileContext (Set ModuleName, Map FilePath (Path Abs File))
getDependencies knownUsages component dirs dotCabalPath =
case dotCabalPath of
DotCabalModulePath resolvedFile -> readResolvedHi resolvedFile
DotCabalMainPath resolvedFile -> readResolvedHi resolvedFile
DotCabalFilePath{} -> pure (S.empty, M.empty)
DotCabalCFilePath{} -> pure (S.empty, M.empty)
where
readResolvedHi resolvedFile = do
dumpHIDir <- componentOutputDir component <$> asks (.distDir)
dir <- asks (parent . (.file))
let sourceDir = fromMaybe dir $ find (`isProperPrefixOf` resolvedFile) dirs
stripSourceDir d = stripProperPrefix d resolvedFile
case stripSourceDir sourceDir of
Nothing -> pure (S.empty, M.empty)
Just fileRel -> do
let hiPath = FilePath.replaceExtension
(toFilePath (dumpHIDir </> fileRel))
".hi"
dumpHIExists <- liftIO $ D.doesFileExist hiPath
if dumpHIExists
then parseHI knownUsages hiPath
else pure (S.empty, M.empty)
-- | Parse a .hi file into a set of modules and files (a map from a given path
-- to a file to the resolved absolute path to the file).
parseHI ::
Map FilePath (Path Abs File)
-- ^ Known file usages, where the file path has already been resolved.
-> FilePath
-- ^ The path to the *.hi file to be parsed
-> RIO GetPackageFileContext (Set ModuleName, Map FilePath (Path Abs File))
parseHI knownUsages hiPath = do
dir <- asks (parent . (.file))
result <-
liftIO $ catchAnyDeep
(Iface.fromFile hiPath)
(pure . Left . displayException)
case result of
Left msg -> do
prettyStackDevL
[ flow "Failed to decode module interface:"
, style File $ fromString hiPath
, flow "Decoding failure:"
, style Error $ fromString msg
]
pure (S.empty, M.empty)
Right iface -> do
let moduleNames = fmap (fromString . T.unpack . decodeUtf8Lenient . fst) .
Iface.unList . Iface.dmods . Iface.deps
resolveFileDependency file =
case M.lookup file knownUsages of
Just p ->
pure $ Just (file, p)
Nothing -> do
resolved <- forgivingResolveFile dir file >>= rejectMissingFile
when (isNothing resolved) $
prettyWarnL
[ flow "Dependent file listed in:"
, style File $ fromString hiPath
, flow "does not exist:"
, style File $ fromString file
]
pure $ (file,) <$> resolved
resolveUsages = traverse
(resolveFileDependency . Iface.unUsage) . Iface.unList . Iface.usage
resolvedUsages <- catMaybes <$> resolveUsages iface
pure (S.fromList $ moduleNames iface, M.fromList resolvedUsages)
-- | The directory where generated files are put like .o or .hs (from .x files).
componentOutputDir :: NamedComponent -> Path Abs Dir -> Path Abs Dir
componentOutputDir namedComponent distDir =
case namedComponent of
CLib -> buildDir distDir
CSubLib name -> makeTmp name
CFlib name -> makeTmp name
CExe name -> makeTmp name
CTest name -> makeTmp name
CBench name -> makeTmp name
where
makeTmp name =
buildDir distDir </> componentNameToDir (name <> "/" <> name <> "-tmp")
-- | Try to resolve the list of base names in the given directory by
-- looking for unique instances of base names applied with the given
-- extensions.
resolveFiles ::
[Path Abs Dir] -- ^ Directories to look in.
-> [DotCabalDescriptor] -- ^ Base names.
-> RIO GetPackageFileContext [(DotCabalDescriptor, Maybe DotCabalPath)]
resolveFiles dirs names =
forM names (\name -> fmap (name, ) (findCandidate dirs name))
-- | Find a candidate for the given module-or-filename from the list
-- of directories and given extensions.
findCandidate ::
[Path Abs Dir]
-> DotCabalDescriptor
-> RIO GetPackageFileContext (Maybe DotCabalPath)
findCandidate dirs name = do
pkg <- asks (.file) >>= parsePackageNameFromFilePath
customPreprocessorExts <- view $ configL . to (.customPreprocessorExts)
let haskellPreprocessorExts =
haskellDefaultPreprocessorExts ++ customPreprocessorExts
candidates <- liftIO $ makeNameCandidates haskellPreprocessorExts
case candidates of
[candidate] -> pure (Just (cons candidate))
[] -> do
case name of
DotCabalModule mn
| display mn /= paths_pkg pkg -> logPossibilities dirs mn
_ -> pure ()
pure Nothing
(candidate:rest) -> do
warnMultiple name candidate rest
pure (Just (cons candidate))
where
cons =
case name of
DotCabalModule{} -> DotCabalModulePath
DotCabalMain{} -> DotCabalMainPath
DotCabalFile{} -> DotCabalFilePath
DotCabalCFile{} -> DotCabalCFilePath
paths_pkg pkg = "Paths_" ++ packageNameString pkg
makeNameCandidates haskellPreprocessorExts =
fmap
(nubOrd . concat)
(mapM (makeDirCandidates haskellPreprocessorExts) dirs)
makeDirCandidates :: [Text]
-> Path Abs Dir
-> IO [Path Abs File]
makeDirCandidates haskellPreprocessorExts dir =
case name of
DotCabalMain fp -> resolveCandidate dir fp
DotCabalFile fp -> resolveCandidate dir fp
DotCabalCFile fp -> resolveCandidate dir fp
DotCabalModule mn -> do
let perExt ext =
resolveCandidate
dir (Cabal.toFilePath mn ++ "." ++ T.unpack ext)
withHaskellExts <- mapM perExt haskellFileExts
withPPExts <- mapM perExt haskellPreprocessorExts
pure $
case (concat withHaskellExts, concat withPPExts) of
-- If we have exactly 1 Haskell extension and exactly
-- 1 preprocessor extension, assume the former file is
-- generated from the latter
--
-- See https://github.com/commercialhaskell/stack/issues/4076
([_], [y]) -> [y]
-- Otherwise, return everything
(xs, ys) -> xs ++ ys
resolveCandidate dir = fmap maybeToList . resolveDirFile dir
-- | Log that we couldn't find a candidate, but there are
-- possibilities for custom preprocessor extensions.
--
-- For example: .erb for a Ruby file might exist in one of the
-- directories.
logPossibilities :: HasTerm env => [Path Abs Dir] -> ModuleName -> RIO env ()
logPossibilities dirs mn = do
possibilities <- fmap concat (makePossibilities mn)
unless (null possibilities) $ prettyWarnL
[ flow "Unable to find a known candidate for the Cabal entry"
, (style Module . fromString $ display mn) <> ","
, flow "but did find:"
, line <> bulletedList (map pretty possibilities)
, flow "If you are using a custom preprocessor for this module"
, flow "with its own file extension, consider adding the extension"
, flow "to the 'custom-preprocessor-extensions' field in stack.yaml."
]
where
makePossibilities name =
mapM
( \dir -> do
(_,files) <- listDir dir
pure
( map
filename
( filter
(isPrefixOf (display name) . toFilePath . filename)
files
)
)
)
dirs
type CAndJsSources rec =
(HasField "cSources" rec [FilePath], HasField "jsSources" rec [FilePath])
-- | Get all C sources and extra source files in a build.
buildOtherSources ::
CAndJsSources rec
=> rec
-> RIO GetPackageFileContext [DotCabalPath]
buildOtherSources build = do
cwd <- liftIO getCurrentDir
dir <- asks (parent . (.file))
file <- asks (.file)
let resolveDirFiles files toCabalPath =
forMaybeM files $ \fp -> do
result <- resolveDirFile dir fp
case result of
Nothing -> do
warnMissingFile "File" cwd fp file
pure Nothing
Just p -> pure $ Just (toCabalPath p)
csources <- resolveDirFiles build.cSources DotCabalCFilePath
jsources <- resolveDirFiles build.jsSources DotCabalFilePath
pure (csources <> jsources)
-- | Resolve file as a child of a specified directory, symlinks
-- don't get followed.
resolveDirFile ::
(MonadIO m, MonadThrow m)
=> Path Abs Dir
-> FilePath.FilePath
-> m (Maybe (Path Abs File))
resolveDirFile x y = do
-- The standard canonicalizePath does not work for this case
p <- parseCollapsedAbsFile (toFilePath x FilePath.</> y)
exists <- doesFileExist p
pure $ if exists then Just p else Nothing
-- | Warn the user that multiple candidates are available for an
-- entry, but that we picked one anyway and continued.
warnMultiple ::
DotCabalDescriptor
-> Path b t
-> [Path b t]
-> RIO GetPackageFileContext ()
warnMultiple name candidate rest =
-- TODO: figure out how to style 'name' and the dispOne stuff
prettyWarnL
[ flow "There were multiple candidates for the Cabal entry"
, fromString . showName $ name
, line <> bulletedList (map dispOne (candidate:rest))
, line <> flow "picking:"
, dispOne candidate
]
where
showName (DotCabalModule name') = display name'
showName (DotCabalMain fp) = fp
showName (DotCabalFile fp) = fp
showName (DotCabalCFile fp) = fp
dispOne = fromString . toFilePath
-- TODO: figure out why dispOne can't be just `display`
-- (remove the .hlint.yaml exception if it can be)
-- | Parse a package name from a file path.
parsePackageNameFromFilePath :: MonadThrow m => Path a File -> m PackageName
parsePackageNameFromFilePath fp = do
base <- clean $ toFilePath $ filename fp
case parsePackageName base of
Nothing -> throwM $ CabalFileNameInvalidPackageName $ toFilePath fp
Just x -> pure x
where
clean = fmap reverse . strip . reverse
strip ('l':'a':'b':'a':'c':'.':xs) = pure xs
strip _ = throwM (CabalFileNameParseFail (toFilePath fp))
-- | Resolve the directory, if it can't be resolved, warn for the user
-- (purely to be helpful).
resolveDirOrWarn :: FilePath.FilePath
-> RIO GetPackageFileContext (Maybe (Path Abs Dir))
resolveDirOrWarn = resolveOrWarn "Directory" f
where
f p x = forgivingResolveDir p x >>= rejectMissingDir
-- | Make the global autogen dir if Cabal version is new enough.
packageAutogenDir :: Version -> Path Abs Dir -> Maybe (Path Abs Dir)
packageAutogenDir cabalVer distDir
| cabalVer < mkVersion [2, 0] = Nothing
| otherwise = Just $ buildDir distDir </> relDirGlobalAutogen
-- | Make the autogen dir.
componentAutogenDir :: Version -> NamedComponent -> Path Abs Dir -> Path Abs Dir
componentAutogenDir cabalVer component distDir =
componentBuildDir cabalVer component distDir </> relDirAutogen
-- | Make the build dir. Note that Cabal >= 2.0 uses the
-- 'componentBuildDir' above for some things.
buildDir :: Path Abs Dir -> Path Abs Dir
buildDir distDir = distDir </> relDirBuild
-- NOTE: don't export this, only use it for valid paths based on
-- component names.
componentNameToDir :: Text -> Path Rel Dir
componentNameToDir name =
fromMaybe (throw $ ComponentNotParsedBug sName) (parseRelDir sName)
where sName = T.unpack name
-- | See 'Distribution.Simple.LocalBuildInfo.componentBuildDir'
componentBuildDir :: Version -> NamedComponent -> Path Abs Dir -> Path Abs Dir
componentBuildDir cabalVer component distDir
| cabalVer < mkVersion [2, 0] = buildDir distDir
| otherwise =
case component of
CLib -> buildDir distDir
CSubLib name -> buildDir distDir </> componentNameToDir name
CFlib name -> buildDir distDir </> componentNameToDir name
CExe name -> buildDir distDir </> componentNameToDir name
CTest name -> buildDir distDir </> componentNameToDir name
CBench name -> buildDir distDir </> componentNameToDir name
-- Internal helper to define resolveFileOrWarn and resolveDirOrWarn
resolveOrWarn ::
Text
-> (Path Abs Dir -> String -> RIO GetPackageFileContext (Maybe a))
-> FilePath.FilePath
-> RIO GetPackageFileContext (Maybe a)
resolveOrWarn subject resolver path = do
cwd <- liftIO getCurrentDir
file <- asks (.file)
dir <- asks (parent . (.file))
result <- resolver dir path
when (isNothing result) $ warnMissingFile subject cwd path file
pure result
warnMissingFile ::
Text
-> Path Abs Dir
-> FilePath
-> Path Abs File
-> RIO GetPackageFileContext ()
warnMissingFile subject cwd path fromFile =
prettyWarnL
[ fromString . T.unpack $ subject -- TODO: needs style?
, flow "listed in"
, maybe (pretty fromFile) pretty (stripProperPrefix cwd fromFile)
, flow "file does not exist:"
, style Dir . fromString $ path
]