summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 52110d6cb76a77dedb49c1a76f4b6fbbf5afa279 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Maintainer: Carl Smedstad <carl.smedstad at protonmail dot com>
# Maintainer: Anton Kudelin <kudelin at protonmail dot com>
# Contrubutor: farwayer <farwayer@gmail.com>

pkgname=ruby-dotenv
_pkgname=${pkgname#ruby-}
pkgver=3.1.0
pkgrel=1
pkgdesc="Loads environment variables from .env"
arch=(any)
url="https://github.com/bkeepers/dotenv"
license=(MIT)
depends=(ruby)
makedepends=(rubygems)
checkdepends=(ruby-rspec)
options=(!emptydirs)
install=ruby-dotenv.install
source=("$pkgname-$pkgver.tar.gz::$url/archive/v$pkgver.tar.gz")
sha256sums=('1d78e3b621dd060e516a2413cfbfd5778a4c039b57c6634667f03fc41de47b8c')

_archive="$_pkgname-$pkgver"

prepare() {
  cd "$_archive"

  # update gemspec/Gemfile to allow newer version of the dependencies
  sed --in-place --regexp-extended 's|~>|>=|g' "$_pkgname.gemspec"

  # we don't build from a git checkout
  sed --in-place --regexp-extended \
    's|git ls-files README.md LICENSE lib bin|find README.md LICENSE lib bin -type f -not -path "*/\.git/*"|' \
    "$_pkgname.gemspec"

  # Add missing require to tests
  echo "require 'pathname'" >> spec/spec_helper.rb
}

build() {
  cd "$_archive"

  local gemdir="$(gem env gemdir)"

  gem build "$_pkgname.gemspec"

  gem install \
    --local \
    --verbose \
    --ignore-dependencies \
    --no-user-install \
    --install-dir "tmp_install/$gemdir" \
    --bindir "tmp_install/usr/bin" \
    "$_pkgname-$pkgver.gem"

  # remove unrepreducible files
  rm --force --recursive --verbose \
    "tmp_install/$gemdir/cache/" \
    "tmp_install/$gemdir/gems/$_pkgname-$pkgver/vendor/" \
    "tmp_install/$gemdir/doc/$_pkgname-$pkgver/ri/ext/"

  find "tmp_install/$gemdir/gems/" \
    -type f \
    \( \
    -iname "*.o" -o \
    -iname "*.c" -o \
    -iname "*.so" -o \
    -iname "*.time" -o \
    -iname "gem.build_complete" -o \
    -iname "Makefile" \
    \) \
    -delete

  find "tmp_install/$gemdir/extensions/" \
    -type f \
    \( \
    -iname "mkmf.log" -o \
    -iname "gem_make.out" \
    \) \
    -delete
}

check() {
  cd "$_archive"

  # Remove tests that depend on rails
  local excluded_tests=(
    dotenv/rails_spec.rb
    dotenv/log_subscriber_spec.rb
  )
  local excluded_tests_pattern="spec/{${excluded_tests[0]}$(printf ',%s' "${excluded_tests[@]:1}")}"

  GEM_HOME="tmp_install/$(gem env gemdir)" rspec \
    --exclude-pattern "$excluded_tests_pattern"
}

package() {
  cd "$_archive"

  cp -a tmp_install/* "$pkgdir"
  mv "$pkgdir/usr/bin/dotenv" "$pkgdir/usr/bin/ruby-dotenv"

  install -Dm644 -t "$pkgdir/usr/share/doc/$pkgname" ./*.md
  install -Dm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE
}