- Development with
ghcid - Running unit tests
- Checking dependent packages
- Benchmarks
- Releasing a new version
This document tries to describe everything you need to know to develop/maintain Megaparsec.
We use nix for development. First enter the Nix shell:
$ nix developInside the shell you can:
-
Build the
megaparsecandmegaparsec-testspackages withcabal build all. -
Run tests from the
megaparsec-testspackage withcabal test all. -
Run
ghcidfor interactive feedback as you edit withghcid --command="cabal repl megaparsec"orghcid --command="cabal repl megaparsec-tests --enable-tests"depending on the package you're editing.
The tests in megaparsec-tests are usually not enough to gain confidence in
non-trivial changes. It is wise to use tests from other packages:
$ nix build .#all_base --no-linkThe base group includes building and testing the following packages:
megaparsechspec-megaparsecmegaparsec-testsparser-combinators-tests
It is worth noting that individual derivations from base can be built like
this:
$ nix build .#base/parser-combinators-tests --no-linkTo find out how your changes affect a selected set of dependent packages do:
$ nix build .#all_deps --no-linkThe “selected set” includes packages that are known to be high-quality, well-tested, and non-trivial, so they are good targets for this sort of testing. You can also try to build and test a particular package like this:
$ nix build .#deps/mmark --no-linkWhen you introduce a breaking change, some packages may stop compiling. Usually it's easy enough to create a patch and make it compile with the current dev version of Megaparsec. To do so, follow these steps:
-
Start by cloning the repo of the failing package.
-
Checkout commit that corresponds to the version our current
nixpkgspackages use. -
Attempt to compile the package with current dev version of Megaparsec to reproduce the build errors. Often, if the broken package uses stack you can just add the path to the updated Megaparsec directory to the
extra-depssection. -
Perform whatever changes that are necessary to make the package work.
-
Use
git diff > my-package.patchorgit diff --cached > my-package.patchto create the patch file. The first command will output unstaged changes, while the second command will write only staged changes. -
Adjust
default.nixto apply the patch. You want to edit thedepsattribute set. For example:# Dependent packages of interest: deps = { # ... idris = patch haskellPackages.idris ./nix/patches/idris.patch; };
To build all benchmarks run:
$ nix build .#all_benchesThis will create several symlinks in result. It is also possible to build
benchmarks for just a specific package:
$ nix build .#benches/megaparsec # builds megaparsec's microbenchmarkscd to the bench sub-directory and run benchmarks from there because some
benchmarks need data to run on and the paths are relative, so it'll fail if
run from the root of Megaparsec's repo.
To release a new version of Megaparsec, follow these steps:
-
Bump version for both
megaparsecandmegaparsec-tests. In themegaparsec.cabalfile update the version of the package. In themegaparsec-tests.cabalfile update the version of the package (we keep it in sync with version ofmegaparsec) as well as the versions ofmegaparsecit depends on. -
Create git tag and push it to the repo.
-
Generate distribution tarballs by running:
$ nix build .#all_distThis will create
resultwith two symlinks to directories containing the tarballs. Typically they are calledresult/megaparsec-source-*andresult/megaparsec-tests-source-*. -
To upload the tarballs to Hackage, execute the following:
$ cabal upload --publish result/megaparsec-source-*/megaparsec-*.tar.gz $ cabal upload --publish result/megaparsec-tests-source-*/megaparsec-tests-*.tar.gz