Go package guidelines (Português)

From ArchWiki
Jump to: navigation, search

Tango-preferences-desktop-locale.pngEsse artigo ou seção precisa de tradução.Tango-preferences-desktop-locale.png

Notas: Este artigo está sendo traduzido (Discuta na Talk:Go package guidelines (Português)#)
Diretrizes de criação de pacotes

CLRCrossEclipseFree PascalGNOMEGoHaskellJavaKDEKernelLispMinGWNode.jsNonfreeOCamlPerlPHPPythonRRubyVCSWebWine

Go também encontra suporte no Arch Linux.

O pacote go contém a ferramenta go (para executar go fix, go build etc). Também há gcc-go que fornece gccgo.

Diretrizes gerais

Nomenclatura

  • Para aplicativos escritos em Go, use o nome do aplicativo como o nome do pacote, em letras minúsculas.
    • Seja criativo se o nome já estiver sendo usado.
  • Para o PKGBUILDS que usa a ferramenta "go" para baixar o pacote, adicione apenas "-git" ao nome do pacote, se ele não for construído a partir de um tarball ou de um lançamento marcado (mas do trunk/HEAD).
    • Da mesma forma, para pacotes mercurial, adicione apenas "-hg" ao nome do pacote, se não for uma revisão de versão.
    • Estenda esse padrão para outros sistemas de controle de versão.
    • A ferramenta go tem sua própria lógica para qual branch ou tag deve ser usada. Veja go get --help.
  • Considere adicionar o nome do autor ao nome do pacote se houver vários aplicativos com o mesmo nome, como dcpu16-kballardAUR.
    • Em geral, os pacotes mais populares devem poder usar o nome mais curto ou "melhor".
  • Correções posteriores para os nomes dos pacotes (como -hg, -git ou -svn) são opcionais se não houver versões oficiais do projeto em questão. Por um lado, é comum usá-los quando o pacote é baixado de um VCS. Por outro lado, a maioria dos projetos Go não possui tarballs de lançamento, apenas o repositório que é usado para branching/tagging o release oficial, se não for trunk. Além disso, o go get, que é a maneira "oficial" de instalar os módulos do Go, usa os repositórios diretamente. Use seu melhor julgamento.

Empacotamento

  • Go projects are either just library files, just executables or both. Choose the appropriate way of packaging them. There are several examples below.
  • Some Go applications or libraries have not been updated to the latest version of Go yet.
    • Running go build -fix may often work, but it may have to be fixed by the developer. Report an issue upstream if this is the case.
  • Several Go projects do not have a version number or a license file.
    • Use license=('unknown') and report an issue to the developer if a license file is missing.
    • Use version "0.1", "1" or the git-revision (or equivalent for other version control systems) if the version number is missing.
    • Alternatively, use the current date as the version number, in this form YYYYMMDD.

Exemplos de PKGBUILDs

Exemplo de PKGBUILD para um aplicativo escrito em Go

# Maintainer: NAME <EMAIL>

pkgname=PACKAGE NAME
pkgver=1.2.3
pkgrel=1
pkgdesc="PACKAGE DESCRIPTION"
arch=('x86_64' 'i686')
url="http://SERVER/$pkgname/"
license=('MIT')
makedepends=('go')
options=('!strip' '!emptydirs')
source=("http://SERVER/$pkgname/$pkgname-$pkgver.tar.gz")
sha256sums=('00112233445566778899aabbccddeeff')

build() {
  cd "$pkgname-$pkgver"

  go build
}

package() {
  cd "$pkgname-$pkgver"

  install -Dm755 "$pkgname-$pkgver" "$pkgdir/usr/bin/$pkgname"
  install -Dm644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"
}

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

Exemplos de pacotes

Exemplo de PKGBUILD para quando apenas um único arquivo fonte está disponível

# Maintainer: NAME <EMAIL>

pkgname=PACKAGE NAME
pkgver=1.2.3
pkgrel=1
pkgdesc="PACKAGE DESCRIPTION"
arch=('x86_64' 'i686')
url="http://SERVER/$pkgname/"
license=('GPL3')
makedepends=('go')
options=('!strip' '!emptydirs')
source=("http://SERVER/$pkgname/$pkgname.go")
sha256sums=('00112233445566778899aabbccddeeff')

build() {
  go build -o "$pkgname"
}

package() {
  install -Dm755 "$pkgname" "$pkgdir/usr/bin/$pkgname"
}

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

Exemplos de pacotes

Exemplos de PKGBUILDs para bibliotecas Go que também incluem executáveis

Usando go get

This is the recommended way, instead of the method below.

Here is a way that relies on go get.

You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).

If this does not work, test with go get first.

Note: Remove /... if the PKGBUILD fails!
# Maintainer: NAME <EMAIL>

pkgname=codesearch
pkgver=20120515
pkgrel=1
pkgdesc="Code indexing and search written in Go"
arch=('x86_64' 'i686')
url="https://github.com/google/codesearch"
license=('BSD')
depends=('go')
makedepends=('mercurial')
options=('!strip' '!emptydirs')
_gourl=github.com/google/codesearch

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

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

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

  mkdir -p "$pkgdir/$GOPATH"
  cp -Rv --preserve=timestamps "$srcdir/"{src,pkg} "$pkgdir/$GOPATH"

  # 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:

Thanks to Rémy Oudompheng‎ for this one.

Usando go get

Here is another way that relies on go get.

You probably will not need to modify the build() or package() functions at all, only the variables at the top (pkgname etc).

If this does not work, test with go get first.

# Maintainer: NAME <EMAIL>

pkgname=PACKAGE NAME
pkgver=1.2.3
pkgrel=1
pkgdesc="PACKAGE DESCRIPTION"
arch=('x86_64' 'i686')
url="http://SERVER/$pkgname/"
license=('MIT')
makedepends=('go' 'git')
options=('!strip' '!emptydirs')
_gourl=SERVER.NET/PATH/MODULENAME

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

  platform=`for f in "$GOROOT/pkg/"*; do echo \`basename $f\`; done|grep linux`

  rm -f "$platform"
  mkdir "$platform"
  cd "$platform"

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

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

  go get -fix "$_gourl"

  # 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)
  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
}

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