10.2 KB
Newer Older
1 2 3 4 5 6
# Contributing to Cabal

Building Cabal for hacking

The current recommended way of developing Cabal is to use the
Jan Hrček's avatar
Jan Hrček committed
`v2-build` feature which [shipped in cabal-install-1.24](  Assuming
8 9 10 11
that you have a sufficiently recent cabal-install (see above),
it is sufficient to run:

Jan Hrček's avatar
Jan Hrček committed
cabal v2-build cabal
13 14 15 16 17 18 19 20 21 22 23

To build a local, development copy of cabal-install.  The location
of your build products will vary depending on which version of
cabal-install you use to build; see the documentation section
[Where are my build products?](
to find the binary (or just run `find -type f -executable -name cabal`).

Here are some other useful variations on the commands:

Jan Hrček's avatar
Jan Hrček committed
24 25 26
cabal v2-build Cabal # build library only
cabal v2-build Cabal:unit-tests # build Cabal's unit test suite
cabal v2-build cabal-tests # etc...
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47

**Dogfooding HEAD.**
Many of the core developers of Cabal dogfood `cabal-install` HEAD
when doing development on Cabal.  This helps us identify bugs
which were missed by the test suite and easily experiment with new

The recommended workflow in this case is slightly different: you will
maintain two Cabal source trees: your production tree (built with a
released version of Cabal) which always tracks `master` and which you
update only when you want to move to a new version of Cabal to dogfood,
and your development tree (built with your production Cabal) that you
actually do development on.

In more detail, suppose you have checkouts of Cabal at `~/cabal-prod`
and `~/cabal-dev`, and you have a release copy of cabal installed at
`/opt/cabal/2.4/bin/cabal`.  First, build your production tree:

cd ~/cabal-prod
Jan Hrček's avatar
Jan Hrček committed
/opt/cabal/2.4/bin/cabal v2-build cabal
49 50 51 52 53 54 55 56

This will produce a cabal binary (see also: [Where are my build products?](
).  Add this binary to your PATH,
and then use it to build your development copy:

cd ~/cabal-dev
Jan Hrček's avatar
Jan Hrček committed
cabal v2-build cabal
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114

Running tests

**Using Travis and AppVeyor.**
If you are not in a hurry, the most convenient way to run tests on Cabal
is to make a branch on GitHub and then open a pull request; our
continuous integration service on Travis and AppVeyor will build and
test your code.  Title your PR with WIP so we know that it does not need
code review.

Some tips for using Travis effectively:

* Travis builds take a long time.  Use them when you are pretty
  sure everything is OK; otherwise, try to run relevant tests locally

* Watch over your jobs on the [Travis website](
  If you know a build of yours is going to fail (because one job has
  already failed), be nice to others and cancel the rest of the jobs,
  so that other commits on the build queue can be processed.

**How to debug a failing CI test.**
One of the annoying things about running tests on CI is when they
fail, there is often no easy way to further troubleshoot the broken
build.  Here are some guidelines for debugging continuous integration

1. Can you tell what the problem is by looking at the logs?  The
   `cabal-testsuite` tests run with `-v` logging by default, which
   is dumped to the log upon failure; you may be able to figure out
   what the problem is directly this way.

2. Can you reproduce the problem by running the test locally?
   See the next section for how to run the various test suites
   on your local machine.

3. Is the test failing only for a specific version of GHC, or
   a specific operating system?  If so, try reproducing the
   problem on the specific configuration.

4. Is the test failing on a Travis per-GHC build
   ([for example](
   In this case, if you click on "Branch", you can get access to
   the precise binaries that were built by Travis that are being
   tested.  If you have an Ubuntu system, you can download
   the binaries and run them directly.

5. Is the test failing on AppVeyor?  Consider logging in via
   Remote Desktop to the build VM:

If none of these let you reproduce, there might be some race condition
or continuous integration breakage; please file a bug.

**Running tests locally.**
Jan Hrček's avatar
Jan Hrček committed
To run tests locally with `v2-build`, you will need to know the
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
name of the test suite you want.  Cabal and cabal-install have
several.  Also, you'll want to read [Where are my build products?](

The most important test suite is `cabal-testsuite`: most user-visible
changes to Cabal should come with a test in this framework.  See
[cabal-testsuite/](cabal-testsuite/ for more
information about how to run tests and write new ones.  Quick
start: use `cabal-tests` to run `Cabal` tests, and `cabal-tests
--with-cabal=/path/to/cabal` to run `cabal-install` tests
(don't forget `--with-cabal`! Your cabal-install tests won't
run without it).

There are also other test suites:

* `Cabal:unit-tests` are small, quick-running unit tests
  on small pieces of functionality in Cabal.  If you are working
  on some utility functions in the Cabal library you should run this
  test suite.

* `cabal-install:unit-tests` are small, quick-running unit tests on
  small pieces of functionality in cabal-install.  If you are working
  on some utility functions in cabal-install you should run this test

* `cabal-install:solver-quickcheck` are QuickCheck tests on
  cabal-install's dependency solver.  If you are working
  on the solver you should run this test suite.

* `cabal-install:integration-tests2` are integration tests on some
  top-level API functions inside the `cabal-install` source code.

For these test executables, `-p` which applies a regex filter to the test


* Spaces, not tabs.

* Try to follow style conventions of a file you are modifying, and
  avoid gratuitous reformatting (it makes merges harder!)

* Format your commit messages [in the standard way](

* A lot of Cabal does not have top-level comments.  We are trying to
  fix this.  If you add new top-level definitions, please Haddock them;
  and if you spend some time understanding what a function does, help
  us out and add a comment.  We'll try to remind you during code review.

* If you do something tricky or non-obvious, add a comment.

* If your commit only touches comments, you can use `[ci skip]`
  anywhere in the body of the commit message to avoid needlessly
  triggering the build bots.

* For local imports (Cabal module importing Cabal module), import lists
  are NOT required (although you may use them at your discretion.)  For
  third-party and standard library imports, please use either qualified imports
  or explicit import lists.

* You can use basically any GHC extension supported by a GHC in our
  support window, except Template Haskell, which would cause
  bootstrapping problems in the GHC compilation process.

* Our GHC support window is five years for the Cabal library and three
  years for cabal-install: that is, the Cabal library must be
  buildable out-of-the-box with the dependencies that shipped with GHC
  for at least five years.  The Travis CI checks this, so most
  developers submit a PR to see if their code works on all these
  versions of GHC.  `cabal-install` must also be buildable on all
  supported GHCs, although it does not have to be buildable
  out-of-the-box. Instead, the `cabal-install/` script
  must be able to download and install all of the dependencies (this
  is also checked by CI). Also, self-upgrade to the latest version
  (i.e. `cabal install cabal-install`) must work with all versions of
  `cabal-install` released during the last three years.

* `Cabal` has its own Prelude, in `Distribution.Compat.Prelude`,
  that provides a compatibility layer and exports some commonly
  used additional functions. Use it in all new modules.

* As far as possible, please do not use CPP. If you must use it,
  try to put it in a `Compat` module, and minimize the amount of code
  that is enclosed by CPP.  For example, prefer:
  f :: Int -> Int
  #ifdef mingw32_HOST_OS
  f = (+1)
  f = (+2)

  #ifdef mingw32_HOST_OS
  f :: Int -> Int
  f = (+1)
  f :: Int -> Int
  f = (+2)

We like [this style guide][guide].



There are a few main venues of communication:

* Most developers subscribe to receive messages from [all issues](; issues can be used to [open discussion](  If you know someone who should hear about a message, CC them explicitly using the @username GitHub syntax.

* For more organizational concerns, the [mailing
  list]( is used.

* Many developers idle on `#hackage` on `` ([archives](  `#ghc` ([archives]( is also a decently good bet.


Notes for how to make a release are at the
wiki page ["Making a release"](
Currently, @23Skidoo, @rthomas, @tibbe and @dcoutts have access to
``, and @davean is the point of contact for getting

API Documentation

Auto-generated API documentation for the `master` branch of Cabal is automatically uploaded here:
249 250 251 252

## Issue triage [![Open Source Helpers](](

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](