11{-# LANGUAGE NoImplicitPrelude #-}
22
3- module Stack.Options.BuildMonoidParser where
3+ module Stack.Options.BuildMonoidParser
4+ ( buildOptsMonoidParser
5+ , cabalVerboseParser
6+ , cabalVerbosityOptsParser
7+ , cabalVerbosityParser
8+ ) where
49
510import qualified Data.Text as T
611import Distribution.Parsec ( eitherParsec )
712import Options.Applicative
13+ ( Parser , eitherReader , flag , help , long , metavar , option
14+ , strOption
15+ )
816import Options.Applicative.Builder.Extra
17+ ( firstBoolFlagsFalse , firstBoolFlagsNoDefault
18+ , firstBoolFlagsTrue , optionalFirst
19+ )
920import Stack.Build ( splitObjsWarning )
1021import Stack.Prelude
11- import Stack.Options.BenchParser
12- import Stack.Options.TestParser
13- import Stack.Options.HaddockParser
14- import Stack.Options.Utils
22+ import Stack.Options.BenchParser ( benchOptsParser )
23+ import Stack.Options.TestParser ( testOptsParser )
24+ import Stack.Options.HaddockParser ( haddockOptsParser )
25+ import Stack.Options.Utils ( GlobalOptsContext ( .. ), hideMods )
1526import Stack.Types.Config.Build
27+ ( BuildOptsMonoid (.. ), CabalVerbosity
28+ , toFirstCabalVerbosity
29+ )
1630
1731buildOptsMonoidParser :: GlobalOptsContext -> Parser BuildOptsMonoid
18- buildOptsMonoidParser hide0 =
19- BuildOptsMonoid <$> trace' <*> profile <*> noStrip <*> libProfiling <*>
20- exeProfiling <*> libStripping <*> exeStripping <*> haddock <*>
21- haddockOptsParser hideBool <*> openHaddocks <*> haddockDeps <*>
22- haddockInternal <*> haddockHyperlinkSource <*> copyBins <*>
23- copyCompilerTool <*> preFetch <*> keepGoing <*> keepTmpFiles <*>
24- forceDirty <*> tests <*> testOptsParser hideBool <*> benches <*>
25- benchOptsParser hideBool <*> reconfigure <*> cabalVerbose <*> splitObjs <*>
26- skipComponents <*> interleavedOutput <*> ddumpDir
27- where
28- hideBool = hide0 /= BuildCmdGlobalOpts
29- hide =
30- hideMods hideBool
31- hideExceptGhci =
32- hideMods (hide0 `notElem` [BuildCmdGlobalOpts , GhciCmdGlobalOpts ])
32+ buildOptsMonoidParser hide0 = BuildOptsMonoid
33+ <$> trace'
34+ <*> profile
35+ <*> noStrip
36+ <*> libProfiling
37+ <*> exeProfiling
38+ <*> libStripping
39+ <*> exeStripping
40+ <*> haddock
41+ <*> haddockOptsParser hideBool
42+ <*> openHaddocks
43+ <*> haddockDeps
44+ <*> haddockInternal
45+ <*> haddockHyperlinkSource
46+ <*> copyBins
47+ <*> copyCompilerTool
48+ <*> preFetch
49+ <*> keepGoing
50+ <*> keepTmpFiles
51+ <*> forceDirty
52+ <*> tests
53+ <*> testOptsParser hideBool
54+ <*> benches
55+ <*> benchOptsParser hideBool
56+ <*> reconfigure
57+ <*> cabalVerbose
58+ <*> splitObjs
59+ <*> skipComponents
60+ <*> interleavedOutput
61+ <*> ddumpDir
62+ where
63+ hideBool = hide0 /= BuildCmdGlobalOpts
64+ hide = hideMods hideBool
65+ hideExceptGhci =
66+ hideMods (hide0 `notElem` [BuildCmdGlobalOpts , GhciCmdGlobalOpts ])
3367
34- -- These use 'Any' because they are not settable in stack.yaml, so
35- -- there is no need for options like --no-profile.
36- trace' = Any <$>
37- flag
38- False
39- True
40- ( long " trace"
41- <> help
42- " Enable profiling in libraries, executables, etc. for all \
43- \expressions and generate a backtrace on exception"
44- <> hideExceptGhci)
45- profile = Any <$>
46- flag
47- False
48- True
49- ( long " profile"
50- <> help
51- " Enable profiling in libraries, executables, etc. for all \
52- \expressions and generate a profiling report in tests or \
53- \benchmarks"
54- <> hideExceptGhci)
55- noStrip = Any <$>
56- flag
57- False
58- True
59- ( long " no-strip"
60- <> help
61- " Disable DWARF debugging symbol stripping in libraries, \
62- \executables, etc. for all expressions, producing larger \
63- \executables but allowing the use of standard \
64- \debuggers/profiling tools/other utilities that use \
65- \debugging symbols."
66- <> hideExceptGhci)
67- libProfiling =
68- firstBoolFlagsFalse
69- " library-profiling"
70- " library profiling for TARGETs and all its dependencies"
71- hide
72- exeProfiling =
73- firstBoolFlagsFalse
74- " executable-profiling"
75- " executable profiling for TARGETs and all its dependencies"
76- hide
77- libStripping =
78- firstBoolFlagsTrue
79- " library-stripping"
80- " library stripping for TARGETs and all its dependencies"
81- hide
82- exeStripping =
83- firstBoolFlagsTrue
84- " executable-stripping"
85- " executable stripping for TARGETs and all its dependencies"
86- hide
87- haddock =
88- firstBoolFlagsFalse
89- " haddock"
90- " generating Haddocks the package(s) in this directory/configuration"
91- hide
92- openHaddocks =
93- firstBoolFlagsFalse
94- " open"
95- " opening the local Haddock documentation in the browser"
96- hide
97- haddockDeps =
98- firstBoolFlagsNoDefault
99- " haddock-deps"
100- " building Haddocks for dependencies (default: true if building \
101- \Haddocks, false otherwise)"
102- hide
103- haddockInternal =
104- firstBoolFlagsFalse
105- " haddock-internal"
106- " building Haddocks for internal modules (like cabal haddock \
107- \--internal)"
108- hide
109- haddockHyperlinkSource =
110- firstBoolFlagsTrue
111- " haddock-hyperlink-source"
112- " building hyperlinked source for Haddock (like haddock \
113- \--hyperlinked-source)"
114- hide
115- copyBins =
116- firstBoolFlagsFalse
117- " copy-bins"
118- " copying binaries to local-bin (see 'stack path')"
119- hide
120- copyCompilerTool =
121- firstBoolFlagsFalse
122- " copy-compiler-tool"
123- " copying binaries of targets to compiler-tools-bin (see 'stack \
124- \path')"
125- hide
126- keepGoing =
127- firstBoolFlagsNoDefault
128- " keep-going"
129- " continue running after a step fails (default: false for build, \
130- \true for test/bench)"
131- hide
132- keepTmpFiles =
133- firstBoolFlagsFalse
134- " keep-tmp-files"
135- " keep intermediate files and build directories"
136- hide
137- preFetch =
138- firstBoolFlagsFalse
139- " prefetch"
140- " fetching packages necessary for the build immediately, useful \
141- \with --dry-run"
142- hide
143- forceDirty =
144- firstBoolFlagsFalse
145- " force-dirty"
146- " forcing the treatment of all local packages as having dirty \
147- \files, useful for cases where Stack can't detect a file change"
148- hide
149- tests =
150- firstBoolFlagsFalse
151- " test"
152- " testing the package(s) in this directory/configuration"
153- hideExceptGhci
154- benches =
155- firstBoolFlagsFalse
156- " bench"
157- " benchmarking the package(s) in this directory/configuration"
158- hideExceptGhci
159- reconfigure =
160- firstBoolFlagsFalse
161- " reconfigure"
162- " performing the configure step, even if unnecessary. Useful in \
163- \some corner cases with custom Setup.hs files"
164- hide
165- cabalVerbose = cabalVerbosityOptsParser hideBool
166- splitObjs =
167- firstBoolFlagsFalse
168- " split-objs"
169- ( " split-objs, to reduce output size (at the cost of build time). "
170- ++ splitObjsWarning)
171- hide
172- skipComponents = many
173- (fmap
174- T. pack
175- (strOption
176- ( long " skip"
177- <> help " Skip given component (can be specified multiple times)"
178- <> hide)))
179- interleavedOutput =
180- firstBoolFlagsTrue
181- " interleaved-output"
182- " printing concurrent GHC output to the console with a prefix for \
183- \the package name"
184- hide
185- ddumpDir =
186- optionalFirst
187- (strOption
188- ( long " ddump-dir"
189- <> help " Specify output ddump-files"
190- <> hide))
68+ -- These use 'Any' because they are not settable in stack.yaml, so
69+ -- there is no need for options like --no-profile.
70+ trace' = Any <$>
71+ flag
72+ False
73+ True
74+ ( long " trace"
75+ <> help
76+ " Enable profiling in libraries, executables, etc. for all \
77+ \expressions and generate a backtrace on exception"
78+ <> hideExceptGhci
79+ )
80+ profile = Any <$>
81+ flag
82+ False
83+ True
84+ ( long " profile"
85+ <> help
86+ " Enable profiling in libraries, executables, etc. for all \
87+ \expressions and generate a profiling report in tests or \
88+ \benchmarks"
89+ <> hideExceptGhci
90+ )
91+ noStrip = Any <$>
92+ flag
93+ False
94+ True
95+ ( long " no-strip"
96+ <> help
97+ " Disable DWARF debugging symbol stripping in libraries, \
98+ \executables, etc. for all expressions, producing larger \
99+ \executables but allowing the use of standard \
100+ \debuggers/profiling tools/other utilities that use \
101+ \debugging symbols."
102+ <> hideExceptGhci
103+ )
104+ libProfiling = firstBoolFlagsFalse
105+ " library-profiling"
106+ " library profiling for TARGETs and all its dependencies"
107+ hide
108+ exeProfiling = firstBoolFlagsFalse
109+ " executable-profiling"
110+ " executable profiling for TARGETs and all its dependencies"
111+ hide
112+ libStripping = firstBoolFlagsTrue
113+ " library-stripping"
114+ " library stripping for TARGETs and all its dependencies"
115+ hide
116+ exeStripping = firstBoolFlagsTrue
117+ " executable-stripping"
118+ " executable stripping for TARGETs and all its dependencies"
119+ hide
120+ haddock = firstBoolFlagsFalse
121+ " haddock"
122+ " generating Haddocks the package(s) in this directory/configuration"
123+ hide
124+ openHaddocks = firstBoolFlagsFalse
125+ " open"
126+ " opening the local Haddock documentation in the browser"
127+ hide
128+ haddockDeps = firstBoolFlagsNoDefault
129+ " haddock-deps"
130+ " building Haddocks for dependencies (default: true if building Haddocks, \
131+ \false otherwise)"
132+ hide
133+ haddockInternal = firstBoolFlagsFalse
134+ " haddock-internal"
135+ " building Haddocks for internal modules (like cabal haddock --internal)"
136+ hide
137+ haddockHyperlinkSource = firstBoolFlagsTrue
138+ " haddock-hyperlink-source"
139+ " building hyperlinked source for Haddock (like haddock \
140+ \--hyperlinked-source)"
141+ hide
142+ copyBins = firstBoolFlagsFalse
143+ " copy-bins"
144+ " copying binaries to local-bin (see 'stack path')"
145+ hide
146+ copyCompilerTool = firstBoolFlagsFalse
147+ " copy-compiler-tool"
148+ " copying binaries of targets to compiler-tools-bin (see 'stack path')"
149+ hide
150+ keepGoing = firstBoolFlagsNoDefault
151+ " keep-going"
152+ " continue running after a step fails (default: false for build, true for \
153+ \test/bench)"
154+ hide
155+ keepTmpFiles = firstBoolFlagsFalse
156+ " keep-tmp-files"
157+ " keep intermediate files and build directories"
158+ hide
159+ preFetch = firstBoolFlagsFalse
160+ " prefetch"
161+ " fetching packages necessary for the build immediately, useful with \
162+ \--dry-run"
163+ hide
164+ forceDirty = firstBoolFlagsFalse
165+ " force-dirty"
166+ " forcing the treatment of all local packages as having dirty files, \
167+ \useful for cases where Stack can't detect a file change"
168+ hide
169+ tests = firstBoolFlagsFalse
170+ " test"
171+ " testing the package(s) in this directory/configuration"
172+ hideExceptGhci
173+ benches = firstBoolFlagsFalse
174+ " bench"
175+ " benchmarking the package(s) in this directory/configuration"
176+ hideExceptGhci
177+ reconfigure = firstBoolFlagsFalse
178+ " reconfigure"
179+ " performing the configure step, even if unnecessary. Useful in some \
180+ \corner cases with custom Setup.hs files"
181+ hide
182+ cabalVerbose = cabalVerbosityOptsParser hideBool
183+ splitObjs = firstBoolFlagsFalse
184+ " split-objs"
185+ ( " split-objs, to reduce output size (at the cost of build time). "
186+ ++ splitObjsWarning
187+ )
188+ hide
189+ skipComponents = many (fmap T. pack (strOption
190+ ( long " skip"
191+ <> help " Skip given component (can be specified multiple times)"
192+ <> hide
193+ )))
194+ interleavedOutput = firstBoolFlagsTrue
195+ " interleaved-output"
196+ " printing concurrent GHC output to the console with a prefix for the \
197+ \package name"
198+ hide
199+ ddumpDir = optionalFirst (strOption
200+ ( long " ddump-dir"
201+ <> help " Specify output ddump-files"
202+ <> hide
203+ ))
191204
192205-- | Parser for Cabal verbosity options
193206cabalVerbosityOptsParser :: Bool -> Parser (First CabalVerbosity )
@@ -198,10 +211,10 @@ cabalVerbosityOptsParser hide =
198211cabalVerbosityParser :: Bool -> Parser (First CabalVerbosity )
199212cabalVerbosityParser hide =
200213 let pCabalVerbosity = option (eitherReader eitherParsec)
201- ( long " cabal-verbosity"
202- <> metavar " VERBOSITY"
203- <> help " Cabal verbosity (accepts Cabal's numerical and extended syntax)"
204- <> hideMods hide)
214+ ( long " cabal-verbosity"
215+ <> metavar " VERBOSITY"
216+ <> help " Cabal verbosity (accepts Cabal's numerical and extended syntax)"
217+ <> hideMods hide)
205218 in First . Just <$> pCabalVerbosity
206219
207220-- | Parser for the Cabal verbose flag, retained for backward compatibility
0 commit comments