forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigParser.hs
More file actions
225 lines (222 loc) · 8.21 KB
/
ConfigParser.hs
File metadata and controls
225 lines (222 loc) · 8.21 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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE DuplicateRecordFields #-}
module Stack.Options.ConfigParser
( configOptsParser
) where
import Data.Char ( toUpper )
import Options.Applicative
( Parser, auto, completer, completeWith, eitherReader, help
, long, metavar, option, short, strOption
)
import Options.Applicative.Builder.Extra
( PathCompleterOpts (..), absDirOption, absFileOption
, defaultPathCompleterOpts, dirCompleter, firstBoolFlagsFalse
, firstBoolFlagsNoDefault, firstBoolFlagsTrue, optionalFirst
, pathCompleterWith
)
import Path ( PathException (..), parseRelDir )
import Stack.Constants ( stackRootOptionName )
import Stack.Options.BuildMonoidParser ( buildOptsMonoidParser )
import Stack.Options.DockerParser ( dockerOptsParser )
import Stack.Options.GhcBuildParser ( ghcBuildParser )
import Stack.Options.GhcVariantParser ( ghcVariantParser )
import Stack.Options.NixParser ( nixOptsParser )
import Stack.Options.Utils ( GlobalOptsContext (..), hideMods )
import Stack.Prelude hiding ( snapshotLocation )
import Stack.Types.ColorWhen ( readColorWhen )
import Stack.Types.ConfigMonoid ( ConfigMonoid (..) )
import Stack.Types.DumpLogs ( DumpLogs (..) )
import qualified System.FilePath as FilePath
-- | Command-line arguments parser for configuration.
configOptsParser :: FilePath -> GlobalOptsContext -> Parser ConfigMonoid
configOptsParser currentDir hide0 =
( \stackRoot workDir buildOpts dockerOpts nixOpts systemGHC installGHC arch
ghcVariant ghcBuild jobs extraIncludeDirs extraLibDirs
customPreprocessorExts overrideGccPath overrideHpack skipGHCCheck skipMsys
localBinPath setupInfoLocations modifyCodePage allowDifferentUser dumpLogs
colorWhen snapshotLocation noRunCompile -> mempty
{ stackRoot
, workDir
, buildOpts
, dockerOpts
, nixOpts
, systemGHC
, installGHC
, skipGHCCheck
, arch
, ghcVariant
, ghcBuild
, jobs
, extraIncludeDirs
, extraLibDirs
, customPreprocessorExts
, overrideGccPath
, overrideHpack
, skipMsys
, localBinPath
, setupInfoLocations
, modifyCodePage
, allowDifferentUser
, dumpLogs
, colorWhen
, snapshotLocation
, noRunCompile
}
)
<$> optionalFirst (absDirOption
( long stackRootOptionName
<> metavar (map toUpper stackRootOptionName)
<> help "Absolute path to the global Stack root directory. Overrides \
\any STACK_ROOT environment variable."
<> hide
))
<*> optionalFirst (option (eitherReader (mapLeft showWorkDirError . parseRelDir))
( long "work-dir"
<> metavar "WORK-DIR"
<> completer
( pathCompleterWith
( defaultPathCompleterOpts
{ absolute = False, fileFilter = const False }
)
)
<> help "Relative path to Stack's work directory. Overrides any \
\STACK_WORK environment variable. (default: '.stack-work')"
<> hide
))
<*> buildOptsMonoidParser hide0
<*> dockerOptsParser True
<*> nixOptsParser True
<*> firstBoolFlagsNoDefault
"system-ghc"
"using the system installed GHC (on the PATH) if it is available and \
\its version matches. (default: disabled)"
hide
<*> firstBoolFlagsTrue
"install-ghc"
"downloading and installing GHC if necessary. (Can be done manually \
\with 'stack setup'.)"
hide
<*> optionalFirst (strOption
( long "arch"
<> metavar "ARCH"
<> help "System architecture, e.g. i386, x86_64, aarch64."
<> hide
))
<*> optionalFirst (ghcVariantParser (hide0 /= OuterGlobalOpts))
<*> optionalFirst (ghcBuildParser (hide0 /= OuterGlobalOpts))
<*> optionalFirst (option auto
( long "jobs"
<> short 'j'
<> metavar "JOBS"
<> help "Number of concurrent jobs to run."
<> hide
))
<*> many ((currentDir FilePath.</>) <$> strOption
( long "extra-include-dirs"
<> metavar "DIR"
<> completer dirCompleter
<> help "Extra directories to check for C header files."
<> hide
))
<*> many ((currentDir FilePath.</>) <$> strOption
( long "extra-lib-dirs"
<> metavar "DIR"
<> completer dirCompleter
<> help "Extra directories to check for libraries."
<> hide
))
<*> many (strOption
( long "custom-preprocessor-extensions"
<> metavar "EXT"
<> help "Extensions used for custom preprocessors."
<> hide
))
<*> optionalFirst (absFileOption
( long "with-gcc"
<> metavar "PATH-TO-GCC"
<> help "Use gcc found at PATH-TO-GCC."
<> hide
))
<*> optionalFirst (strOption
( long "with-hpack"
<> metavar "HPACK"
<> help "Use HPACK executable (overrides bundled Hpack)."
<> hide
))
<*> firstBoolFlagsFalse
"skip-ghc-check"
"skipping the GHC version and architecture check."
hide
<*> firstBoolFlagsFalse
"skip-msys"
"skipping the local MSYS installation (Windows only)."
hide
<*> optionalFirst ((currentDir FilePath.</>) <$> strOption
( long "local-bin-path"
<> metavar "DIR"
<> completer dirCompleter
<> help "Override the target directory for 'stack build --copy-bins' \
\and 'stack install'. DIR can be an absolute path or one \
\relative to the current directory."
<> hide
))
<*> many (strOption
( long "setup-info-yaml"
<> help "Alternate URL or path (relative or absolute) for Stack \
\dependencies."
<> metavar "URL"
))
<*> firstBoolFlagsTrue
"modify-code-page"
"setting the codepage to support UTF-8 (Windows only)."
hide
<*> firstBoolFlagsNoDefault
"allow-different-user"
"permission for users other than the owner of the Stack root directory \
\to use a Stack installation (POSIX only). (default: inside Docker, \
\ true; otherwise, false)"
hide
<*> fmap toDumpLogs (firstBoolFlagsNoDefault
"dump-logs"
"dump the build output logs for local packages to the console. \
\(default: dump warning logs)"
hide)
<*> optionalFirst (option readColorWhen
( long "color"
<> long "colour"
<> metavar "WHEN"
<> completeWith ["always", "never", "auto"]
<> help "Specify when to use color in output; WHEN is 'always', \
\'never', or 'auto'. On Windows versions before Windows \
\10, for terminals that do not support color codes, the \
\default is 'never'; color may work on terminals that \
\support color codes."
<> hide
))
<*> optionalFirst (strOption
( long "snapshot-location-base"
<> help "The base location of LTS/Nightly snapshots."
<> metavar "URL"
))
<*> firstBoolFlagsFalse
"script-no-run-compile"
"the use of options `--no-run --compile` with `stack script`."
hide
where
hide = hideMods (hide0 /= OuterGlobalOpts)
toDumpLogs (First (Just True)) = First (Just DumpAllLogs)
toDumpLogs (First (Just False)) = First (Just DumpNoLogs)
toDumpLogs (First Nothing) = First Nothing
showWorkDirError err = case fromException err of
Just (InvalidRelDir x) ->
"Stack failed to interpret the value of the option as a valid\n\
\relative path to a directory. Stack will not accept an absolute path. A \
\path\n\
\containing a .. (parent directory) component is not valid.\n\n\
\If set, Stack expects the value to identify the location of Stack's \
\work\n\
\directory, relative to the root directory of the project or package. \
\Stack\n\
\encountered the value:\n"
++ x
_ -> displayException err