summarylogtreecommitdiffstats
path: root/geninfo.sh
blob: 820db449afc1179b753d149ecb1cfa164b08ecc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/env bash

## need install yq and jq

pkgbase=$(awk -F= '/pkgbase=/{print $2}' PKGBUILD)
pkgver=$(awk -F= '/pkgver=/{print $2}' PKGBUILD)
tmp_pkgname=$(mktemp)
tmp_pkgdescs=$(mktemp)
tmp_urls=$(mktemp)
tmp_depends=$(mktemp)
tmp_optdepends=$(mktemp)

trap "rm $tmp_pkgname $tmp_pkgdescs $tmp_urls $tmp_depends $tmp_optdepends" EXIT 

_get_dirname() {
    case $1 in
        opentelemetry-exporter-*)               echo "exporter/";;
        opentelemetry-instrumentation-openai-*) echo "instrumentation-genai/";;
        opentelemetry-instrumentation-*)        echo "instrumentation/";;
        opentelemetry-processor-*)              echo "processor/";;
        opentelemetry-propagator-*)             echo "propagator/";;
        opentelemetry-resource-*)               echo "resource/";;
        opentelemetry-sdk-extension-*)          echo "sdk-extension/";;
        opentelemetry-util-*)                   echo "util/";;
        *) ;;
    esac
}

## pkgname
_gen_pkgname() {
    echo "$pkgs" | sed 's|^|    \"python-|' | sed 's|$|\"|'
    echo ")"
}

## _pkgdescs
_gen_pkgdescs() {
    for pkg in $pkgs; do
        dirname=$(_get_dirname "$pkg")
        pkgdesc=$(yq eval -o=json "src/${pkgbase}-${pkgver}/${dirname}${pkg}/pyproject.toml" | jq -r '.project.description')
        echo "    \"$pkgdesc\""
    done
    echo ")"
}

## _urls
_gen_urls() {
    for pkg in $pkgs; do
        dirname=$(_get_dirname "$pkg")
        echo "    \"\${_url}/tree/main/${dirname}${pkg}\""
    done
    echo ")"
}

## _depends
_gen_depends() {
    for pkg in $pkgs; do
        dirname=$(_get_dirname "$pkg")
        depends=($(
            yq eval -o=json "src/${pkgbase}-${pkgver}/${dirname}${pkg}/pyproject.toml" | \
            jq -r '.project.dependencies.[]' 2>/dev/null | \
            grep -oP '^([a-zA-Z0-9_-]+)' | \
            tr 'A-Z' 'a-z' | \
            sed 's|^|python-|' | \
            sed 's|python-python|python|' | \
            sort -u
        ))
        echo "    \""${depends[@]}"\""
    done
    echo ")"
}

## _optdepends
_gen_optdepends() {
    for pkg in $pkgs; do
        dirname=$(_get_dirname "$pkg")
        depends=($(
            yq eval -o=json "src/${pkgbase}-${pkgver}/${dirname}${pkg}/pyproject.toml" | \
            jq -r '.project."optional-dependencies".[].[]' 2>/dev/null | \
            grep -oP '^([a-zA-Z0-9_-]+)' | \
            tr 'A-Z' 'a-z' | \
            sed 's|^|python-|' | \
            sed 's|-python||g' | \
            sed 's|_|-|g' | \
            sort -u
        ))
        echo "    \""${depends[@]}"\""
    done
    echo ")"
}

makepkg -do
pkgs=$(find "src/${pkgbase}-${pkgver}" -type f -name "pyproject.toml" | grep -vP '.git|_template' | awk -F '/' '{print $((NF-1))}' | grep -v "${pkgbase}-${pkgver}" | tr 'A-Z' 'a-z' | sort -u)
_gen_pkgname > $tmp_pkgname
_gen_pkgdescs > $tmp_pkgdescs
_gen_urls > $tmp_urls
_gen_depends > $tmp_depends
_gen_optdepends > $tmp_optdepends

sed -e "/^pkgname=(/,/)/c\pkgname=(" \
    -e "/^_pkgdescs=(/,/)/c\_pkgdescs=(" \
    -e "/^_urls=(/,/)/c\_urls=(" \
    -e "/^_depends=(/,/)/c\_depends=(" \
    -e "/^_optdepends=(/,/)/c\_optdepends=(" \
    -i PKGBUILD

sed -e "/^pkgname=/r $tmp_pkgname" \
    -e "/^_pkgdescs=/r $tmp_pkgdescs" \
    -e "/^_urls=/r $tmp_urls" \
    -e "/^_depends=/r $tmp_depends" \
    -e "/^_optdepends=/r $tmp_optdepends" \
    -i PKGBUILD