Talk:Go package guidelines

From ArchWiki
Jump to: navigation, search

GOPATH has been removed from /etc/profile.d/go.sh

/etc/profile.d/go.sh since go 1.2-1 doesn't contain GOPATH and breaks PKGBUILD templates. https://projects.archlinux.org/svntogit/community.git/commit/trunk?h=packages/go&id=fa3a43875223f38c577093e2b6dc14c604a78b08 I really don't know if /usr/lib/go/src is the right place for sources or they should go to /usr/lib/go/site/src. In either case, $GOPATH is not reset after sourcing /etc/profile.d/go.sh, so src ends up in $srcdir. Vulpesvelox (talk) 10:44, 24 January 2014 (UTC)

Use of GOPATH

In the check() function of the sample PKGBUILD using go get, the GOPATH is set to "$GOPATH:$srcdir". This fails if GOPATH is empty. Beside, I don't see the point of setting this to a possibly existing $GOPATH when the code. I think PKGBUILDs should not rely on the the user's repository, that is, it should be sandboxed. If the users already have a repo, they probably don't need the PKGBUILD in the first place. All they need is run go get -u blah/blah and same for testing. What do you think? -- Ambrevar (talk) 07:39, 1 May 2016 (UTC)

Generate version using pkgver()

I tweaked one of the examples on this page to include a automatically generated version. Perhaps worth considering:


# Maintainer: Harold Drost <baelish@bluecell.net>

pkgname=okta-kubectl-auth-git
pkgver=0.1.1.r2.gd731ef2
pkgrel=1
pkgdesc="Okta auth plugin for kubectl"
arch=("x86_64")
makedepends=("go")
url="https://github.com/jetstack/okta-kubectl-auth"
license=("Apache")
options=('!strip' '!emptydirs')
_gourl="github.com/jetstack/okta-kubectl-auth"

prepare() {
  GOPATH="$srcdir" go get -fix -v -x ${_gourl}
}

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

check() {
  GOPATH="$GOPATH:$srcdir" go test -v -x ${_gourl}
}

package() {
  mkdir -p "$pkgdir/usr/bin"
  install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"

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

# vim:set ts=2 sw=2 et:

I used prepare() for the steps which were in build() as it's run before pkgver(). I don't think it's unreasonable to call the "go get" step preparation so I don't think it's a concern. --Baelish (talk) 19:52, 27 July 2018 (UTC)