Ruby package guidelines#
This document covers standards and guidelines on writing PKGBUILDs for software that uses ruby.
Package naming#
For libraries, use ruby-$_name (where $_name is the upstream project name).
For applications, use the project name (without the ruby- prefix) and optionally add ruby-$_name to provides.
Build and tests#
Ruby packages should be built from upstream sources as this provides a transparent chain of trust for the build. To ensure integration with the existing set of Ruby packages, it is expected to run tests using ruby-rake or ruby-rspec.
ℹ️ Note
To detect dependency changes in between releases of a project, have a close look at the
.gemspecorGemfileupon update.
Template#
prepare() {
cd "${_name}-${pkgver}"
# update gemspec/Gemfile to allow newer version of the dependencies
sed --in-place --regexp-extended 's|~>|>=|g' "${_name}.gemspec"
}
build() {
cd "${_name}-${pkgver}"
local _gemdir="$(gem env gemdir)"
gem build "${_name}.gemspec"
gem install \
--local \
--verbose \
--ignore-dependencies \
--build-root "tmp_install" \
"${_name}-${pkgver}.gem"
}
check() {
cd "${_name}-${pkgver}"
local _gemdir="$(gem env gemdir)"
GEM_HOME="tmp_install/${_gemdir}" rake test
}
package() {
cd "${_name}-${pkgver}"
cp --archive --verbose tmp_install/* "${pkgdir}"
install --verbose -D --mode=0644 LICENSE --target-directory "${pkgdir}/usr/share/licenses/${pkgname}"
install --verbose -D --mode=0644 *.md --target-directory "${pkgdir}/usr/share/doc/${pkgname}"
}Tips and tricks#
The gem is deriving the files to add with “git ls-files”#
In this case you can add the following sed command to the prepare() function:
# we don't build from a git checkout
sed --in-place --regexp-extended 's|git ls-files|find . -type f -not -path "*/\.git/*"|' "${_name}.gemspec"The upstream project is using “rspec” to run tests#
In this case you can replace the code line in the check() function with the following:
GEM_HOME="tmp_install/${_gemdir}" rspec