cabal-validate: Hide build plan unless `--verbose`
[cabal.git] / CONTRIBUTING.md
blob81ea71849dab7f36732f711a01f670e99cdc60ee
1 # Contributing to Cabal
3 ## Building Cabal for hacking
5 If you use the `cabal` executable from the latest version of the
6 [cabal-install](https://hackage.haskell.org/package/cabal-install) package
7 published on Hackage, it is sufficient to run:
9 ```
10 $ cabal build cabal
11 ```
13 If you have trouble building the testsuite for this initial build, try building
14 with the release project that excludes this testsuite:
16 ```
17 $ cabal build cabal --project-file=cabal.release.project
18 ```
20 > [!NOTE]
21 > The default `cabal.project` is picked up implicitly as if the
22 > `--project-file=cabal.project` explicit option had been given.
24 For developing, we recommend using the locally built version of `cabal`, the
25 executable, if only because one of the released versions available may be
26 lacking a fix. This can be installed:
28 ```
29 $ cabal install cabal-install:exe:cabal --overwrite-policy=always
30 ```
32 It can be run without first installing it with `cabal run cabal --` followed by
33 its own arguments, as shown here for `build --help`:
35 ```
36 $ cabal run cabal -- build --help
37 ```
39 > [!NOTE]
40 > If you're using Nix, you might find it convenient to work within a shell that has the following `Cabal` development dependencies:
41 > ```bash
42 > $ nix-shell -p cabal-install ghc ghcid pkg-config zlib.dev # incomplete
43 > ```
44 > One dependency that we left out in the above command is `haskellPackages.fourmolu_0_12_0_0` which would need to be installed manually.
45 > A Nix flake developer shell with these dependencies is also available, supported solely by the community, through the command `nix develop github:yvan-sraka/cabal.nix`.
47 The location of your build products will vary depending on which version of
48 cabal-install you use to build; see the documentation section
49 [Where are my build products?](http://cabal.readthedocs.io/en/latest/nix-local-build.html#where-are-my-build-products)
50 to find the binary (or just run `find -type f -executable -name cabal`).
52 Here are some other useful variations on the commands:
54 ```
55 $ cabal build Cabal                  # build library only
56 $ cabal build Cabal-tests:unit-tests # build Cabal's unit test suite
57 $ cabal build cabal-tests            # etc...
58 ```
60 ## Running tests
62 There are two ways to run tests: in CI with GitHub actions and locally with
63 `./validate.sh`.
65 ### Using GitHub Actions.
67 If you are not in a hurry, the most convenient way to run tests on Cabal
68 is to make a branch on GitHub and then open a pull request; our
69 continuous integration service on GitHub Actions builds and
70 tests your code.  Title your PR with WIP so we know that it does not need
71 code review.
73 Some tips for using GitHub Actions effectively:
75 * GitHub Actions builds take a long time.  Use them when you are pretty
76   sure everything is OK; otherwise, try to run relevant tests locally
77   first.
79 * If you are only changing documentation in the `docs/` subdirectory,
80   or if you change `README.md` or `CONTRIBUTING.md`, then we only run a
81   small subset of the CI jobs. You can therefore open small PRs with
82   improvements to the documentation without feeling guilty about wasted
83   resources!
85 * Watch over your jobs on the [GitHub Actions website](http://github.org/haskell/cabal/actions).
86   If you know a build of yours is going to fail (because one job has
87   already failed), be nice to others and cancel the rest of the jobs,
88   so that other commits on the build queue can be processed.
90 ### How to debug a failing CI test.
92 One of the annoying things about running tests on CI is when they
93 fail, there is often no easy way to further troubleshoot the broken
94 build.  Here are some guidelines for debugging continuous integration
95 failures:
97 1. Can you tell what the problem is by looking at the logs?  The
98    `cabal-testsuite` tests run with `-v` logging by default, which
99    is dumped to the log upon failure; you may be able to figure out
100    what the problem is directly this way.
102 2. Can you reproduce the problem by running the test locally?
103    See the next section for how to run the various test suites
104    on your local machine.
106 3. Is the test failing only for a specific version of GHC, or
107    a specific operating system?  If so, try reproducing the
108    problem on the specific configuration.
110 4. Is the test failing on a GitHub Actions per-GHC build.
111    In this case, if you click on "Branch", you can get access to
112    the precise binaries that were built by GitHub Actions that are being
113    tested.  If you have an Ubuntu system, you can download
114    the binaries and run them directly.
116 If none of these let you reproduce, there might be some race condition
117 or continuous integration breakage; please file a bug.
119 ### Running tests locally.
121 The [`./validate.sh`](./validate.sh) script runs all the test suites. It takes
122 various options to restrict the test suites it runs; use `--help` to list them.
124 To run tests locally with `cabal`, you will need to know the
125 name of the test suite you want.  Cabal and cabal-install have
126 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)
128 The most important test suite is `cabal-testsuite`: most user-visible
129 changes to Cabal should come with a test in this framework.  See
130 [cabal-testsuite/README.md](cabal-testsuite/README.md) for more
131 information about how to run tests and write new ones.  Quick
132 start: use `cabal-tests` to run `Cabal` tests, and `cabal-tests
133 --with-cabal=/path/to/cabal` to run `cabal-install` tests
134 (don't forget `--with-cabal`! Your cabal-install tests won't
135 run without it).
137 There are also other test suites:
139 * `Cabal-tests:unit-tests` are small, quick-running unit tests
140   on small pieces of functionality in Cabal.  If you are working
141   on some utility functions in the Cabal library you should run this
142   test suite.
144 * `cabal-install:unit-tests` are small, quick-running unit tests on
145   small pieces of functionality in cabal-install.  If you are working
146   on some utility functions in cabal-install you should run this test
147   suite.
149 * `cabal-install:long-tests` are QuickCheck tests on
150   cabal-install's dependency solver, VCS, and file monitoring code.
151   If you are working on the solver you should run this test suite.
153 * `cabal-install:integration-tests2` are integration tests on some
154   top-level API functions inside the `cabal-install` source code.
156 For these test executables, `-p` which applies a regex filter to the test
157 names. When running `cabal-install` test suites, one need only use `cabal test` or
158 `cabal run <test-target>` in order to test locally.
160 ## Running other checks locally
162 Various other checks done by CI can be run locally to make sure your code doesn't
163 fail annoyingly once you push it. `make checks` will do these checks. The list of
164 checks is expected to grow over time, to make it easier to avoid CI turnaround on
165 simple problems.
167 ## QA Notes
169 Manual Quality Assurance (QA) is performed to ensure that the changes impacting
170 the command-line interface, whether adding or modifying a behaviour,
171 are tested before being released. This allows us to catch UX regressions and put
172 a human perspective into testing.
174 Contributions that touch `cabal-install` are expected to include notes for the QA team.
175 They are a description of an expected result upon calling `cabal-install` with certain parameters,
176 and should be written in the body of the ticket or PR under their own heading, like this:
178 ```markdown
179 ## QA Notes
181 Calling `cabal haddock-project` should produce documentation for the whole
182 cabal project with the following defaults enabled:
183 * Documentation lives in ./haddocks
184 * The file `./haddocks/index.html` should exist
187 Manual QA is not expected to find every possible bug, but to really challenge the assumptions of the contributor, and to verify that their own testing
188 of their patch is not influenced by their setup or implicit knowledge of the system.
191 ## Code Style
193 We use automated formatting, checked in the CI process, to enforce a unified
194 style across the code bases and include these makefile targets to help with
195 formatting:
197 * `make style` - Format the `Cabal`, `Cabal-syntax` and `cabal-install` directories.
198 * `make style-modified` - Format files modified in the current tree.
199 * `make style-commit COMMIT=<ref>` - Format files modified between HEAD and the given reference.
201 > [!NOTE]
202 > We use `fourmolu-0.12.0.0` for formatting. If installing it with `cabal
203 > install`, please make sure to use a version of `GHC >= 9.2.1 && < 9.8`.
204 > Its requirement of `GHC2021` sets the lower bound, and its reliance on
205 > `ghc-lib-parser` sets the upper bound on GHC versions. A command for
206 > installing it this way is:
208 > ```
209 > $ cabal install fourmolu-0.12.0.0 --overwrite-policy=always --ignore-project
210 > ```
212 > [!Tip]
213 > If you have multiple versions of GHC installed with `ghcup`, a series-specific
214 > GHC can be used by adding an option of `--with-compiler=ghc-x.y` (for the
215 > latest installed `x.y.z` version in the `x.y` series) or an option of
216 > `--with-compiler=ghc-x.y.z` to the above install command.
218 > ```
219 > $ ghc --numeric-version
220 > 9.10.1
222 > $ ghc-9.6 --numeric-version
223 > 9.6.6
225 > $ ghc-9.4.8 --numeric-version
226 > 9.4.8
227 > ```
229 > If not using the `--with-compiler` option then the system `ghc` version should
230 > be one in the `ghc-9.2`, `ghc-9.4` or `ghc-9.6` series when installing
231 > `fourmolu`.
233 > [!WARNING]
234 > If you have need of another `fourmolu` version for other work and want to
235 > switch between versions then your options are reinstalling or using a nix shell
236 > or something similar. It is not yet possible to specify development
237 > environment tools within a package with different constraints on dependencies,
238 > see [issue-9230][issue-9230].
240 [issue-9230]: https://github.com/haskell/cabal/issues/9230
242 ## Whitespace Conventions
244 We use automated whitespace convention checking. Violations can be fixed by
245 running [fix-whitespace](https://hackage.haskell.org/package/fix-whitespace). If
246 you push a fix of a whitespace violation, please do so in a _separate commit_. For convenience,
247 `make whitespace` will show violations and `make fix-whitespace` will fix them, if the
248 `fix-whitespace` utility is installed.
250 ## Other Conventions
252 * Format your commit messages [in the standard way](https://chris.beams.io/posts/git-commit/#seven-rules).
254 * A lot of Cabal does not have top-level comments.  We are trying to
255   fix this.  If you add new top-level definitions, please Haddock them;
256   and if you spend some time understanding what a function does, help
257   us out and add a comment.  We'll try to remind you during code review.
259 * If you do something tricky or non-obvious, add a comment.
261 * For local imports (Cabal module importing Cabal module), import lists
262   are NOT required (although you may use them at your discretion.)  For
263   third-party and standard library imports, please use either qualified imports
264   or explicit import lists.
266 * You can use basically any GHC extension supported by a GHC in our
267   support window, except Template Haskell, which would cause
268   bootstrapping problems in the GHC compilation process.
270 * Our GHC support window is five years for the Cabal library and three
271   years for cabal-install: that is, the Cabal library must be
272   buildable out-of-the-box with the dependencies that shipped with GHC
273   for at least five years.  GitHub Actions checks this, so most
274   developers submit a PR to see if their code works on all these
275   versions of GHC.  `cabal-install` must also be buildable on all
276   supported GHCs, although it does not have to be buildable
277   out-of-the-box. Instead, the `cabal-install/bootstrap.sh` script
278   must be able to download and install all of the dependencies (this
279   is also checked by CI). Also, self-upgrade to the latest version
280   (i.e. `cabal install cabal-install`) must work with all versions of
281   `cabal-install` released during the last three years.
283 * `Cabal` has its own Prelude, in `Distribution.Compat.Prelude`,
284   that provides a compatibility layer and exports some commonly
285   used additional functions. Use it in all new modules.
287 * As far as possible, please do not use CPP. If you must use it,
288   try to put it in a `Compat` module, and minimize the amount of code
289   that is enclosed by CPP.  For example, prefer:
290   ```
291   f :: Int -> Int
292   #ifdef mingw32_HOST_OS
293   f = (+1)
294   #else
295   f = (+2)
296   #endif
297   ```
299   over:
300   ```
301   #ifdef mingw32_HOST_OS
302   f :: Int -> Int
303   f = (+1)
304   #else
305   f :: Int -> Int
306   f = (+2)
307   #endif
308   ```
310 ## GitHub Ticket Conventions
312 Each major `Cabal`/`cabal-install` release (e.g. 3.4, 3.6, etc.) has a
313 corresponding GitHub Project and milestone. A ticket is included in a release's
314 project if the release managers are tentatively planning on including a fix for
315 the ticket in the release, i.e. if they are actively seeking someone to work on
316 the ticket.
318 By contrast, a ticket is milestoned to a given release if we are open to
319 accepting a fix in that release, i.e. we would very much appreciate someone
320 working on it, but are not committing to actively sourcing someone to work on
323 ## GitHub Pull Request Conventions
325 Every (non-backport) pull request has to go through a review and get 2
326 approvals. After this is done, the author of the pull request is expected to add
327 any final touches they deem important and put the `merge me` label on the pull
328 request. If the author lacks permissions to apply labels, they are welcome to
329 explicitly signal the merge intent on the discussion thread of the pull request,
330 at which point others (e.g., reviewers) apply the label. Merge buttons are
331 reserved for exceptional situations, e.g., CI fixes being iterated on or
332 backports/patches that need to be expedited for a release.
334 Currently there is a 2 day buffer for potential extra feedback between the last
335 update of a pull request (e.g. a commit, a rebase, an addition of the `merge me`
336 label) and the moment the Mergify bot picks up the pull request for a merge.
338 If your pull request consists of several commits, consider using `squash+merge
339 me` instead of `merge me`: the Mergify bot will squash all the commits into one
340 and concatenate the commit messages of the commits before merging.
342 There is also a `merge+no rebase` label. Use this very sparingly, as not rebasing
343 severely complicates Git history. It is intended for special circumstances, as when
344 the PR branch cannot or should not be modified. If you have any questions about it,
345 please ask us.
347 ### Pull Requests & Issues
349 A pull request *fixes* a problem that is *described* in an issue. Make sure to
350 file an issue before opening a pull request. In the issue you can illustrate
351 your proposed design, UX considerations, tradeoffs etc. and work them out with
352 other contributors. The PR itself is for implementation.
354 If a PR becomes out of sync with its issue, go back to the issue, update
355 it, and continue the conversation there. Telltale signs of Issue/PR diverging
356 are, for example: the PR growing bigger in scope; lengthy discussions
357 about things that are *not* implementation choices; a change in design.
359 If your PR is trivial you can omit this process (but explain in the PR why you
360 think it does not warrant an issue). Feel free to open a new issue (or new
361 issues) when appropriate.
364 ## Changelog
366 Anything that changes `cabal-install:exe:cabal` or changes exports from library
367 modules or changes behaviour of functions exported from packages published to
368 hackage is a <a id="user-visible-change">user-visible change</a>. Raising the
369 lower bound on `base` is most definitely a user-visible change because it
370 excludes versions of GHC from being able to build these packages.
372 When opening a pull request with a user-visible change, you should write one
373 changelog entry (or more in case of multiple independent changes) — the
374 information will end up in our release notes.
376 Changelogs for the next release are stored in the `changelog.d` directory.
377 The files follow a simple key-value format similar to the one for `.cabal` files.
378 Free-form text fields (`synopsis` and `description`) allow Markdown markup — please,
379 use markup to make our release notes more readable.
381 Here's an example:
383 ```cabal
384 synopsis: Add feature xyz
385 packages: cabal-install
386 prs: #0000
387 issues: #0000 #0000
388 significance: significant
390 description: {
392 - Detail number 1
393 - Detail number 2
398 Changelogs may also be written in "markdown-frontmatter" format. This is useful if your
399 description contains braces, which must be escaped with backslashes in `.cabal` file
400 format. The front matter is in YAML syntax, not `.cabal` file syntax, and the file
401 _must_ begin with a line containing only hyphens.
403 ```markdown
405 synopsis: Add feature xyz
406 packages: [cabal-install]
407 prs: 0000
408 issues: [0000, 0000]
409 significance: significant
412 - Detail number 1
413 - Detail number 2
416 The package list must be enclosed in square brackets and comma-separated, but this
417 isn't needed for `prs` or `issues`; those are free-form and any YAML syntax will
418 be accepted. Note that the number signs on PR and issue numbers are required in
419 `.cabal` file syntax, but won't work in markdown-frontmatter syntax because they
420 signify comments in YAML.
422 Only the `synopsis` and `prs` fields are required, but you should also set the others where applicable.
424 | Field          | Description                                                                                                        |
425 | -----          | -----------                                                                                                        |
426 | `synopsis`     | Brief description of the change. Often just the pr title.                                                          |
427 | `description`  | Longer description, with a list of sub-changes. Not needed for small/atomic changes.                               |
428 | `packages`     | Packages affected by the change (`cabal-install`, `Cabal`...). Omit if it's a non-package change.                  |
429 | `prs`          | Space-separated hash-prefixed pull request numbers containing the change (usually just one).                       |
430 | `issues`       | Space-separated hash-prefixed issue numbers that the change fixes/closes/affects.                                  |
431 | `significance` | Set to `significant` if the change is significant, that is if it warrants being put near the top of the changelog. |
433 You can find a large number of real-world examples of changelog files
434 [here](https://github.com/haskell/cabal/tree/bc83de27569fda22dbe1e10be1a921bebf4d3430/changelog.d).
436 At release time, the entries will be merged with
437 [this tool](https://github.com/fgaz/changelog-d).
439 In addition, if you're changing the `.cabal` file format specification you should
440 add an entry in `doc/file-format-changelog.rst`.
442 ### Is my change `significant`?
444 Use your best judgement and if unsure ask other maintainers. If your PR fixes
445 a specific ticket, how busy was the discussion there? A new command or option
446 most likely warrants a `significance: significant` tag, same with command
447 line changes that disrupts the workflow of many users or an API change
448 that requires substantial time to integrate in a program.
450 Put yourself in the shoes of the user: would you appreciate seeing this
451 change highlighted in the announcement post or release notes overview? If
452 so, add `significance: significant`.
454 ## Communicating
456 There are a few main venues of communication:
458 * 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.
460 * For more organizational concerns, the [mailing
461   list](http://www.haskell.org/mailman/listinfo/cabal-devel) is used.
463 * Many developers idle on `#hackage` on [`irc.libera.chat`](https://libera.chat). The `#ghc` channel is also a decently good bet.
464   * You can join the channel using a web client, even anonymously: https://web.libera.chat/#hackage
465   * Alternatively you can join it using [matrix](https://matrix.org/): https://matrix.to/#/#hackage:matrix.org
467 ## Releases
469 Notes for how to make a release are at the
470 wiki page ["Making a release"](https://github.com/haskell/cabal/wiki/Making-a-release).
471 Currently, [@emilypi](https://github.com/emilypi), [@fgaz](https://github.com/fgaz) and [@Mikolaj](https://github.com/Mikolaj) have access to
472 `haskell.org/cabal`, and [@Mikolaj](https://github.com/Mikolaj) is the point of contact for getting
473 permissions.
475 ## Preview Releases
477 We make preview releases available to facilitate testing of development builds.
479 Artifacts can be found on the [`cabal-head` release page](https://github.com/haskell/cabal/releases/tag/cabal-head).
480 The Validate CI pipeline generates tarballs with a `cabal` executable. The executable gets uploaded to this release by the pipelines that run on `master`.
482 We currently make available builds for:
483   - Linux, dynamically linked (requiring `zlib`, `gmp`, `glibc`)
484   - Linux, statically linked
485   - MacOS
486   - Windows
488 The statically linked Linux executables are built using Alpine.
489 To reproduce these locally, set up an Alpine build environment using GHCup,
490 and then build by calling `cabal build cabal-install --enable-executable-static`.
493 ## API Documentation
495 Auto-generated API documentation for the `master` branch of Cabal is automatically uploaded here: http://haskell.github.io/cabal-website/doc/html/Cabal/.
497 ## Issue triage [![Open Source Helpers](https://www.codetriage.com/haskell/cabal/badges/users.svg)](https://www.codetriage.com/haskell/cabal)
499 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).
501 ## Hackage Revisions
503 We are reactive rather than proactive with revising bounds on our dependencies
504 for code already released on Hackage. If you would benefit from a version bump,
505 please, open a ticket and get familiar with
506 [our revision policy](https://github.com/haskell/cabal/issues/9531#issuecomment-1866930240).
508 The burden of proof that the bump is harmless remains with you, but we have a CI
509 setup to show that our main pipeline ("Validate") is fine with the bump. To use
510 it, someone with enough permissions needs to go on the
511 [Validate workflow page](https://github.com/haskell/cabal/actions/workflows/validate.yml)
512 and dispatch it manually by clicking "Run workflow".
514 Running workflow manually as discussed above allows you to supply two inputs:
516 > allow-newer line
517 > constraints line
519 Going via an example, imagine that Cabal only allows `tar` or version less then
520 or equal to 0.6, and you want to bump it to 0.6. Then, to show that Validate
521 succeeds with `tar` 0.6, you should input
523 - `tar` to the "allow-newer line"
524 - `tar ==0.6` to the "constraints line"
526 Hopefully, running the Validate pipeline with these inputs succeeds and you
527 supply the link to the run in the ticket about bumping the bound and making a revision.
529 If interested in technical details, refer to the parts of `validate.yml` that
530 mention `hackage-revisions`.