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