summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: ced65babf67bed82d2e8df28e15405954ea2cfe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
# Maintainer: Gesh <gesh@gesh.uni.cx>
# Contributor: amesgen <amesgen AT amesgen DOT de>
# Based on ormolu and ormolu-bin by amesgen

pkgname=ormolu-static-git
_pkgname="${pkgname%-static-git}"
pkgver=0.7.7.0.r16.g096b72d
pkgrel=4
pkgdesc='A formatter for Haskell source code'
arch=('i686' 'x86_64')
url="https://github.com/tweag/${_pkgname}"
license=('BSD-3-Clause')
provides=("$_pkgname=${pkgver%%.r*}")
conflicts=("$_pkgname")
depends=('gmp')
makedepends=('git' 'stack' 'yq')
source=("$pkgname::git+$url.git")
sha256sums=('SKIP')

# TODO: Delete the old version even if it's more complicated than just a hackage
# string
_rmDep() {
    yq -i --yaml-output --arg pkg "$1" \
        "$(cat <<'EOF'
        ."extra-deps"
        |= del(.[] | strings | select(match("^\($pkg)-[0-9.]+")))
EOF
)" stack.yaml
}

_bump() {
    _rmDep "$1"
    yq -i --yaml-output --argjson val "$2" '."extra-deps"+=[$val]' stack.yaml
}

__ver() { jq -cn '"\($pkg)-\($ver)"' --arg pkg "$1" --arg ver "$2"; }
_bumpVer() { _bump "$1" "$(__ver "$@")"; }

pkgver() {
  cd "$pkgname"
  git describe --tags --long \
    | sed 's/^v//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd "$pkgname"
  stack config set resolver lts-22.22 # ghc-9.6.5

  _bumpVer aeson 2.2.2.0
  _bumpVer character-ps 0.1
  _bumpVer parsec 3.1.17.0
  _bumpVer text 2.1.1
  _bumpVer text-iso8601 0.1.1

  # enable tests
  yq -i --yaml-output \
      '.build."test-arguments"."no-run-tests" = false' stack.yaml
}

build() {
  cd "$pkgname"
  stack build
}

check() {
  cd "$pkgname"
  stack test
}

package() {
  cd "$pkgname"
  stack install --local-bin-path "$pkgdir/usr/bin"
  install -Dm644 LICENSE.md -t "$pkgdir/usr/share/licenses/$pkgname/"

  _install_completion_script bash bash-completion/completions/ormolu
  _install_completion_script zsh zsh/site-functions/_ormolu
  _install_completion_script fish fish/vendor_completions.d/ormolu.fish
}

_install_completion_script() {
  install -Dm644 \
    <("$pkgdir/usr/bin/ormolu" --$1-completion-script /usr/bin/ormolu) \
    "$pkgdir/usr/share/$2"
}

# vim:set ts=2 sw=2 et