forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPackageFile.hs
More file actions
110 lines (93 loc) · 3.61 KB
/
Copy pathPackageFile.hs
File metadata and controls
110 lines (93 loc) · 3.61 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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE RankNTypes #-}
-- | The facility for retrieving all files from the main Stack
-- 'Stack.Types.Package' type. This was moved into its own module to allow
-- component-level file-gathering without circular dependency at the Package
-- level.
module Stack.Types.PackageFile
( GetPackageFileContext (..)
, DotCabalPath (..)
, DotCabalDescriptor (..)
, GetPackageFiles (..)
, PackageWarning (..)
) where
import Distribution.ModuleName ( ModuleName )
import RIO.Process ( HasProcessContext (processContextL) )
import Stack.Prelude
import Stack.Types.Config
( BuildConfig, HasBuildConfig (..), HasConfig (..)
, HasEnvConfig, HasGHCVariant, HasPlatform, HasRunner (..)
)
import Stack.Types.NamedComponent ( NamedComponent )
data GetPackageFileContext = GetPackageFileContext
{ ctxFile :: !(Path Abs File)
, ctxDistDir :: !(Path Abs Dir)
, ctxBuildConfig :: !BuildConfig
, ctxCabalVer :: !Version
}
instance HasPlatform GetPackageFileContext
instance HasGHCVariant GetPackageFileContext
instance HasLogFunc GetPackageFileContext where
logFuncL = configL.logFuncL
instance HasRunner GetPackageFileContext where
runnerL = configL.runnerL
instance HasStylesUpdate GetPackageFileContext where
stylesUpdateL = runnerL.stylesUpdateL
instance HasTerm GetPackageFileContext where
useColorL = runnerL.useColorL
termWidthL = runnerL.termWidthL
instance HasConfig GetPackageFileContext
instance HasPantryConfig GetPackageFileContext where
pantryConfigL = configL.pantryConfigL
instance HasProcessContext GetPackageFileContext where
processContextL = configL.processContextL
instance HasBuildConfig GetPackageFileContext where
buildConfigL = lens ctxBuildConfig (\x y -> x { ctxBuildConfig = y })
-- | A path resolved from the Cabal file, which is either main-is or
-- an exposed/internal/referenced module.
data DotCabalPath
= DotCabalModulePath !(Path Abs File)
| DotCabalMainPath !(Path Abs File)
| DotCabalFilePath !(Path Abs File)
| DotCabalCFilePath !(Path Abs File)
deriving (Eq, Ord, Show)
-- | A descriptor from a Cabal file indicating one of the following:
--
-- exposed-modules: Foo
-- other-modules: Foo
-- or
-- main-is: Foo.hs
--
data DotCabalDescriptor
= DotCabalModule !ModuleName
| DotCabalMain !FilePath
| DotCabalFile !FilePath
| DotCabalCFile !FilePath
deriving (Eq, Ord, Show)
-- | Files that the package depends on, relative to package directory.
-- Argument is the location of the Cabal file
newtype GetPackageFiles = GetPackageFiles
{ getPackageFiles :: forall env. HasEnvConfig env
=> Path Abs File
-> RIO env
( Map NamedComponent (Map ModuleName (Path Abs File))
, Map NamedComponent [DotCabalPath]
, Set (Path Abs File)
, [PackageWarning]
)
}
instance Show GetPackageFiles where
show _ = "<GetPackageFiles>"
-- | Warning generated when reading a package
data PackageWarning
= UnlistedModulesWarning NamedComponent [ModuleName]
-- ^ Modules found that are not listed in Cabal file
-- TODO: bring this back - see
-- https://github.com/commercialhaskell/stack/issues/2649
{-
| MissingModulesWarning (Path Abs File) (Maybe String) [ModuleName]
-- ^ Modules not found in file system, which are listed in Cabal file
-}