forked from commercialhaskell/stack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildParser.hs
More file actions
184 lines (178 loc) · 6.15 KB
/
BuildParser.hs
File metadata and controls
184 lines (178 loc) · 6.15 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
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
module Stack.Options.BuildParser
( buildOptsParser
, flagsParser
, targetsParser
) where
import qualified Data.List as L
import qualified Data.Map as Map
import qualified Data.Text as T
import Options.Applicative
( Parser, completer, flag, flag', help, internal, long
, metavar, option, strOption, switch, value
)
import Options.Applicative.Args ( cmdOption )
import Options.Applicative.Builder.Extra ( textArgument, textOption )
import Stack.Options.Completion
( flagCompleter, ghcOptsCompleter, targetCompleter )
import Stack.Options.PackageParser ( readFlag )
import Stack.Prelude
import Stack.Types.BuildOptsCLI
( ApplyCLIFlag, BuildCommand, BuildOptsCLI (..)
, BuildSubset (..), FileWatchOpts (..)
)
-- | Parser for CLI-only build arguments
buildOptsParser :: BuildCommand -> Parser BuildOptsCLI
buildOptsParser cmd = BuildOptsCLI
<$> targetsParser
<*> switch
( long "dry-run"
<> help "Don't build anything, just prepare to."
)
<*> ( (\x y z -> concat [x, y, z])
<$> flag
[]
["-Wall", "-Werror"]
( long "pedantic"
<> help "Pass the -Wall and -Werror flags to GHC, turning on all \
\warnings that indicate potentially suspicious code and \
\making all warnings into fatal errors. Can be overridden \
\using Stack's --ghc-options option."
)
<*> flag
[]
["-O0"]
( long "fast"
<> help "Pass a -O0 flag to GHC, turning off any GHC \
\optimsations that have been set. Can be overridden using \
\Stack's --ghc-options option."
)
<*> many (textOption
( long "ghc-options"
<> metavar "OPTIONS"
<> completer ghcOptsCompleter
<> help "Additional options to be passed to GHC (can be specified \
\multiple times)."
))
)
<*> progsOptionsParser
<*> flagsParser
<*> ( flag' BSOnlyDependencies
( long "dependencies-only"
<> help "A synonym for --only-dependencies."
)
<|> flag' BSOnlySnapshot
( long "only-snapshot"
<> help "Only build packages for the snapshot database, not the \
\local database."
)
<|> flag' BSOnlyDependencies
( long "only-dependencies"
<> help "Only build packages that are dependencies of targets on \
\the command line."
)
<|> flag' BSOnlyLocals
( long "only-locals"
<> help "Only build packages in the local database. Fail if the \
\build plan includes the snapshot database."
)
<|> pure BSAll
)
<*> ( flag' FileWatch
( long "file-watch"
<> help "Watch for changes in local files and automatically \
\rebuild."
)
<|> flag' FileWatchPoll
( long "file-watch-poll"
<> help "Like --file-watch, but polling the filesystem instead of \
\using events."
)
<|> pure NoFileWatch
)
<*> switch
( long "watch-all"
<> help "Watch all local files not taking targets into account."
)
<*> many (cmdOption
( long "exec"
<> metavar "COMMAND [ARGUMENT(S)]"
<> help "Command and argument(s) to run after a successful build."
))
<*> switch
( long "only-configure"
<> help "Only perform the configure step, not any builds. Intended for \
\tool usage. May break when used on multiple packages at once!"
)
<*> pure cmd
<*> switch
( long "initial-build-steps"
<> help "For target packages, only run initial build steps needed for \
\GHCi."
<> internal
)
targetsParser :: Parser [Text]
targetsParser =
many (textArgument
( metavar "TARGET"
<> completer targetCompleter
<> help "If none specified, use all local packages. See \
\https://docs.haskellstack.org/en/stable/build_command/#target-syntax \
\for details."
))
flagsParser :: Parser (Map.Map ApplyCLIFlag (Map.Map FlagName Bool))
flagsParser = Map.unionsWith Map.union
<$> many (option readFlag
( long "flag"
<> completer flagCompleter
<> metavar "PACKAGE:[-]FLAG"
<> help "Override flags set in stack.yaml (applies to local packages \
\and extra-deps)."
))
progsOptionsParser :: Parser [(Text, [Text])]
progsOptionsParser =
dummyProgOptionsParser
*> (filter (not . L.null . snd) <$> progsOptionsParser')
where
-- The purpose of this parser is only to generate the desired help text. The
-- actual --PROG-options parsers are all internal.
dummyProgOptionsParser :: Parser String
dummyProgOptionsParser = strOption
( long "PROG-option"
<> help
( "Pass an argument to PROG (can be specified multiple times). PROG \
\must be a program recognised by the Cabal library and one of "
<> T.unpack (T.intercalate " " progs) <> "."
)
<> metavar "ARG"
<> value ""
)
progs :: [Text]
progs = L.sort
[
-- configuration
"pkg-config"
-- preprocessors
, "alex"
, "c2hs"
, "cpphs"
, "doctest"
, "greencard"
, "happy"
, "hsc2hs"
, "hscolour"
-- platform toolchain (GNU)
, "ar" -- create, modify, and extract from archives
, "gcc" -- C/C++ compiler
, "ld" -- linker
, "strip" -- discards symbols and other data from object files
, "tar"
]
progsOptionsParser' :: Parser [(Text, [Text])]
progsOptionsParser' = traverse mkProgOptionsParser progs
mkProgOptionsParser :: Text -> Parser (Text, [Text])
mkProgOptionsParser prog = fmap (prog,) $ many $ textOption
( long (T.unpack prog <> "-option")
<> internal
)