DEV Community

Cover image for How to test your branch in an Arch Linux package
Axel Navarro for Cloud(x);

Posted on • Updated on

How to test your branch in an Arch Linux package

In the previous post, we learned how to apply a git patch to a package. In this entry, we'll try to package a specific branch and run our code installed on our system.

The easy way

There are a few alternatives to package a branch, but we'll use the most comfortable way. For this example, we want to compile the master branch using the PKGBUILD for git-delta.

In Arch Linux, the build is based in a git tag, so we should download the commits between the tag and the branch:

https://github.com/dandavison/delta/compare/0.4.1..master.patch

or, the diff alternative:

https://github.com/dandavison/delta/compare/0.4.1..master.diff

The original PKGBUILD

You can see the PKGBUILD in https://aur.archlinux.org/packages/git-delta clicking the View PKGBUILD link. But this is the simplified version:

pkgname=git-delta
_name=delta
pkgver=0.4.1
pkgrel=1
pkgdesc='A syntax-highlighting pager for git and diff output'
arch=('i686' 'x86_64' 'arm' 'armv7h' 'armv6h' 'aarch64')
url="https://github.com/dandavison/$_name"
license=('MIT')
makedepends=('rust' 'clang' 'llvm')
source=("$url/archive/$pkgver.tar.gz")
sha256sums=('5c2e46e398702b13b2768043ba5dc6bea899fb34271120bad4608ff9a64b0434')

build() {
  cd "$_name-$pkgver"
  cargo build --release --locked
}

package() {
  cd "$_name-$pkgver"
  install -Dm755 "target/release/$_name" -t "$pkgdir/usr/bin/"
}
Enter fullscreen mode Exit fullscreen mode

Adding the prepare step

We just need to add the patch URL to the source variable and SKIP to the checksum:

source=("$url/archive/$pkgver.tar.gz"
        my.patch::"$url/compare/$pkgver..master.patch")
sha256sums=('5c2e46e398702b13b2768043ba5dc6bea899fb34271120bad4608ff9a64b0434'
            'SKIP')
Enter fullscreen mode Exit fullscreen mode

And, the prepare function to patch the tag with the new commits:

prepare() {
  patch -d "$_name-$pkgver" -p1 -i ../my.patch
}
Enter fullscreen mode Exit fullscreen mode

So, the PKGBUILD for build the master branch is:

pkgname=git-delta
_name=delta
pkgver=0.4.1
pkgrel=1
pkgdesc='A syntax-highlighting pager for git and diff output'
arch=('i686' 'x86_64' 'arm' 'armv7h' 'armv6h' 'aarch64')
url="https://github.com/dandavison/$_name"
license=('MIT')
makedepends=('rust' 'clang' 'llvm')

source=("$url/archive/$pkgver.tar.gz"
        my.patch::"$url/compare/$pkgver..master.patch")
sha256sums=('5c2e46e398702b13b2768043ba5dc6bea899fb34271120bad4608ff9a64b0434'
            'SKIP')

prepare() {
  patch -d "$_name-$pkgver" -p1 -i ../my.patch
}

build() {
  cd "$_name-$pkgver"
  cargo build --release --locked
}

package() {
  cd "$_name-$pkgver"
  install -Dm755 "target/release/$_name" -t "$pkgdir/usr/bin/"
}
Enter fullscreen mode Exit fullscreen mode

Building your package

For build and install this you just need to use:

makepkg -si
Enter fullscreen mode Exit fullscreen mode

Remember that if you rebuild the package with new commits the makepkg won't refresh the downloaded my.patch file, so we can use this command:

rm my.patch && makepkg -sicCf
Enter fullscreen mode Exit fullscreen mode

The -C, or --cleanbuild, removes the src/ folder before build. And, -c, or --clean, removes the src/ and pkg/ folders after build.

The -f, or --force to overwrite existing package if was already compiled.

A final words

There is a git-delta-git package that compiles the latest commit but Arch needs to uninstall the git-delta before installing the git-delta-git, and for some packages this is not a choise because other packages depend on the package we are trying to update.

You can learn more of Delta here.

Top comments (0)