You are not logged in.

#1 2018-10-22 19:27:40

brokenpip3
Member
Registered: 2018-10-22
Posts: 5

review my go pkgbuild - lxd client

Hi all,
for my workflow i don't need the entire lxd package in aur (lxd daemon plus lxd client called "lxc"), so i prepare this pkgbuild for build only the cli tool (in ubuntu are splitted into different packages, only in snap version are the same packages).

But is my first time with golang, can you review?

I forgot something?

# Maintainer: 

pkgname=lxd-client-git
pkgver=3.6
pkgrel=1
pkgdesc="Command line tool for LXD"
arch=('x86_64')
url="https://github.com/lxc/lxd"
license=('APACHE')
conflicts=('lxd-lts' 'lxd')
depends=()
makedepends=('go' 'git')
options=('!strip' '!emptydirs')
_gourl=('github.com/lxc/lxd/lxc')

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

package() {
  mkdir -p "$pkgdir/usr/bin"
  install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"
  mkdir -p "${pkgdir}/usr/share/bash-completion/completions"
  cp --preserve=timestamps "${srcdir}/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
  "${pkgdir}/usr/share/bash-completion/completions/lxd-client"
}

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

Ty

Last edited by brokenpip3 (2018-10-22 19:33:11)

Offline

#2 2018-10-23 12:31:02

brokenpip3
Member
Registered: 2018-10-22
Posts: 5

Re: review my go pkgbuild - lxd client

@Mods: my mistake, can you move to right forum section?

i think is https://bbs.archlinux.org/viewforum.php?id=4

Offline

#3 2018-10-23 13:36:29

a821
Member
Registered: 2012-10-31
Posts: 381

Re: review my go pkgbuild - lxd client

after a quick glance I can see

depends=()

remove empty arrays

  mkdir -p "$pkgdir/usr/bin"
  install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"

Why do you need this? did you miss something? You could just do

  install -Dpm755 "$srcdir/bin/lxc" "$pkgdir/usr/bin/lxc"

...

  mkdir -p "${pkgdir}/usr/share/bash-completion/completions"
  cp --preserve=timestamps "${srcdir}/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
  "${pkgdir}/usr/share/bash-completion/completions/lxd-client"

can be replaced with

  install -Dpm644 "${srcdir}/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
      "${pkgdir}/usr/share/bash-completion/completions/lxd-client"

Edit: misread those lines...

Edit2: I forgot, this is a git package but you don't define a pkgver function. You could use the lxd pacakge in the AUR as reference.

Last edited by a821 (2018-10-23 17:52:01)

Offline

#4 2018-10-23 20:19:54

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: review my go pkgbuild - lxd client

brokenpip3 wrote:

Hi all,
for my workflow i don't need the entire lxd package in aur (lxd daemon plus lxd client called "lxc"), so i prepare this pkgbuild for build only the cli tool (in ubuntu are splitted into different packages, only in snap version are the same packages).

But is my first time with golang, can you review?

I forgot something?

# Maintainer: 

pkgname=lxd-client-git
pkgver=3.6
pkgrel=1
pkgdesc="Command line tool for LXD"
arch=('x86_64')
url="https://github.com/lxc/lxd"
license=('APACHE')
conflicts=('lxd-lts' 'lxd')

It should not conflict the lts version, the lts version will conflict and provide lxd.

depends=()


makedepends=('go' 'git')
options=('!strip' '!emptydirs')
_gourl=('github.com/lxc/lxd/lxc')

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

See https://wiki.archlinux.org/index.php/Us … guidelines

Don't download sources during build(), the current golang packaging guidelines are dreadful and you should use the pending rewrite instead.

package() {
  mkdir -p "$pkgdir/usr/bin"
  install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"
  mkdir -p "${pkgdir}/usr/share/bash-completion/completions"
  cp --preserve=timestamps "${srcdir}/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
  "${pkgdir}/usr/share/bash-completion/completions/lxd-client"
}

As mentioned, you should just use install(1) for this.

Also note that makepkg will explicitly modify the timestamps of *all* files in the packaged archive, in accordance with https://reproducible-builds.org/specs/s … ate-epoch/

We're trying to be reproducible by default, so if SOURCE_DATE_EPOCH is not set, makepkg will set it based on the date that makepkg started running.

So preserving the timestamps seems sort of pointless...


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#5 2018-10-25 16:34:48

brokenpip3
Member
Registered: 2018-10-22
Posts: 5

Re: review my go pkgbuild - lxd client

a821 wrote:

after a quick glance I can see

depends=()

remove empty arrays

  mkdir -p "$pkgdir/usr/bin"
  install -p -m755 "$srcdir/bin/"* "$pkgdir/usr/bin"

Why do you need this? did you miss something? You could just do

  install -Dpm755 "$srcdir/bin/lxc" "$pkgdir/usr/bin/lxc"

...

  mkdir -p "${pkgdir}/usr/share/bash-completion/completions"
  cp --preserve=timestamps "${srcdir}/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
  "${pkgdir}/usr/share/bash-completion/completions/lxd-client"

can be replaced with

  install -Dpm644 "${srcdir}/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
      "${pkgdir}/usr/share/bash-completion/completions/lxd-client"

Edit: misread those lines...

Edit2: I forgot, this is a git package but you don't define a pkgver function. You could use the lxd pacakge in the AUR as reference.

Thanks, i rewrite the entire pkgbuild to fit the "-git" version with pkgver.

# Maintainer: 

pkgname=lxd-client-git
pkgver=3.6.r57.7af057b6
pkgrel=1
pkgdesc="Command line tool for LXD"
arch=('x86_64')
url="https://github.com/lxc/lxd"
license=('APACHE')
conflicts=('lxd')
makedepends=('go-pie' 'git')
options=('!strip' '!emptydirs')
_gourl=('github.com/lxc/lxd/lxc')

prepare() {
  export GOPATH="${srcdir}/go"
  mkdir -p "${GOPATH}"
  go get -d -v ${_gourl}
}

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

build() { 
  cd "${GOPATH}/src/${_gourl}"
  go build
  go install
}

package() {
  install -Dpm755 "$srcdir/go/bin/lxc" "$pkgdir/usr/bin/lxc"
  install -Dpm644 "${srcdir}/go/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
      "${pkgdir}/usr/share/bash-completion/completions/lxd-client"
}

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

@eschwartz thanks for clarifying me the reproducible-build but i don't understand why i must remove lxd-lts (the package in aur build the cli client (lts version) but conflict with mine).
And how i can create the pkgvers without download the source?

thanks guys for your tip

Offline

#6 2018-10-25 16:56:50

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: review my go pkgbuild - lxd client

brokenpip3 wrote:

@eschwartz thanks for clarifying me the reproducible-build but i don't understand why i must remove lxd-lts (the package in aur build the cli client (lts version) but conflict with mine).

Because your PKGBUILD conflicts with "lxd", and the other PKGBUILD conflicts+provides "lxd" as well. This means that your PKGBUILD, by extension, conflicts with *any* PKGBUILD that provides "lxd".

This is why your PKGBUILD should also

provides=('lxd')

And how i can create the pkgvers without download the source?

I don't know what you mean by that. Of course you have sources downloaded, you're supposed to do that by using https://wiki.archlinux.org/index.php/PKGBUILD#source


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#7 2018-10-26 08:12:13

brokenpip3
Member
Registered: 2018-10-22
Posts: 5

Re: review my go pkgbuild - lxd client

eschwartz wrote:

Because your PKGBUILD conflicts with "lxd", and the other PKGBUILD conflicts+provides "lxd" as well. This means that your PKGBUILD, by extension, conflicts with *any* PKGBUILD that provides "lxd".

This is why your PKGBUILD should also

provides=('lxd')

Thanks, so my last changes:

+ provides=('lxd')
+ GOFLAGS from go guidelines linked by eschwartz

# Maintainer: 

pkgname=lxd-client-git
pkgver=3.6.r59.975a559f
pkgrel=1
pkgdesc="Command line tool for LXD"
arch=('x86_64')
url="https://github.com/lxc/lxd"
license=('APACHE')
conflicts=('lxd' 'lxd-git')
provides=('lxd')
makedepends=('go-pie' 'git')
options=('!strip' '!emptydirs')
_gourl=('github.com/lxc/lxd/lxc')

prepare() {
  export GOPATH="${srcdir}/go"
  mkdir -p "${GOPATH}"
  go get -d -v ${_gourl}
}

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

build() { 
  cd "${GOPATH}/src/${_gourl}"
  export GOFLAGS="-ldflags=-s -ldflags=-w -gcflags=all=-trimpath=${GOPATH} -asmflags=all=-trimpath=${GOPATH}"
  go build
  go install -v
}

package() {
  install -Dpm755 "$srcdir/go/bin/lxc" "$pkgdir/usr/bin/lxc"
  install -Dpm644 "${srcdir}/go/src/github.com/lxc/lxd/scripts/bash/lxd-client" \
      "${pkgdir}/usr/share/bash-completion/completions/lxd-client"
}

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

Offline

#8 2018-10-26 16:03:03

eschwartz
Fellow
Registered: 2014-08-08
Posts: 4,097

Re: review my go pkgbuild - lxd client

But you still haven't fixed it to download the sources properly using source=()

Also, you still need to remove lxd-git from the conflicts array.


Managing AUR repos The Right Way -- aurpublish (now a standalone tool)

Offline

#9 2018-10-26 22:16:41

brokenpip3
Member
Registered: 2018-10-22
Posts: 5

Re: review my go pkgbuild - lxd client

eschwartz wrote:

But you still haven't fixed it to download the sources properly using source=()

I'm sorry, maybe i miss something but from what I understood the command "go get" download the main repo and all dependencies needed. If I use only "source" to download sources how i get the same result? (download for all the dependencies too)

Or maybe i can use source to fill the pkgversion but after i must download recursive again using "go get".

please tell me if i wrong, i don't know golang stuff

Thanks

Offline

#10 2018-10-27 12:55:36

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 11,866

Re: review my go pkgbuild - lxd client

Follow the first link in #5, is "go get" used anywhere on that page ?
look at the 3 example packages that page mentions, do they use "go get" ?

Then goto lxd github  site and check their releases page.
compare what's in a source code tarball with what "go get" downloads.

Last edited by Lone_Wolf (2018-10-27 12:56:24)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.


(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

Board footer

Powered by FluxBB