forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackage.hs
More file actions
611 lines (568 loc) · 23.3 KB
/
Package.hs
File metadata and controls
611 lines (568 loc) · 23.3 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
598
599
600
601
602
603
604
605
606
607
608
609
610
611
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-- | Dealing with Cabal.
module Stack.Package
(readPackage
,readPackageBS
,readPackageDir
,readPackageUnresolved
,readPackageUnresolvedBS
,resolvePackage
,getCabalFileName
,Package(..)
,GetPackageFiles(..)
,PackageConfig(..)
,buildLogPath
,PackageException (..)
,resolvePackageDescription
,packageToolDependencies
,packageDependencies
,packageIdentifier)
where
import Control.Exception hiding (try,catch)
import Control.Monad
import Control.Monad.Catch
import Control.Monad.IO.Class
import Control.Monad.Logger (MonadLogger,logWarn)
import Control.Monad.Reader
import qualified Data.ByteString as S
import Data.Data
import Data.Either
import Data.Function
import Data.List
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import Data.Maybe
import Data.Maybe.Extra
import Data.Monoid
import Data.Set (Set)
import qualified Data.Set as S
import Data.Text (Text)
import qualified Data.Text as T
import Data.Text.Encoding (decodeUtf8With)
import Data.Text.Encoding.Error (lenientDecode)
import Data.Yaml (ParseException)
import Distribution.Compiler
import Distribution.InstalledPackageInfo (PError)
import Distribution.ModuleName as Cabal
import Distribution.Package hiding (Package,PackageName,packageName,packageVersion,PackageIdentifier)
import Distribution.PackageDescription hiding (FlagName)
import Distribution.PackageDescription.Parse
import Distribution.Simple.Utils
import Distribution.System (OS, Arch, Platform (..))
import Distribution.Version (intersectVersionRanges)
import Path as FL
import Path.Find
import Path.IO
import Prelude hiding (FilePath)
import Stack.Constants
import Stack.Types
import qualified Stack.Types.PackageIdentifier
import System.Directory (getDirectoryContents)
import System.FilePath (splitExtensions)
import qualified System.FilePath as FilePath
import System.IO.Error
-- | All exceptions thrown by the library.
data PackageException
= PackageConfigError ParseException
| PackageNoConfigFile
| PackageNoCabalFile (Path Abs Dir)
| PackageInvalidCabalFile (Maybe (Path Abs File)) PError
| PackageDepCycle PackageName
| PackageMissingDep Package PackageName VersionRange
| PackageDependencyIssues [PackageException]
| PackageMissingTool Dependency
| PackageCouldn'tFindPkgId PackageName
| PackageStackageVersionMismatch PackageName Version Version
| PackageStackageDepVerMismatch PackageName Version VersionRange
| PackageNoCabalFileFound (Path Abs Dir)
| PackageMultipleCabalFilesFound (Path Abs Dir) [Path Abs File]
| MismatchedCabalName (Path Abs File) PackageName
deriving (Show,Typeable)
instance Exception PackageException
{- TODO use for nicer error messages
instance Show MismatchedCabalName where
show (MismatchedCabalName fp name) = concat
[ "cabal file "
, toFilePath cabalfp
, " has a mismatched package name: "
, packageNameString $ packageName pkg
]
-}
-- | Some package info.
data Package =
Package {packageName :: !PackageName -- ^ Name of the package.
,packageVersion :: !Version -- ^ Version of the package
,packageFiles :: !GetPackageFiles
,packageDeps :: !(Map PackageName VersionRange) -- ^ Packages that the package depends on.
,packageTools :: ![Dependency] -- ^ A build tool name.
,packageAllDeps :: !(Set PackageName) -- ^ Original dependencies (not sieved).
,packageFlags :: !(Map FlagName Bool) -- ^ Flags used on package.
,packageHasLibrary :: !Bool -- ^ does the package have a buildable library stanza?
,packageTests :: !(Set Text) -- ^ names of test suites
}
deriving (Show,Typeable)
-- | Files that the package depends on, relative to package directory.
-- Argument is the location of the .cabal file
newtype GetPackageFiles = GetPackageFiles
{ getPackageFiles :: forall m. (MonadIO m, MonadLogger m, MonadThrow m, MonadCatch m)
=> Path Abs File
-> m (Set (Path Abs File))
}
instance Show GetPackageFiles where
show _ = "<GetPackageFiles>"
-- | Get the identifier of the package.
packageIdentifier :: Package -> Stack.Types.PackageIdentifier.PackageIdentifier
packageIdentifier pkg =
Stack.Types.PackageIdentifier.PackageIdentifier
(packageName pkg)
(packageVersion pkg)
-- | Package build configuration
data PackageConfig =
PackageConfig {packageConfigEnableTests :: !Bool -- ^ Are tests enabled?
,packageConfigEnableBenchmarks :: !Bool -- ^ Are benchmarks enabled?
,packageConfigFlags :: !(Map FlagName Bool) -- ^ Package config flags.
,packageConfigGhcVersion :: !Version -- ^ GHC version
,packageConfigPlatform :: !Platform -- ^ host platform
}
deriving (Show,Typeable)
-- | Compares the package name.
instance Ord Package where
compare = on compare packageName
-- | Compares the package name.
instance Eq Package where
(==) = on (==) packageName
-- | Read the raw, unresolved package information.
readPackageUnresolved :: (MonadIO m, MonadThrow m)
=> Path Abs File
-> m GenericPackageDescription
readPackageUnresolved cabalfp =
liftIO (S.readFile (FL.toFilePath cabalfp))
>>= readPackageUnresolvedBS (Just cabalfp)
-- | Read the raw, unresolved package information from a ByteString.
readPackageUnresolvedBS :: (MonadThrow m)
=> Maybe (Path Abs File)
-> S.ByteString
-> m GenericPackageDescription
readPackageUnresolvedBS mcabalfp bs =
case parsePackageDescription chars of
ParseFailed per ->
throwM (PackageInvalidCabalFile mcabalfp per)
ParseOk _ gpkg -> return gpkg
where
chars = T.unpack (dropBOM (decodeUtf8With lenientDecode bs))
-- https://github.com/haskell/hackage-server/issues/351
dropBOM t = fromMaybe t $ T.stripPrefix "\xFEFF" t
-- | Reads and exposes the package information
readPackage :: (MonadLogger m, MonadIO m, MonadThrow m, MonadCatch m)
=> PackageConfig
-> Path Abs File
-> m Package
readPackage packageConfig cabalfp =
resolvePackage packageConfig `liftM` readPackageUnresolved cabalfp
-- | Reads and exposes the package information, from a ByteString
readPackageBS :: (MonadThrow m)
=> PackageConfig
-> S.ByteString
-> m Package
readPackageBS packageConfig bs =
resolvePackage packageConfig `liftM` readPackageUnresolvedBS Nothing bs
-- | Convenience wrapper around @readPackage@ that first finds the cabal file
-- in the given directory.
readPackageDir :: (MonadLogger m, MonadIO m, MonadThrow m, MonadCatch m)
=> PackageConfig
-> Path Abs Dir
-> m (Path Abs File, Package)
readPackageDir packageConfig dir = do
cabalfp <- getCabalFileName dir
pkg <- readPackage packageConfig cabalfp
name <- parsePackageNameFromFilePath cabalfp
when (packageName pkg /= name)
$ throwM $ MismatchedCabalName cabalfp name
return (cabalfp, pkg)
-- | Resolve a parsed cabal file into a 'Package'.
resolvePackage :: PackageConfig
-> GenericPackageDescription
-> Package
resolvePackage packageConfig gpkg = Package
{ packageName = name
, packageVersion = fromCabalVersion (pkgVersion pkgId)
, packageDeps = deps
, packageFiles = GetPackageFiles $ \cabalfp -> do
files <- runReaderT (packageDescFiles pkg) cabalfp
return $ S.fromList $ cabalfp : files
, packageTools = packageDescTools pkg
, packageFlags = packageConfigFlags packageConfig
, packageAllDeps = S.fromList (M.keys deps)
, packageHasLibrary = maybe False (buildable . libBuildInfo) (library pkg)
, packageTests = S.fromList $ map (T.pack . fst) $ condTestSuites gpkg
}
where
pkgId = package (packageDescription gpkg)
name = fromCabalPackageName (pkgName pkgId)
pkg = resolvePackageDescription packageConfig gpkg
deps = M.filterWithKey (const . (/= name)) (packageDependencies pkg)
-- | Get all dependencies of the package (buildable targets only).
packageDependencies :: PackageDescription -> Map PackageName VersionRange
packageDependencies =
M.fromListWith intersectVersionRanges .
concatMap (map (\dep -> ((depName dep),depRange dep)) .
targetBuildDepends) .
allBuildInfo'
-- | Get all build tool dependencies of the package (buildable targets only).
packageToolDependencies :: PackageDescription -> Map S.ByteString VersionRange
packageToolDependencies =
M.fromList .
concatMap (map (\dep -> ((packageNameByteString $ depName dep),depRange dep)) .
buildTools) .
allBuildInfo'
-- | Get all dependencies of the package (buildable targets only).
packageDescTools :: PackageDescription -> [Dependency]
packageDescTools = concatMap buildTools . allBuildInfo'
-- | This is a copy-paste from Cabal's @allBuildInfo@ function, but with the
-- @buildable@ test removed. The reason is that (surprise) Cabal is broken,
-- see: https://github.com/haskell/cabal/issues/1725
allBuildInfo' :: PackageDescription -> [BuildInfo]
allBuildInfo' pkg_descr = [ bi | Just lib <- [library pkg_descr]
, let bi = libBuildInfo lib
, True || buildable bi ]
++ [ bi | exe <- executables pkg_descr
, let bi = buildInfo exe
, True || buildable bi ]
++ [ bi | tst <- testSuites pkg_descr
, let bi = testBuildInfo tst
, True || buildable bi
, testEnabled tst ]
++ [ bi | tst <- benchmarks pkg_descr
, let bi = benchmarkBuildInfo tst
, True || buildable bi
, benchmarkEnabled tst ]
-- | Get all files referenced by the package.
packageDescFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File) m,MonadCatch m)
=> PackageDescription -> m [Path Abs File]
packageDescFiles pkg =
do libfiles <-
liftM concat
(mapM libraryFiles
(maybe [] return (library pkg)))
exefiles <-
liftM concat
(mapM executableFiles
(executables pkg))
dfiles <-
resolveGlobFiles (map (dataDir pkg FilePath.</>) (dataFiles pkg))
srcfiles <-
resolveGlobFiles (extraSrcFiles pkg)
-- extraTmpFiles purposely not included here, as those are files generated
-- by the build script. Another possible implementation: include them, but
-- don't error out if not present
docfiles <-
resolveGlobFiles (extraDocFiles pkg)
return (concat [libfiles,exefiles,dfiles,srcfiles,docfiles])
-- | Resolve globbing of files (e.g. data files) to absolute paths.
resolveGlobFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File) m,MonadCatch m)
=> [String] -> m [Path Abs File]
resolveGlobFiles =
liftM (catMaybes . concat) .
mapM resolve
where
resolve name =
if any (== '*') name
then explode name
else liftM return (resolveFileOrWarn name)
explode name = do
dir <- asks parent
names <-
matchDirFileGlob'
(FL.toFilePath dir)
name
mapM resolveFileOrWarn names
matchDirFileGlob' dir glob =
catch
(liftIO (matchDirFileGlob_ dir glob))
(\(e :: IOException) ->
if isUserError e
then do
$logWarn
("Wildcard does not match any files: " <> T.pack glob <> "\n" <>
"in directory: " <> T.pack dir)
return []
else throwM e)
-- | This is a copy/paste of the Cabal library function, but with
--
-- @ext == ext'@
--
-- Changed to
--
-- @isSuffixOf ext ext'@
--
-- So that this will work:
--
-- @
-- λ> matchDirFileGlob_ "." "test/package-dump/*.txt"
-- ["test/package-dump/ghc-7.8.txt","test/package-dump/ghc-7.10.txt"]
-- @
--
matchDirFileGlob_ :: String -> String -> IO [String]
matchDirFileGlob_ dir filepath = case parseFileGlob filepath of
Nothing -> die $ "invalid file glob '" ++ filepath
++ "'. Wildcards '*' are only allowed in place of the file"
++ " name, not in the directory name or file extension."
++ " If a wildcard is used it must be with an file extension."
Just (NoGlob filepath') -> return [filepath']
Just (FileGlob dir' ext) -> do
files <- getDirectoryContents (dir FilePath.</> dir')
case [ dir' FilePath.</> file
| file <- files
, let (name, ext') = splitExtensions file
, not (null name) && isSuffixOf ext ext' ] of
[] -> die $ "filepath wildcard '" ++ filepath
++ "' does not match any files."
matches -> return matches
-- | Get all files referenced by the executable.
executableFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File) m)
=> Executable -> m [Path Abs File]
executableFiles exe =
do dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
dir <- asks parent
exposed <-
resolveFiles
(dirs ++ [dir])
[Right (modulePath exe)]
haskellFileExts
bfiles <- buildFiles dir build
return (concat [bfiles,exposed])
where build = buildInfo exe
-- | Get all files referenced by the library.
libraryFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File) m)
=> Library -> m [Path Abs File]
libraryFiles lib =
do dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
dir <- asks parent
exposed <- resolveFiles
(dirs ++ [dir])
(map Left (exposedModules lib))
haskellFileExts
bfiles <- buildFiles dir build
return (concat [bfiles,exposed])
where build = libBuildInfo lib
-- | Get all files in a build.
buildFiles :: (MonadLogger m,MonadIO m,MonadThrow m,MonadReader (Path Abs File) m)
=> Path Abs Dir -> BuildInfo -> m [Path Abs File]
buildFiles dir build = do
dirs <- mapMaybeM resolveDirOrWarn (hsSourceDirs build)
other <- resolveFiles
(dirs ++ [dir])
(map Left (otherModules build))
haskellFileExts
cSources' <- mapMaybeM resolveFileOrWarn (cSources build)
return (other ++ cSources')
-- | Get all dependencies of a package, including library,
-- executables, tests, benchmarks.
resolvePackageDescription :: PackageConfig
-> GenericPackageDescription
-> PackageDescription
resolvePackageDescription packageConfig (GenericPackageDescription desc defaultFlags mlib exes tests benches) =
desc {library =
fmap (resolveConditions rc updateLibDeps) mlib
,executables =
map (resolveConditions rc updateExeDeps .
snd)
exes
,testSuites =
map (resolveConditions rc updateTestDeps .
snd)
tests
,benchmarks =
map (resolveConditions rc updateBenchmarkDeps .
snd)
benches}
where flags =
M.union (packageConfigFlags packageConfig)
(flagMap defaultFlags)
rc = mkResolveConditions
(packageConfigGhcVersion packageConfig)
(packageConfigPlatform packageConfig)
flags
updateLibDeps lib deps =
lib {libBuildInfo =
((libBuildInfo lib) {targetBuildDepends =
deps})}
updateExeDeps exe deps =
exe {buildInfo =
(buildInfo exe) {targetBuildDepends = deps}}
updateTestDeps test deps =
test {testBuildInfo =
(testBuildInfo test) {targetBuildDepends = deps}
,testEnabled = packageConfigEnableTests packageConfig}
updateBenchmarkDeps benchmark deps =
benchmark {benchmarkBuildInfo =
(benchmarkBuildInfo benchmark) {targetBuildDepends = deps}
,benchmarkEnabled = packageConfigEnableBenchmarks packageConfig}
-- | Make a map from a list of flag specifications.
--
-- What is @flagManual@ for?
flagMap :: [Flag] -> Map FlagName Bool
flagMap = M.fromList . map pair
where pair :: Flag -> (FlagName, Bool)
pair (MkFlag (fromCabalFlagName -> name) _desc def _manual) = (name,def)
data ResolveConditions = ResolveConditions
{ rcFlags :: Map FlagName Bool
, rcGhcVersion :: Version
, rcOS :: OS
, rcArch :: Arch
}
-- | Generic a @ResolveConditions@ using sensible defaults.
mkResolveConditions :: Version -- ^ GHC version
-> Platform -- ^ installation target platform
-> Map FlagName Bool -- ^ enabled flags
-> ResolveConditions
mkResolveConditions ghcVersion (Platform arch os) flags = ResolveConditions
{ rcFlags = flags
, rcGhcVersion = ghcVersion
, rcOS = os
, rcArch = arch
}
-- | Resolve the condition tree for the library.
resolveConditions :: (Monoid target,Show target)
=> ResolveConditions
-> (target -> cs -> target)
-> CondTree ConfVar cs target
-> target
resolveConditions rc addDeps (CondNode lib deps cs) = basic <> children
where basic = addDeps lib deps
children = mconcat (map apply cs)
where apply (cond,node,mcs) =
if (condSatisfied cond)
then resolveConditions rc addDeps node
else maybe mempty (resolveConditions rc addDeps) mcs
condSatisfied c =
case c of
Var v -> varSatisifed v
Lit b -> b
CNot c' ->
not (condSatisfied c')
COr cx cy ->
or [condSatisfied cx,condSatisfied cy]
CAnd cx cy ->
and [condSatisfied cx,condSatisfied cy]
varSatisifed v =
case v of
OS os -> os == rcOS rc
Arch arch -> arch == rcArch rc
Flag flag ->
case M.lookup (fromCabalFlagName flag) (rcFlags rc) of
Just x -> x
Nothing ->
-- NOTE: This should never happen, as all flags
-- which are used must be declared. Defaulting
-- to False
False
Impl flavor range ->
flavor == GHC &&
withinRange (rcGhcVersion rc) range
-- | Get the name of a dependency.
depName :: Dependency -> PackageName
depName = \(Dependency n _) -> fromCabalPackageName n
-- | Get the version range of a dependency.
depRange :: Dependency -> VersionRange
depRange = \(Dependency _ r) -> r
-- | 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 :: MonadIO m
=> [Path Abs Dir] -- ^ Directories to look in.
-> [Either ModuleName String] -- ^ Base names.
-> [Text] -- ^ Extentions.
-> m [Path Abs File]
resolveFiles dirs names exts =
liftM catMaybes (forM names (liftIO . makeNameCandidates))
where makeNameCandidates name =
fmap (listToMaybe . rights . concat)
(mapM (makeDirCandidates name) dirs)
makeDirCandidates :: Either ModuleName String
-> Path Abs Dir
-> IO [Either ResolveException (Path Abs File)]
makeDirCandidates name dir =
mapM (\ext ->
try (case name of
Left mn ->
resolveFile dir
(Cabal.toFilePath mn ++ "." ++ ext)
Right fp ->
resolveFile dir fp))
(map T.unpack exts)
-- | Get the filename for the cabal file in the given directory.
--
-- If no .cabal file is present, or more than one is present, an exception is
-- thrown via 'throwM'.
getCabalFileName
:: (MonadThrow m, MonadIO m)
=> Path Abs Dir -- ^ package directory
-> m (Path Abs File)
getCabalFileName pkgDir = do
files <- liftIO $ findFiles
pkgDir
(flip hasExtension "cabal" . FL.toFilePath)
(const False)
case files of
[] -> throwM $ PackageNoCabalFileFound pkgDir
[x] -> return x
_:_ -> throwM $ PackageMultipleCabalFilesFound pkgDir files
where hasExtension fp x = FilePath.takeExtensions fp == "." ++ x
-- | Path for the package's build log.
buildLogPath :: (MonadReader env m, HasBuildConfig env, MonadThrow m)
=> Package -> m (Path Abs File)
buildLogPath package' = do
env <- ask
let stack = configProjectWorkDir env
fp <- parseRelFile $ concat
[ packageNameString $ packageName package'
, "-"
, versionString $ packageVersion package'
, ".log"
]
return $ stack </> $(mkRelDir "logs") </> fp
-- | Resolve the file, if it can't be resolved, warn for the user
-- (purely to be helpful).
resolveFileOrWarn :: (MonadThrow m,MonadIO m,MonadLogger m,MonadReader (Path Abs File) m)
=> FilePath.FilePath
-> m (Maybe (Path Abs File))
resolveFileOrWarn y =
do cwd <- getWorkingDir
file <- ask
dir <- asks parent
result <- resolveFileMaybe dir y
case result of
Nothing ->
$logWarn ("Warning: File listed in " <>
T.pack (maybe (FL.toFilePath file) FL.toFilePath (stripDir cwd file)) <>
" file does not exist: " <>
T.pack y)
_ -> return ()
return result
-- | Resolve the directory, if it can't be resolved, warn for the user
-- (purely to be helpful).
resolveDirOrWarn :: (MonadThrow m,MonadIO m,MonadLogger m,MonadReader (Path Abs File) m)
=> FilePath.FilePath
-> m (Maybe (Path Abs Dir))
resolveDirOrWarn y =
do cwd <- getWorkingDir
file <- ask
dir <- asks parent
result <- resolveDirMaybe dir y
case result of
Nothing ->
$logWarn ("Warning: Directory listed in " <>
T.pack (maybe (FL.toFilePath file) FL.toFilePath (stripDir cwd file)) <>
" file does not exist: " <>
T.pack y)
_ -> return ()
return result