@@ -125,62 +125,169 @@ about how these dependencies get specified.
125
125
In addition to specifying targets, you can also control what gets built, or
126
126
retained, with the following flags:
127
127
128
- * ` --haddock ` , to build documentation. This may cause a lot of packages to get
129
- re-built, so that the documentation links work.
128
+ ### The ` stack build --dependencies-only ` flag
130
129
131
- * ` --force-dirty ` , to force rebuild of packages even when it doesn't seem
132
- necessary based on file dirtiness .
130
+ Pass the flag to skip building the targets. The flag ` --only-dependencies ` has
131
+ the same effect .
133
132
134
- * ` --reconfigure ` , to force reconfiguration even when it doesn't seem necessary
135
- based on file dirtiness. This is sometimes useful with custom ` Setup.hs `
136
- files, in particular when they depend on external data files.
133
+ ### The ` stack build --[no-]dry-run ` flag
137
134
138
- * ` --dry-run ` , to build nothing and output information about the build plan.
135
+ Default: Disabled
139
136
140
- * ` --only-dependencies ` , to skip building the targets .
137
+ Set the flag to build nothing and output information about the build plan .
141
138
142
- * ` --only-snapshot ` , to only build snapshot dependencies, which are cached and
143
- shared with other projects.
139
+ ### The ` stack build --flag ` option
144
140
145
- * ` --keep-going ` , to continue building packages even after some build step
146
- fails. The packages which depend upon the failed build won't get built .
141
+ ` stack build --flag <package_name>:[-]<flag_name> ` sets (or unsets) the
142
+ specified Cabal flag for the specified package .
147
143
148
- * ` --keep-tmp-files ` , to keep intermediate files and build directories that
149
- would otherwise be considered temporary and deleted. It may be useful to
150
- inspect these, if a build fails. By default, they are not kept.
144
+ This option can be specified multiple times to set (or unset) multiple Cabal
145
+ flags.
151
146
152
- * ` --skip ` , to skip building components of a local package. It allows
153
- you to skip test suites and benchmark without specifying other components
154
- (e.g. ` stack test --skip long-test-suite ` will run the tests without the
155
- ` long-test-suite ` test suite). Be aware that skipping executables won't work
156
- the first time the package is built due to
157
- [ an issue in cabal] ( https://github.com/commercialhaskell/stack/issues/3229 ) .
158
- This option can be specified multiple times to skip multiple components.
147
+ The same Cabal flag name can be set (or unset) for multiple packages (at the
148
+ command line only) with:
159
149
160
- ## Flags
150
+ ~~~ text
151
+ stack build --flag *:[-]<flag)name>
152
+ ~~~
153
+
154
+ !!! note
155
+
156
+ Currently you needs to list all of your modules that interpret flags in the
157
+ `other-modules` section of a Cabal file. Cabal (the tool) has a different
158
+ behavior currently and doesn't require that the modules be listed. This may
159
+ change in a future release.
160
+
161
+ ### The ` stack build --[no-]force-dirty ` flag
162
+
163
+ Default: Disabled
164
+
165
+ Set the flag to force rebuild of packages even when it doesn't seem necessary
166
+ based on file dirtiness.
167
+
168
+ ### The ` stack build --[no-]haddock ` flag
169
+
170
+ Default: Disabled
171
+
172
+ Set the flag to build Haddock documentation. This may cause a lot of packages to
173
+ get re-built, so that the documentation links work.
174
+
175
+ ### The ` stack build --[no-]keep-going ` flag
176
+
177
+ Default (` stack build ` ): Disabled
178
+
179
+ Default (` stack test ` or ` stack bench ` ): Enabled
180
+
181
+ Set the flag to continue building packages even after some build step fails.
182
+ The packages which depend upon the failed build won't get built.
183
+
184
+ ### The ` stack build --[no-]keep-tmp-files ` flag
185
+
186
+ Default: Disabled
187
+
188
+ Set the flag to keep intermediate files and build directories that would
189
+ otherwise be considered temporary and deleted. It may be useful to inspect
190
+ these, if a build fails. By default, they are not kept.
191
+
192
+ ### The ` stack build --only-dependencies ` flag
193
+
194
+ Pass the flag to skip building the targets. The flag ` --dependencies-only ` has
195
+ the same effect.
196
+
197
+ ### The ` stack build --[no-]reconfigure ` flag
198
+
199
+ Default: Disabled
200
+
201
+ Set the flag to force reconfiguration even when it doesn't seem necessary based
202
+ on file dirtiness. This is sometimes useful with custom ` Setup.hs ` files, in
203
+ particular when they depend on external data files.
204
+
205
+ ### The ` stack build --skip ` option
206
+
207
+ ` stack build --skip <component> ` skips building the specified components of a
208
+ local package. It allows you to skip test suites and benchmark without
209
+ specifying other components (e.g. ` stack test --skip long-test-suite ` will run
210
+ the tests without the ` long-test-suite ` test suite). Be aware that skipping
211
+ executables won't work the first time the package is built due to an issue in
212
+ [ Cabal] ( https://github.com/commercialhaskell/stack/issues/3229 ) .
213
+
214
+ This option can be specified multiple times to skip multiple components.
215
+
216
+ ### The ` stack build --only-snapshot ` flag
217
+
218
+ Pass the flag to build only snapshot dependencies, which are cached and shared
219
+ with other projects.
220
+
221
+ ## Other flags and options
161
222
162
223
There are a number of other flags accepted by ` stack build ` . Instead of listing
163
224
all of them, please use ` stack build --help ` . Some particularly convenient ones
164
225
worth mentioning here since they compose well with the rest of the build system
165
226
as described:
166
227
167
- * ` --file-watch ` will rebuild your project every time a file changes, by default
168
- it will take into account all files belonging to the targets you specify,
169
- alternatively one could specify ` --watch-all ` which will make Stack watch
170
- any local files (from project packages or from local dependencies)
171
- * ` --exec "cmd [args]" ` will run a command after a successful build
228
+ ### The ` stack build --coverage ` flag
172
229
173
- To come back to the composable approach described above, consider this final
174
- example (which uses the [ wai repository] ( https://github.com/yesodweb/wai/ ) ). The
230
+ Pass the flag to generate a code coverage report. For further information, see
231
+ the [ code coverage] ( coverage.md ) documentation.
232
+
233
+ ### The ` stack build --exec ` option
234
+
235
+ ` stack build --exec "<command> [<arguments>]" ` will run a command after a
236
+ successful build.
237
+
238
+ ### The ` stack build --file-watch ` flag
239
+
240
+ Pass the flag to rebuild your project every time a file changes. By default it
241
+ will take into account all files belonging to the targets you specify. See also
242
+ the ` --watch-all ` flag.
243
+
244
+ ### The ` stack build --[no-]interleaved-output ` flag
245
+
246
+ [ :octicons-tag-24: 2.1.1] ( https://github.com/commercialhaskell/stack/releases/tag/v2.1.1 )
247
+
248
+ Default: Enabled
249
+
250
+ Set the flag to have the output of all packages being built scroll by in a
251
+ streaming fashion. The output from each package built will be prefixed by the
252
+ package name, e.g. ` mtl> Building ... ` . This will include the output from
253
+ dependencies being built, not just targets.
254
+
255
+ Unset the flag to disable this behaviour. When disabled:
256
+
257
+ * When building a single target package (e.g., ` stack build ` in a project
258
+ with only one package, or ` stack build <package_name> ` in a multi-package
259
+ project), the build output from GHC will be hidden for building all
260
+ dependencies, and will be displayed for the one target package.
261
+ * By default, when building multiple target packages, the output from these
262
+ will end up in a log file instead of on the console unless it contains
263
+ errors or warnings, to avoid problems of interleaved output and decrease
264
+ console noise. If you would like to see this content instead, you can use
265
+ the ` dump-logs ` option.
266
+
267
+ ### The ` stack build --pedantic ` flag
268
+
269
+ Pass the flag to build your project with the GHC options ` -Wall ` and ` -Werror ` .
270
+ ` -Wall ` turns on all warning options that indicate potentially suspicious code.
271
+ ` -Werror ` makes any warning into a fatal error.
272
+
273
+ ### The ` stack build --watch-all ` flag
274
+
275
+ Pass the flag to rebuild your project every time any local file changes (from
276
+ project packages or from local dependencies). See also the ` --file-watch ` flag.
277
+
278
+ ## Composition
279
+
280
+ To come back to the composable approach described above, consider this example
281
+ (which uses the ` wai ` [ repository] ( https://github.com/yesodweb/wai/ ) ). The
175
282
command:
176
283
177
284
~~~ text
178
285
stack build --file-watch --test --copy-bins --haddock wai-extra :warp warp:doctest --exec 'echo Yay, it worked!'
179
286
~~~
180
287
181
- This command will start Stack up in file watch mode, waiting for files in your
182
- project to change. When first starting, and each time a file changes, it will do
183
- all of the following.
288
+ will start Stack up in file watch mode, waiting for files in your project to
289
+ change. When first starting, and each time a file changes, it will do all of the
290
+ following.
184
291
185
292
* Build the wai-extra package and its test suites
186
293
* Build the ` warp ` executable
@@ -191,25 +298,3 @@ all of the following.
191
298
* If all of that succeeds:
192
299
* Copy generated executables to the local bin path
193
300
* Run the command ` echo Yay, it worked! `
194
-
195
- ## Build output
196
-
197
- Starting with Stack 2.1, output of all packages being built scrolls by in a
198
- streaming fashion. The output from each package built will be prefixed by the
199
- package name, e.g. ` mtl> Building ... ` . This will include the output from
200
- dependencies being built, not just targets.
201
-
202
- To disable this behaviour, you can pass ` --no-interleaved-output ` , or add
203
- ` interleaved-output: false ` to your ` stack.yaml ` file. When disabled:
204
-
205
- * When building a single target package (e.g., ` stack build ` in a project
206
- with only one package, or ` stack build package-name ` in a multi-package
207
- project), the build output from GHC will be hidden for building all
208
- dependencies, and will be displayed for the one target package.
209
-
210
- * By default, when building multiple target packages, the output from these
211
- will end up in a log file instead of on the console unless it contains
212
- errors or warnings, to avoid problems of interleaved output and decrease
213
- console noise. If you would like to see this content instead, you can use
214
- the ` --dump-logs ` command line option, or add ` dump-logs: all ` to your
215
- YAML configuration file (` stack.yaml ` or ` config.yaml ` ).
0 commit comments