Skip to content

Commit 4eac3cd

Browse files
committed
Tidy up non-standard project intialisation
1 parent 2ce5851 commit 4eac3cd

File tree

3 files changed

+151
-175
lines changed

3 files changed

+151
-175
lines changed

doc/build_command.md

Lines changed: 130 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -125,62 +125,158 @@ about how these dependencies get specified.
125125
In addition to specifying targets, you can also control what gets built, or
126126
retained, with the following flags:
127127

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
130129

131-
* `--force-dirty`, to force rebuild of packages even when it doesn't seem
132-
necessary based on file dirtiness.
130+
Set the flag to skip building the targets. The flag `--only-dependencies` has
131+
the same effect.
133132

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
137134

138-
* `--dry-run`, to build nothing and output information about the build plan.
135+
Default: Disabled
139136

140-
* `--only-dependencies`, to skip building the targets.
137+
Set the flag to build nothing and output information about the build plan.
141138

142-
* `--only-snapshot`, to only build snapshot dependencies, which are cached and
143-
shared with other projects.
139+
### The `stack build --flag` option
144140

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.
147143

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.
151146

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:
159149

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+
Set 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+
Set the flag to build only snapshot dependencies, which are cached and shared
219+
with other projects.
220+
221+
## Other flags and options
161222

162223
There are a number of other flags accepted by `stack build`. Instead of listing
163224
all of them, please use `stack build --help`. Some particularly convenient ones
164225
worth mentioning here since they compose well with the rest of the build system
165226
as described:
166227

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 --exec` option
229+
230+
`stack build --exec "<command> [<arguments>]"` will run a command after a
231+
successful build.
232+
233+
### The `stack build --file-watch` flag
234+
235+
Set the flag to rebuild your project every time a file changes. By default it
236+
will take into account all files belonging to the targets you specify. See also
237+
the `--watch-all` flag.
238+
239+
### The `stack build --[no-]interleaved-output` flag
240+
241+
[:octicons-tag-24: 2.1.1](https://github.com/commercialhaskell/stack/releases/tag/v2.1.1)
242+
243+
Default: Enabled
244+
245+
Set the flag to have the output of all packages being built scroll by in a
246+
streaming fashion. The output from each package built will be prefixed by the
247+
package name, e.g. `mtl> Building ...`. This will include the output from
248+
dependencies being built, not just targets.
249+
250+
Unset the flag to disable this behaviour. When disabled:
172251

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
252+
* When building a single target package (e.g., `stack build` in a project
253+
with only one package, or `stack build <package_name>` in a multi-package
254+
project), the build output from GHC will be hidden for building all
255+
dependencies, and will be displayed for the one target package.
256+
* By default, when building multiple target packages, the output from these
257+
will end up in a log file instead of on the console unless it contains
258+
errors or warnings, to avoid problems of interleaved output and decrease
259+
console noise. If you would like to see this content instead, you can use
260+
the `dump-logs` option.
261+
262+
### The `stack build --watch-all` flag
263+
264+
Set the flag to rebuild your project every time any local file changes (from
265+
project packages or from local dependencies). See also the `--file-watch` flag.
266+
267+
## Composition
268+
269+
To come back to the composable approach described above, consider this example
270+
(which uses the `wai` [repository](https://github.com/yesodweb/wai/)). The
175271
command:
176272

177273
~~~text
178274
stack build --file-watch --test --copy-bins --haddock wai-extra :warp warp:doctest --exec 'echo Yay, it worked!'
179275
~~~
180276

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.
277+
will start Stack up in file watch mode, waiting for files in your project to
278+
change. When first starting, and each time a file changes, it will do all of the
279+
following.
184280

185281
* Build the wai-extra package and its test suites
186282
* Build the `warp` executable
@@ -191,25 +287,3 @@ all of the following.
191287
* If all of that succeeds:
192288
* Copy generated executables to the local bin path
193289
* 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`).

doc/nonstandard_project_init.md

Lines changed: 20 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -2,132 +2,34 @@
22

33
# Non-standard project initialization
44

5-
## Introduction
6-
The purpose of this page is to collect information about issues that arise when
7-
users either have an existing Cabal project or another nonstandard setup such
8-
as a private Hackage database.
5+
You may need to configure Stack to work with an existing project that has one or
6+
more Cabal files but no Stack project-level configuration file (`stack.yaml`).
97

10-
## Using a Cabal file
8+
## The `stack init` command
119

12-
New users may be confused by the fact that you must add dependencies to the
13-
package's Cabal file, even in the case when you have already listed the package
14-
in the `stack.yaml` file. In most cases, dependencies for your package that are
15-
in the Stackage snapshot need *only* be added to the Cabal file. Stack makes
16-
heavy use of Cabal under the hood. In general, your Stack packages should also
17-
end up being valid packages for Cabal (the tool).
10+
The `stack init` command:
1811

19-
### Issues Referenced
20-
- <https://github.com/commercialhaskell/stack/issues/105>
12+
* finds all of the Cabal files in your current directory and subdirectories
13+
(unless you use `--ignore-subdirs`) and determines the packages and versions
14+
they require
15+
* Finds the best combination of snapshot and package flags that allows
16+
everything to compile with minimum external dependencies
17+
* Tries to look for the best matching snapshot from latest Haskell LTS, latest
18+
Stackage Nightly, and other Haskell LTS, in that order
2119

22-
## Passing Flags to Cabal
20+
If `stack init` finds a match, it will generate a `stack.yaml` file.
2321

24-
Any build command, `bench`, `install`, `haddock`, `test`, etc. takes a `--flag`
25-
option which passes flags to cabal. Another way to do this is using the flags
26-
field in a `stack.yaml`, with the option to specify flags on a per package
27-
basis.
22+
You can specify the directory, or directories to include in the search for
23+
Cabal files.
2824

29-
As an example, in a `stack.yaml` for multi-package project with packages `foo`,
30-
`bar`, `baz`:
25+
### The `stack init --force` flag
3126

32-
~~~yaml
33-
flags:
34-
foo:
35-
release: true
36-
bar:
37-
default: true
38-
baz:
39-
manual: true
40-
~~~
27+
Set the flag to force the over-writing of any existing `stack.yaml` file.
4128

42-
It is also possible to pass the same flag to multiple packages, i.e.
43-
`stack build --flag *:necessary`
29+
### The `stack init --ignore-subdirs` flag
4430

45-
Currently one needs to list all of your modules that interpret flags in the
46-
`other-modules` section of a cabal file. Cabal (the tool) has a different
47-
behavior currently and doesn't require that the modules be listed. This may
48-
change in a future release.
31+
Set the flag to not search for Cabal files in subdirectories.
4932

33+
### The `stack init --omit-packages` flag
5034

51-
### Issues Referenced
52-
- <https://github.com/commercialhaskell/stack/issues/191>
53-
- <https://github.com/commercialhaskell/stack/issues/417>
54-
- <https://github.com/commercialhaskell/stack/issues/335>
55-
- <https://github.com/commercialhaskell/stack/issues/301>
56-
- <https://github.com/commercialhaskell/stack/issues/365>
57-
- <https://github.com/commercialhaskell/stack/issues/105>
58-
59-
## Selecting a Resolver
60-
61-
`stack init` or `stack new` will try to default to the current Haskell LTS
62-
present on `https://www.stackage.org/snapshots` if no snapshot has been
63-
previously used locally, and to the latest LTS snapshot locally used for a
64-
build otherwise. Using an incorrect resolver can cause a build to fail if the
65-
version of GHC it requires is not present.
66-
67-
In order to override the resolver entry at project initialization one can pass
68-
`--prefer-lts` or `--prefer-nightly`. These options will choose the latest LTS
69-
or nightly versions locally used. Alternatively the `--resolver` option can be
70-
used with the name of any snapshots on Stackage, or with `lts` or `nightly` to
71-
select the latest versions, disregarding previously used ones. This is not the
72-
default so as to avoid unnecessary recompilation time.
73-
74-
:TODO: Document `--solver`
75-
76-
### Issues Referenced
77-
- <https://github.com/commercialhaskell/stack/issues/468>
78-
- <https://github.com/commercialhaskell/stack/issues/464>
79-
80-
## Using git Repositories
81-
82-
Stack has support for packages that reside in remote git locations. Please see
83-
the [YAML configuration
84-
documentation](yaml_configuration.md#git-and-mercurial-repos) for more
85-
information.
86-
87-
### Issues Referenced
88-
- <https://github.com/commercialhaskell/stack/issues/254>
89-
- <https://github.com/commercialhaskell/stack/issues/199>
90-
91-
## Private Hackage
92-
Working with a private Hackage is currently supported in certain situations.
93-
There exist special entries in `stack.yaml` that may help you. In a
94-
`stack.yaml` file, it is possible to add lines for packages in your database
95-
referencing the sdist locations via an `http` entry, or to use a `Hackage`
96-
entry.
97-
98-
The recommended stack workflow is to use git submodules instead of a private
99-
Hackage. Either by using git submodules and listing the directories in the
100-
packages section of `stack.yaml`, or by adding the private dependencies as git
101-
URIs with a commit SHA to the `stack.yaml`. This has the large benefit of
102-
eliminating the need to manage a Hackage database and pointless version bumps.
103-
104-
For further information see [YAML configuration](yaml_configuration.md)
105-
106-
### Issues Referenced
107-
- <https://github.com/commercialhaskell/stack/issues/445>
108-
- <https://github.com/commercialhaskell/stack/issues/565>
109-
110-
## Custom Snapshots
111-
See [Custom Snapshots](custom_snapshot.md).
112-
113-
### Issues Referenced
114-
- <https://github.com/commercialhaskell/stack/issues/111>
115-
- <https://github.com/commercialhaskell/stack/issues/253>
116-
- <https://github.com/commercialhaskell/stack/issues/137>
117-
118-
## Intra-package Targets
119-
120-
Stack supports intra-package targets, similar to `cabal build COMPONENTS` for
121-
situations when you don't want to build every target inside your package.
122-
123-
For example, command:
124-
125-
~~~text
126-
stack build stack:lib:stack
127-
stack test stack:test:stack-integration-test
128-
~~~
129-
130-
Note: this does require prefixing the component name with the package name.
131-
132-
### Issues referenced
133-
- <https://github.com/commercialhaskell/stack/issues/201>
35+
Set the flag to exclude any conflicting or incompatible user packages.

doc/yaml_configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ Default: `{}`
225225

226226
Command line equivalent (takes precedence): `stack build --flag` option
227227

228-
Flags can be set for each package separately, e.g.
228+
Flags can be set for each package separately. For example:
229229

230230
~~~yaml
231231
flags:

0 commit comments

Comments
 (0)