You are not logged in.

#1 2016-02-04 13:02:14

fusion809
Member
Registered: 2015-06-19
Posts: 70

Creating PKGBUILDs for package written in Go: limetext

Hi,

I have been trying to write a PKGBUILD for the backend for the text editor Lime which is written in Go. Now, I have read (and copied most of their go-get example) the Go package article at the ArchWiki. The problem is that my PKGBUILD generates a package that includes a home directory (which a structure identical to where I am building this package on my machine), which as I understand it is not meant to be. Here is my PKGBUILD:

# Maintainer: Brenton Horne <brentonhorne77 at gmail dot com>

pkgname=limetext-backend-git
pkgver=1f1303a
pkgrel=1
pkgdesc='Free Sublime Text clone written in Go, backend'
arch=('i686' 'x86_64')
url="http://limetext.org/"
license=('BSD')
depends=('python' 'ruby')
makedepends=('git' 'go')
options=('!strip' '!emptydirs')
_gourl=github.com/limetext/lime-backend/lib

build() {
  export GOROOT=/usr/lib/go
  rm -rf build
  mkdir -p build/go
  cd build/go

  for f in "$GOROOT/"*; do
    ln -s "$f"
  done

  rm pkg
  mkdir pkg
  cd pkg

  for f in "$GOROOT/pkg/"*; do
    ln -s "$f"
  done

  export GOROOT="$srcdir/build/go"
  export GOPATH="$srcdir/build"

  go get -fix "$_gourl"
  cd $GOPATH/src/github.com/limetext/lime-backend
  git submodule update --init --recursive

  # Prepare executable
  if [ -d "$srcdir/build/src" ]; then
    cd "$srcdir/build/src/$_gourl"
    go build -o "$srcdir/build/$pkgname"
  else
    echo 'Old sources for a previous version of this package are already present!'
    echo 'Build in a chroot or uninstall the previous version.'
    return 1
  fi
}

package() {
  export GOROOT="$GOPATH"

  # Package go package files
  for f in "$srcdir/build/go/pkg/"* "$srcdir/build/pkg/"*; do
    # If it's a directory
    if [ -d "$f" ]; then
      cd "$f"
      mkdir -p "$pkgdir/$GOROOT/pkg/`basename $f`"
      for z in *; do
        # Check if the directory name matches
        if [ "$z" == `echo $_gourl | cut -d/ -f1` ]; then
          cp -r $z "$pkgdir/$GOROOT/pkg/`basename $f`"
        fi
      done
      cd ..
    fi
  done

  # Package source files
  if [ -d "$srcdir/build/src" ]; then
    mkdir -p "$pkgdir/$GOROOT/src/pkg"
    cp -r "$srcdir/build/src/"* "$pkgdir/$GOROOT/src/pkg/"
    find "$pkgdir" -depth -type d -name .git -exec rm -r {} \;
  fi

  # Package license (if available)
  mkdir -p $pkgdir/usr/share/licenses/$pkgname/
  for f in LICENSE COPYING; do
    if [ -e "$srcdir/build/src/$_gourl/$f" ]; then
      install -Dm644 "$srcdir/build/src/$_gourl/$f" \
      "$pkgdir/usr/share/licenses/$pkgname/$f"
    fi
  done

  # Package executables
  if [ -e "$srcdir/build/$pkgname" ]; then
    install -Dm755 "$srcdir/build/$pkgname" \
      "$pkgdir/usr/bin/$pkgname"
  fi
}

additionally, I do not know why but namcap is giving this error:

limetext-backend-git E: Missing custom license directory (usr/share/licenses/limetext-backend-git)

this is despite the fact that as you can clearly see in my PKGBUILD I do include a block of code that is designed to install the license to /usr/share/licenses/limetext-backend-git. I am not totally new to writing PKGBUILDs, but I am totally new to writing Go PKGBUILDs so any assistance will be greatly appreciated. If it helps here is the output of namcap: http://paste2.org/MvXzfxUy. Lime's development is in its infancy and quite frankly its build documentation is poor, especially for Arch Linux (this documentation can be found here). The reason why I was trying to use go get in this PKGBUILD was because to install Lime text manually from source code (without a PKGBUILD) the instructions that worked best for me were for Ubuntu 14.04 (https://github.com/limetext/lime/wiki/B … untu-14.04), which involved go get.

Thanks for your time,
Brenton

Last edited by fusion809 (2016-02-04 13:04:34)

Offline

#2 2016-02-04 14:35:36

fusion809
Member
Registered: 2015-06-19
Posts: 70

Re: Creating PKGBUILDs for package written in Go: limetext

Aha, I have a possible solution PKGBUILD:

# Maintainer: Brenton Horne <brentonhorne77 at gmail dot com>

pkgname=limetext-backend-git
pkgver=1f1303a
pkgrel=1
pkgdesc='Free Sublime Text clone written in Go, backend'
arch=('i686' 'x86_64')
url="http://limetext.org/"
license=('BSD')
depends=('python' 'ruby')
makedepends=('git' 'go')
options=('!strip' '!emptydirs')
_gourl=github.com/limetext/lime-backend/lib

build() {
  export GOROOT=/usr/lib/go
  export GOPATH="$srcdir"
  go get -u github.com/limetext/lime-backend/lib/...
  cd $GOPATH/src/github.com/limetext/lime-backend
  git submodule update --init --recursive
}

package() {
  export GOROOT="$GOPATH"

  # Package license (if available)
  mkdir -p $pkgdir/usr/share/licenses/$pkgname/
  install -Dm644 "$srcdir/build/src/$_gourl/LICENSE" \
  "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

	install -dm755 "$pkgdir/usr/bin"
}

problem is that building it keeps failing because of bug #63 (https://github.com/limetext/lime-backend/issues/63). When building manually this bug does not prevent one from building the lime backend, but it does for this PKGBUILD. This is the exact error message I get from the PKGBUILD:

==> Making package: limetext-backend-git 1f1303a-1 (Fri Feb  5 00:25:04 AEST 2016)
==> Checking runtime dependencies...
==> Checking buildtime dependencies...
==> Retrieving sources...
==> Extracting sources...
==> Removing existing $pkgdir/ directory...
==> Starting build()...
go build github.com/limetext/lime-backend/lib/render/textmate: no buildable Go source files in /home/fusion809/GitHub/PKGBUILDs/limetext-backend
-git/src/src/github.com/limetext/lime-backend/lib/render/textmate
==> ERROR: A failure occurred in build().
    Aborting...

while

go build github.com/limetext/lime-backend/lib/render/textmate: no buildable Go source files in /home/fusion809/GitHub/PKGBUILDs/limetext-backend
-git/src/src/github.com/limetext/lime-backend/lib/render/textmate

is the error message reported in issue #63, it is not a fatal error when building Lime manually but it is a fatal error to this PKGBUILD, is there a way around this?

Offline

Board footer

Powered by FluxBB