docs: cabal.project in parent directories
[cabal.git] / CONTRIBUTING.md
blob0982050e9a49d335d5cb0d2ab50f30e9251e20ff
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: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: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 Conventions
117 -----------
119 * Spaces, not tabs.
121 * Try to follow style conventions of a file you are modifying, and
122   avoid gratuitous reformatting (it makes merges harder!)
124 * Format your commit messages [in the standard way](https://chris.beams.io/posts/git-commit/#seven-rules).
126 * A lot of Cabal does not have top-level comments.  We are trying to
127   fix this.  If you add new top-level definitions, please Haddock them;
128   and if you spend some time understanding what a function does, help
129   us out and add a comment.  We'll try to remind you during code review.
131 * If you do something tricky or non-obvious, add a comment.
133 * For local imports (Cabal module importing Cabal module), import lists
134   are NOT required (although you may use them at your discretion.)  For
135   third-party and standard library imports, please use either qualified imports
136   or explicit import lists.
138 * You can use basically any GHC extension supported by a GHC in our
139   support window, except Template Haskell, which would cause
140   bootstrapping problems in the GHC compilation process.
142 * Our GHC support window is five years for the Cabal library and three
143   years for cabal-install: that is, the Cabal library must be
144   buildable out-of-the-box with the dependencies that shipped with GHC
145   for at least five years.  The Travis CI checks this, so most
146   developers submit a PR to see if their code works on all these
147   versions of GHC.  `cabal-install` must also be buildable on all
148   supported GHCs, although it does not have to be buildable
149   out-of-the-box. Instead, the `cabal-install/bootstrap.sh` script
150   must be able to download and install all of the dependencies (this
151   is also checked by CI). Also, self-upgrade to the latest version
152   (i.e. `cabal install cabal-install`) must work with all versions of
153   `cabal-install` released during the last three years.
155 * `Cabal` has its own Prelude, in `Distribution.Compat.Prelude`,
156   that provides a compatibility layer and exports some commonly
157   used additional functions. Use it in all new modules.
159 * As far as possible, please do not use CPP. If you must use it,
160   try to put it in a `Compat` module, and minimize the amount of code
161   that is enclosed by CPP.  For example, prefer:
162   ```
163   f :: Int -> Int
164   #ifdef mingw32_HOST_OS
165   f = (+1)
166   #else
167   f = (+2)
168   #endif
169   ```
171   over:
172   ```
173   #ifdef mingw32_HOST_OS
174   f :: Int -> Int
175   f = (+1)
176   #else
177   f :: Int -> Int
178   f = (+2)
179   #endif
180   ```
182 We like [this style guide][guide].
184 [guide]: https://github.com/tibbe/haskell-style-guide/blob/master/haskell-style.md
186 Changelog
187 ---------
189 When opening a pull request, you should write a changelog entry
190 (or more in case of multiple independent changes).
191 This is done by adding files in the `changelog.d` directory.
193 The files follow a simple key-value format similar to the one for .cabal files.
195 Here's an exhaustive example:
197 ```cabal
198 synopsis: Add feature xyz
199 packages: cabal-install
200 prs: #0000
201 issues: #0000 #0000
202 significance: significant
204 description: {
206 - Detail number 1
207 - Detail number 2
212 Only the `synopsis` field is actually required, but you should also set the others where applicable.
214 | Field          | Description                                                                                                        |
215 | -----          | -----------                                                                                                        |
216 | `synopsis`     | Brief description of the change. Often just the pr title.                                                          |
217 | `description`  | Longer description, with a list of sub-changes. Not needed for small/atomic changes.                               |
218 | `packages`     | Packages affected by the change (`cabal-install`, `Cabal`...). Omit if it's an overarching or non-package change.  |
219 | `prs`          | Space-separated hash-prefixed pull request numbers containing the change (usually just one).                       |
220 | `issues`       | Space-separated hash-prefixed issue numbers that the change fixes/closes/affects.                                  |
221 | `significance` | Set to `significant` if the change is significant, that is if it warrants being put near the top of the changelog. |
223 You can find a large number of real-world examples of changelog files
224 [here](https://github.com/haskell/cabal/tree/bc83de27569fda22dbe1e10be1a921bebf4d3430/changelog.d).
226 At release time, the entries will be merged with
227 [this tool](https://github.com/phadej/changelog-d).
229 Communicating
230 -------------
232 There are a few main venues of communication:
234 * 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.
236 * For more organizational concerns, the [mailing
237   list](http://www.haskell.org/mailman/listinfo/cabal-devel) is used.
239 * Many developers idle on `#hackage` on [`irc.libera.chat`](https://libera.chat). The `#ghc` channel is also a decently good bet.
240   * You can join the channel using a web client, even anonymously: https://web.libera.chat/#hackage
241   * Alternatively you can join it using [matrix](https://matrix.org/): https://matrix.to/#/#hackage:libera.chat
243 Releases
244 --------
246 Notes for how to make a release are at the
247 wiki page ["Making a release"](https://github.com/haskell/cabal/wiki/Making-a-release).
248 Currently, [@emilypi](https://github.com/emilypi), [@fgaz](https://github.com/fgaz) and [@Mikolaj](https://github.com/Mikolaj) have access to
249 `haskell.org/cabal`, and [@Mikolaj](https://github.com/Mikolaj) is the point of contact for getting
250 permissions.
252 API Documentation
253 -----------------
255 Auto-generated API documentation for the `master` branch of Cabal is automatically uploaded here: http://haskell.github.io/cabal-website/doc/html/Cabal/.
257 ## Issue triage [![Open Source Helpers](https://www.codetriage.com/haskell/cabal/badges/users.svg)](https://www.codetriage.com/haskell/cabal)
259 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).