This is the start of what will be a makepkg test suite. It shows a (somewhat robust?) method of parsing splitpkg overrides so will be of use when updating db-scripts to handle splitpkg's with different arch/pkgrel/pkgver's (which can be overrided in pacman-git now).

It extracts the "package_foo()" function with a sed statements that assumes that it starts at the start of the line and the closing "}" is the only thing on its line (could be made more robust...). Then is extracts the various variables using a grep. It can handle the following syntax:

foo=1
foo=STRING
foo="ABC  DEF"
for=('a' 'b' \
         'c' )
which is basically everything...

Any comments on how to improve this are welcome.

Allan


#!/bin/bash

splitpkg_overrides=('pkgver' 'pkgrel' 'pkgdesc' 'arch' 'license' 'groups' \
'depends' 'optdepends' 'provides' 'conflicts' 'replaces' \
                   'backup' 'options' 'install' 'changelog')
readonly -a splitpkg_overrides

backup_package_variables() {
   for var in ${splitpkg_overrid...@]}; do
       indirect="${var}_backup"
       eval "${indirect}=(\"\${$v...@]}\")"
   done
}

restore_package_variables() {
   for var in ${splitpkg_overrid...@]}; do
       indirect="${var}_backup"
       if [[ -n ${!indirect} ]]; then
           eval "${var}=(\"\${$indire...@]}\")"
       else
           unset ${var}
       fi
   done
}

parse_splitpkg_overrides() {
   if grep -q "package_$1()" PKGBUILD; then
       pkgfunc=$(sed -n "/^package_$1\(\)/,/^}/p" PKGBUILD)
       for var in ${splitpkg_overrid...@]}; do
eval $(echo $pkgfunc | grep -Eo "$var=(\"[^)]*\"|\([^)]*\)|[^ ]*)")
       done
   fi
}

##
# Checks if all packages are created - does not work yet... :P
##
pkg_exists() {
   # get package arch
   if [[ $arch != "any" ]]; then
       arch=$CARCH
   fi

   for pkg in ${pkgna...@]}; do
       # check for package specific overrides
       backup_package_variables
       parse_splitpkg_overrides $pkg
       echo $pkg-$pkgver-$pkgrel-$arch$PKGEXT
restore_package_variables done
}

source /etc/makepkg.conf
source PKGBUILD

pkg_exists


Reply via email to