You are not logged in.

#1 2020-11-08 10:29:33

adigitoleo
Member
Registered: 2020-08-02
Posts: 20

[SOLVED] VCS package for pyoxidizer

Hi, I'm trying to write a PKGBUILD for pyoxidizer-git as per this issue but I'm having trouble with pkgver. The project git tags are unreliable so I want to parse a .toml file from inside src/pyoxidizer/pyoxidizer to generate the VERSION.rREVISION number but I'm probably doing it wrong:

What I have so far:

pkgname=pyoxidizer-git
pkgver=0.10.0
pkgrel=1
pkgdesc="A modern Python application packaging and distribution tool"
arch=(x86_64)
url="https://github.com/indygreg/PyOxidizer"
license=('MPL2')
depends=('rust')
makedepends=('git' 'cargo')
provides=("${pkgname%-git}")
conflicts=("${pkgname%-git}")
source=("${pkgname%-git}::git+${url}#branch=main")
md5sums=('SKIP')

pkgver() {
    cd "$srcdir/${pkgname%-git}/${pkgname%-git}"
    # Construct a unique pkgver for each commit on the main branch, in the format:
    # RELEASE.rREVISION

    # printf "%s" "$(git describe --long --tags | sed 's/^v//;s/-/.r/;s/-/./')"

    local toml=$(awk '/\[/{section=$0; next} $1{print section $0}' Cargo.toml)
    for line in $toml; do
        case $line in
            \[package\]version=* )
                printf "%s.r%s.%s" \
                    "$(echo $line | sed 's/^\[package\]version=//;s/"//g;s/-/_')" \
                    "$(git rev-list --count HEAD)" \
                    "$(git rev-parse --short HEAD)"
                ;;
        esac
    done

}

build() {
    cd "$srcdir/${pkgname%-git}"
    cargo build --release --locked --bin pyoxidizer
}

check() {
    cd "$srcdir/${pkgname%-git}"
    cargo test --release --locked --bin pyoxidizer -p pyoxidizer
}

package() {
    cd "$srcdir/${pkgname%-git}"
   install -Dm 755 target/release/${pkgname%-git} -t "${pkgdir}/usr/bin"
}

Last edited by adigitoleo (2020-11-09 03:24:02)

Offline

#2 2020-11-08 17:23:12

yochananmarqos
Member
Registered: 2020-02-05
Posts: 22
Website

Re: [SOLVED] VCS package for pyoxidizer

You could do something like this:

pkgver() {
    cd "$srcdir/${pkgname%-git}/${pkgname%-git}"
    printf "%s.r%s.%s" \
        "$(grep '^version =' Cargo.toml | head -n1 | cut -d\" -f2 | sed s/-/./g)" \
        "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}
0.10.0.pre.r2823.562ac88d

Offline

#3 2020-11-08 18:13:05

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 24,638
Website

Re: [SOLVED] VCS package for pyoxidizer

I can't make heads or tails of what all that code is trying to do - you should just use one sed command:

pkgver() {
  cd "$srcdir/${pkgname%-git}/${pkgname%-git}"
  printf "%s.r%s.%s" \
    $(sed -n '/version/{s/.*"\([0-9\.]*\).*"/\1/p;q}' Cargo.toml) \
    "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

yochananmarqos, there should never be a need to pipe from grep to head or either to cut or any of those to sed.  grep + head is the same as just providing a -c flag to grep.  grep + head + cut is the same as using awk.  All that plus sed is the same as just using sed.


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

#4 2020-11-08 18:43:19

yochananmarqos
Member
Registered: 2020-02-05
Posts: 22
Website

Re: [SOLVED] VCS package for pyoxidizer

@Trilby: Thanks for the tips.

Offline

#5 2020-11-09 03:18:13

adigitoleo
Member
Registered: 2020-08-02
Posts: 20

Re: [SOLVED] VCS package for pyoxidizer

Thanks so much guys, I'm using the version that Trilby posted. I still have a lot to learn including how to properly use sed. Testing now, then I'll mark as solved.

Offline

#6 2020-11-09 03:30:47

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 24,638
Website

Re: [SOLVED] VCS package for pyoxidizer

This can also be done well in awk:

pkgver() {
  cd "$srcdir/${pkgname%-git}/${pkgname%-git}"
  printf "%s.r%s.%s" \
    $(awk -F[\"-] '/^version/ { print $2; exit;}' Cargo.toml) \
    "$(git rev-list --count HEAD)" "$(git rev-parse --short HEAD)"
}

I tend to prefer sed - although I'm likely an oddity.  Those not familiar with sed can find it to look a bit like gibberish, while awk is without a doubt more expressive.  But despite it being easier to understand the human author's intent in an awk script, I find it easier to see what the computer will actually do with a sed script (it "feels" more deterministic and easier to anticipate / predict for me).

Last edited by Trilby (2020-11-09 03:31:32)


"UNIX is simple and coherent..." - Dennis Ritchie, "GNU's Not UNIX" -  Richard Stallman

Offline

Board footer

Powered by FluxBB