ghcup-hs/docs/dev.md

121 lines
5.9 KiB
Markdown
Raw Normal View History

2021-10-02 18:21:51 +00:00
# Development
2021-10-06 08:20:08 +00:00
All you wanted to know about GHCup development.
2020-04-12 17:48:26 +00:00
2021-10-05 19:36:50 +00:00
## Module graph
[![Module graph](./modules_small.svg){: .center style="width:900px"}](./modules_wide.svg)
2021-10-06 08:20:08 +00:00
Main functionality is in `GHCup` module. Utility functions are
organised tree-ish in `GHCup.Utils` and `GHCup.Utils.*`.
Anything dealing with ghcup specific directories is in
`GHCup.Utils.Dirs`.
Download information on where to fetch bindists from is in the appropriate
yaml files: `data/metadata/ghcup-<yaml-ver>.yaml`.
2020-04-12 17:48:26 +00:00
## Design decisions
2021-10-04 19:40:48 +00:00
### Using [Excepts](https://hackage.haskell.org/package/haskus-utils-variant-3.0/docs/Haskus-Utils-Variant-Excepts.html) as a beefed up ExceptT
2020-04-12 17:48:26 +00:00
This is an open variant, similar to [plucky](https://hackage.haskell.org/package/plucky) or [oops](https://github.com/i-am-tom/oops) and allows us to combine different error types. Maybe it is too much and it's a little bit [unergonomic](https://github.com/haskus/packages/issues/32) at times. If it really hurts maintenance, it will be removed. It was more of an experiment.
2021-10-04 19:40:48 +00:00
### No use of haskell-TLS
2020-04-12 17:48:26 +00:00
2021-10-06 08:20:08 +00:00
I consider haskell-TLS an interesting experiment, but not a battle-tested and peer-reviewed crypto implementation. There is little to no research about what the intricacies of using haskell for low-level crypto are and how vulnerable such binaries are. Instead, we use either curl the binary or wget. There's also an implementation based on OpenSSL bindings, but it isn't enabled by default, since it would complicate shipping static binaries.
2020-04-12 17:48:26 +00:00
2021-10-04 19:40:48 +00:00
### Optics instead of lens
2020-04-12 17:48:26 +00:00
2021-10-06 08:20:08 +00:00
They're a little safer (less Monoid weirdness with view) and have better error messages. Consider the following with [lens](https://hackage.haskell.org/package/lens):
2020-04-13 13:20:56 +00:00
```
> view (_Just . to (++ "abc")) Nothing
""
```
2021-10-06 08:20:08 +00:00
vs [optics](https://hackage.haskell.org/package/optics):
2020-04-13 13:20:56 +00:00
```
2020-04-13 19:11:00 +00:00
> view (_Just % to (++ "abc")) Nothing
2020-04-13 13:20:56 +00:00
<interactive>:2:1: error:
• An_AffineFold cannot be used as A_Getter
• In the expression: view (_Just % to (++ "abc")) Nothing
In an equation for it: it = view (_Just % to (++ "abc")) Nothing
```
2020-04-12 17:48:26 +00:00
2021-10-06 08:20:08 +00:00
### StrictData on by default
2020-04-12 17:48:26 +00:00
Kazu Yamamoto [explained it in his PR](https://github.com/yesodweb/wai/pull/752#issuecomment-501531386) very well. I like to agree with him. The instances where we need non-strict behavior, we annotate it.
2021-10-06 08:20:08 +00:00
`Strict` is a little more odd as a default, since it depends on how you define your functions as well.
2020-04-28 15:41:08 +00:00
2021-10-06 08:20:08 +00:00
## Code style and formatting
2020-04-28 15:41:08 +00:00
2021-10-06 08:20:08 +00:00
Unfortunately, code formatters are semi-broken on this codebase, due to TH and CPP.
2020-04-28 15:41:08 +00:00
2021-10-06 08:20:08 +00:00
Some light suggestions:
2020-04-28 15:41:08 +00:00
2021-10-06 08:20:08 +00:00
1. mtl-style preferred
2. no overly pointfree style
3. use `where` a lot, so the main function body reads like prose
4. documentation is part of the code
2021-01-02 08:07:41 +00:00
## Common Tasks
2021-10-04 19:40:48 +00:00
### Adding a new GHC version
2021-01-02 08:07:41 +00:00
2021-10-06 08:20:08 +00:00
1. open the latest `data/metadata/ghcup-<yaml-ver>.yaml`
2. find the latest ghc version (in yaml tree e.g. `ghcupDownloads -> GHC -> 8.10.7`)
2021-01-02 08:07:41 +00:00
3. copy-paste it
4. adjust the version, tags, changelog, source url
5. adjust the various bindist urls (make sure to also change the yaml anchors)
2021-10-06 08:20:08 +00:00
6. run `cabal run exe:ghcup-gen -- check -f data/metadata/ghcup-<yaml-ver>.yaml`
7. run `cabal run exe:ghcup-gen -- check-tarballs -f data/metadata/ghcup-<yaml-ver>.yaml -u 'ghc-8\.10\.8'`
### Adding a new CLI command
An example illustration on how to deal with [optparse-applicative](https://hackage.haskell.org/package/optparse-applicative) can be seen here: https://gitlab.haskell.org/haskell/ghcup-hs/-/commit/c19dd5ee8b2edbaf0336af143f1c75b6f4843e26
2020-04-28 15:41:08 +00:00
2020-04-25 10:06:41 +00:00
## Major refactors
1. First major refactor included adding cross support. This added
`GHCTargetVersion`, which includes the target in addition to the version.
Most of the `Version` parameters to functions had to be replaced with
that and ensured the logic is consistent for cross and non-cross
installs.
2021-07-09 17:51:21 +00:00
2. This refactor added windows support wrt [#130](https://gitlab.haskell.org/haskell/ghcup-hs/-/issues/130).
The major changes here were switching `hpath` library out for `filepath`/`directory` (sadly) and
introducing a non-unix way of handling processes via the `process` library. It also introduced considerable
amounts of CPP wrt file handling, installation etc.
2021-10-02 18:21:51 +00:00
# Releasing
1. Update version in `ghcup.cabal` and `boostrap-haskell` (`ghver` variable at the top of the script)
2. Update `GHCup.Version` module. `ghcupURL` must only be updated if we change the `GHCupInfo` type or the YAML representation of it. The version of the YAML represents the change increments. `ghcUpVer` is the current application version, read from `ghcup.cabal`.
3. Add ChangeLog entry
2021-10-06 08:20:08 +00:00
4. Add/fix downloads in `ghcup-<ver>.yaml` (under `data/metadata`), then verify with `ghcup-gen check -f data/metadata/ghcup-<ver>.yaml` and possibly (example only) `ghcup-gen check-tarballs -f data/metadata/ghcup-<ver>.yaml -u 'ghc-8.10.7'`. Generally, new GHC/cabal/stack/hls versions are only added to the latest yaml file. New GHCup versions are added to all (great care must be taken here to not break the parser... e.g. ARM platforms don't parse in all older formats).
2021-10-02 18:21:51 +00:00
5. Commit and git push with tag. Wait for tests to succeed and release artifacts to build.
2021-10-06 08:20:08 +00:00
6. Download release artifacts and upload them `downloads.haskell.org/~ghcup` along with checksum files (`sha256sum --tag * > SHA256SUMS && gpg --detach-sign -u <your-email> SHA256SUMS`)
2021-10-02 18:21:51 +00:00
7. Add ghcup release artifacts to ALL yaml files (see point 4.)
2021-10-06 08:20:08 +00:00
8. Upload the final `data/metadata/ghcup-<ver>.yaml` (and a detached GPG sig of it) to `webhost.haskell.org/ghcup/data/`.
2021-10-02 18:21:51 +00:00
9. Update `bootstrap-haskell` and `bootstrap-haskell.ps1` to `webhost.haskell.org/ghcup/sh/`
2021-10-06 08:20:08 +00:00
10. Update the top-level ghcup symlinks at `downloads.haskell.org/~ghcup`
11. Post on reddit/discourse/etc. and collect rewards
# Documentation
2021-10-02 18:21:51 +00:00
2021-10-06 08:20:08 +00:00
This documentation page is built via [mkdocs](https://www.mkdocs.org/), see `mkdocs.yml` and `docs/` subfolder.
The module graph needs [graphmod](https://github.com/yav/graphmod) and is generated via `scripts/dev/modgraph.sh`.