Fix optional test-suite/benchmark type docs
[cabal.git] / CONTRIBUTING.md
blobb0491d8868f4727ea9af3c411b1eb037a5dae7fa
1 # Contributing to Cabal
3 Building Cabal for hacking
4 --------------------------
6 The current recommended way of developing Cabal is to use the
7 `v2-build` feature which [shipped in cabal-install-1.24](http://blog.ezyang.com/2016/05/announcing-cabal-new-build-nix-style-local-builds/).  Assuming
8 that you have a sufficiently recent cabal-install (see above),
9 it is sufficient to run:
11 ```
12 cabal v2-build cabal
13 ```
15 To build a local, development copy of cabal-install.  The location
16 of your build products will vary depending on which version of
17 cabal-install you use to build; see the documentation section
18 [Where are my build products?](http://cabal.readthedocs.io/en/latest/nix-local-build.html#where-are-my-build-products)
19 to find the binary (or just run `find -type f -executable -name cabal`).
21 Here are some other useful variations on the commands:
23 ```
24 cabal v2-build Cabal # build library only
25 cabal v2-build Cabal-tests:unit-tests # build Cabal's unit test suite
26 cabal v2-build cabal-tests # etc...
27 ```
29 Running tests
30 -------------
32 **Using Github Actions.**
33 If you are not in a hurry, the most convenient way to run tests on Cabal
34 is to make a branch on GitHub and then open a pull request; our
35 continuous integration service on Github Actions builds and
36 tests your code.  Title your PR with WIP so we know that it does not need
37 code review.
39 Some tips for using Github Actions effectively:
41 * Github Actions builds take a long time.  Use them when you are pretty
42   sure everything is OK; otherwise, try to run relevant tests locally
43   first.
45 * Watch over your jobs on the [Github Actions website](http://github.org/haskell/cabal/actions).
46   If you know a build of yours is going to fail (because one job has
47   already failed), be nice to others and cancel the rest of the jobs,
48   so that other commits on the build queue can be processed.
50 **How to debug a failing CI test.**
51 One of the annoying things about running tests on CI is when they
52 fail, there is often no easy way to further troubleshoot the broken
53 build.  Here are some guidelines for debugging continuous integration
54 failures:
56 1. Can you tell what the problem is by looking at the logs?  The
57    `cabal-testsuite` tests run with `-v` logging by default, which
58    is dumped to the log upon failure; you may be able to figure out
59    what the problem is directly this way.
61 2. Can you reproduce the problem by running the test locally?
62    See the next section for how to run the various test suites
63    on your local machine.
65 3. Is the test failing only for a specific version of GHC, or
66    a specific operating system?  If so, try reproducing the
67    problem on the specific configuration.
69 4. Is the test failing on a Github Actions per-GHC build.
70    In this case, if you click on "Branch", you can get access to
71    the precise binaries that were built by Github Actions that are being
72    tested.  If you have an Ubuntu system, you can download
73    the binaries and run them directly.
75 If none of these let you reproduce, there might be some race condition
76 or continuous integration breakage; please file a bug.
78 **Running tests locally.**
79 To run tests locally with `v2-build`, you will need to know the
80 name of the test suite you want.  Cabal and cabal-install have
81 several.  Also, you'll want to read [Where are my build products?](http://cabal.readthedocs.io/en/latest/nix-local-build.html#where-are-my-build-products)
83 The most important test suite is `cabal-testsuite`: most user-visible
84 changes to Cabal should come with a test in this framework.  See
85 [cabal-testsuite/README.md](cabal-testsuite/README.md) for more
86 information about how to run tests and write new ones.  Quick
87 start: use `cabal-tests` to run `Cabal` tests, and `cabal-tests
88 --with-cabal=/path/to/cabal` to run `cabal-install` tests
89 (don't forget `--with-cabal`! Your cabal-install tests won't
90 run without it).
92 There are also other test suites:
94 * `Cabal-tests:unit-tests` are small, quick-running unit tests
95   on small pieces of functionality in Cabal.  If you are working
96   on some utility functions in the Cabal library you should run this
97   test suite.
99 * `cabal-install:unit-tests` are small, quick-running unit tests on
100   small pieces of functionality in cabal-install.  If you are working
101   on some utility functions in cabal-install you should run this test
102   suite.
104 * `cabal-install:long-tests` are QuickCheck tests on
105   cabal-install's dependency solver, VCS, and file monitoring code.
106   If you are working on the solver you should run this test suite.
108 * `cabal-install:integration-tests2` are integration tests on some
109   top-level API functions inside the `cabal-install` source code.
111 For these test executables, `-p` which applies a regex filter to the test
112 names. When running `cabal-install` test suites, one need only use `cabal test` or
113 `cabal run <test-target>` in order to test locally.
116 Whitespace Conventions
117 ----------------------
119 * No tab characters allowed.
120 * No trailing whitespace allowed.
121 * File needs to be terminated by a newline character.
123 These conventions are enforced by the
124 [fix-whitespace](https://hackage.haskell.org/package/fix-whitespace)
125 tool.  Install it from hackage as usual (`cabal install fix-whitespace`)
126 and run it in the project root to fix whitespace violations.
128 The files included in the automatic whitespace check are specified in
129 `fix-whitespace.yaml`.  Please add to this file if you add textfiles
130 to this repository that are not included by the rules given there.
131 Note that files that make essential use of tab characters (like `Makefile`)
132 should _not_ be included in the automatic check.
134 Whitespace conventions are enforced by
135 [CI](https://github.com/haskell/cabal/actions/workflows/whitespace.yml).
136 If you push a fix of a whitespace violation, please do so in a
137 _separate commit_.
142 Other Conventions
143 -----------------
145 * Try to follow style conventions of a file you are modifying, and
146   avoid gratuitous reformatting (it makes merges harder!)
148 * Format your commit messages [in the standard way](https://chris.beams.io/posts/git-commit/#seven-rules).
150 * A lot of Cabal does not have top-level comments.  We are trying to
151   fix this.  If you add new top-level definitions, please Haddock them;
152   and if you spend some time understanding what a function does, help
153   us out and add a comment.  We'll try to remind you during code review.
155 * If you do something tricky or non-obvious, add a comment.
157 * For local imports (Cabal module importing Cabal module), import lists
158   are NOT required (although you may use them at your discretion.)  For
159   third-party and standard library imports, please use either qualified imports
160   or explicit import lists.
162 * You can use basically any GHC extension supported by a GHC in our
163   support window, except Template Haskell, which would cause
164   bootstrapping problems in the GHC compilation process.
166 * Our GHC support window is five years for the Cabal library and three
167   years for cabal-install: that is, the Cabal library must be
168   buildable out-of-the-box with the dependencies that shipped with GHC
169   for at least five years.  The Travis CI checks this, so most
170   developers submit a PR to see if their code works on all these
171   versions of GHC.  `cabal-install` must also be buildable on all
172   supported GHCs, although it does not have to be buildable
173   out-of-the-box. Instead, the `cabal-install/bootstrap.sh` script
174   must be able to download and install all of the dependencies (this
175   is also checked by CI). Also, self-upgrade to the latest version
176   (i.e. `cabal install cabal-install`) must work with all versions of
177   `cabal-install` released during the last three years.
179 * `Cabal` has its own Prelude, in `Distribution.Compat.Prelude`,
180   that provides a compatibility layer and exports some commonly
181   used additional functions. Use it in all new modules.
183 * As far as possible, please do not use CPP. If you must use it,
184   try to put it in a `Compat` module, and minimize the amount of code
185   that is enclosed by CPP.  For example, prefer:
186   ```
187   f :: Int -> Int
188   #ifdef mingw32_HOST_OS
189   f = (+1)
190   #else
191   f = (+2)
192   #endif
193   ```
195   over:
196   ```
197   #ifdef mingw32_HOST_OS
198   f :: Int -> Int
199   f = (+1)
200   #else
201   f :: Int -> Int
202   f = (+2)
203   #endif
204   ```
206 We like [this style guide][guide].
208 [guide]: https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md
210 GitHub Ticket Conventions
211 -------------------
213 Each major `Cabal`/`cabal-install` release (e.g. 3.4, 3.6, etc.) has a
214 corresponding GitHub Project and milestone. A ticket is included in a release's
215 project if the release managers are tenatively planning on including a fix for
216 the ticket in the release, i.e. if they are actively seeking someone to work on
217 the ticket.
219 By contrast, a ticket is milestoned to a given release if we are open to
220 accepting a fix in that release, i.e. we would very much appreciate someone
221 working on it, but are not committing to actively sourcing someone to work on
224 GitHub Pull Request Conventions
225 -------------------
227 Every (non-backport) pull request has to go through a review and get 2
228 approvals. After this is done, the author of the pull request is expected to add
229 any final touches they deem important and put the `merge me` label on the pull
230 request. If the author lacks permissions to apply labels, they are welcome to
231 explicitly signal the merge intent on the discussion thread of the pull request,
232 at which point others (e.g., reviewers) apply the label. Merge buttons are
233 reserved for exceptional situations, e.g., CI fixes being iterated on or
234 backports/patches that need to be expedited for a release.
236 Currently there is a 2 day buffer for potential extra feedback between the last
237 update of a pull request (e.g. a commit, a rebase, an addition of the `merge me`
238 label) and the moment the Mergify bot picks up the pull request for a merge.
240 If your pull request consists of several commits, consider using `squash+merge
241 me` instead of `merge me`: the Mergify bot will squash all the commits into one
242 and concatenate the commit messages of the commits before merging.
244 Changelog
245 ---------
247 When opening a pull request, you should write a changelog entry
248 (or more in case of multiple independent changes).
249 This is done by adding files in the `changelog.d` directory.
251 The files follow a simple key-value format similar to the one for .cabal files.
253 Here's an exhaustive example:
255 ```cabal
256 synopsis: Add feature xyz
257 packages: cabal-install
258 prs: #0000
259 issues: #0000 #0000
260 significance: significant
262 description: {
264 - Detail number 1
265 - Detail number 2
270 Only the `synopsis` field is actually required, but you should also set the others where applicable.
272 | Field          | Description                                                                                                        |
273 | -----          | -----------                                                                                                        |
274 | `synopsis`     | Brief description of the change. Often just the pr title.                                                          |
275 | `description`  | Longer description, with a list of sub-changes. Not needed for small/atomic changes.                               |
276 | `packages`     | Packages affected by the change (`cabal-install`, `Cabal`...). Omit if it's an overarching or non-package change.  |
277 | `prs`          | Space-separated hash-prefixed pull request numbers containing the change (usually just one).                       |
278 | `issues`       | Space-separated hash-prefixed issue numbers that the change fixes/closes/affects.                                  |
279 | `significance` | Set to `significant` if the change is significant, that is if it warrants being put near the top of the changelog. |
281 You can find a large number of real-world examples of changelog files
282 [here](https://github.com/haskell/cabal/tree/bc83de27569fda22dbe1e10be1a921bebf4d3430/changelog.d).
284 At release time, the entries will be merged with
285 [this tool](https://github.com/phadej/changelog-d).
287 In addition, if you're changing the .cabal file format specification you should
288 add an entry in `doc/file-format-changelog.rst`.
290 Communicating
291 -------------
293 There are a few main venues of communication:
295 * Most developers subscribe to receive messages from [all issues](https://github.com/haskell/cabal/issues); issues can be used to [open discussion](https://github.com/haskell/cabal/issues?q=is%3Aissue+is%3Aopen+custom+label%3A%22type%3A+discussion%22).  If you know someone who should hear about a message, CC them explicitly using the @username GitHub syntax.
297 * For more organizational concerns, the [mailing
298   list](http://www.haskell.org/mailman/listinfo/cabal-devel) is used.
300 * Many developers idle on `#hackage` on [`irc.libera.chat`](https://libera.chat). The `#ghc` channel is also a decently good bet.
301   * You can join the channel using a web client, even anonymously: https://web.libera.chat/#hackage
302   * Alternatively you can join it using [matrix](https://matrix.org/): https://matrix.to/#/#hackage:libera.chat
304 Releases
305 --------
307 Notes for how to make a release are at the
308 wiki page ["Making a release"](https://github.com/haskell/cabal/wiki/Making-a-release).
309 Currently, [@emilypi](https://github.com/emilypi), [@fgaz](https://github.com/fgaz) and [@Mikolaj](https://github.com/Mikolaj) have access to
310 `haskell.org/cabal`, and [@Mikolaj](https://github.com/Mikolaj) is the point of contact for getting
311 permissions.
313 API Documentation
314 -----------------
316 Auto-generated API documentation for the `master` branch of Cabal is automatically uploaded here: http://haskell.github.io/cabal-website/doc/html/Cabal/.
318 ## Issue triage [![Open Source Helpers](https://www.codetriage.com/haskell/cabal/badges/users.svg)](https://www.codetriage.com/haskell/cabal)
320 You can contribute by triaging issues which may include reproducing bug reports or asking for vital information, such as version numbers or reproduction instructions. If you would like to start triaging issues, one easy way to get started is to [subscribe to cabal on CodeTriage](https://www.codetriage.com/haskell/cabal).