[pacman-dev] Handling splitpkg overrides in scripts

Allan McRae allan at archlinux.org
Sun Dec 27 04:57:55 EST 2009


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_overrides[@]}; do
        indirect="${var}_backup"
        eval "${indirect}=(\"\${$var[@]}\")"
    done
}

restore_package_variables() {
    for var in ${splitpkg_overrides[@]}; do
        indirect="${var}_backup"
        if [[ -n ${!indirect} ]]; then
            eval "${var}=(\"\${$indirect[@]}\")"
        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_overrides[@]}; 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 ${pkgname[@]}; 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



More information about the pacman-dev mailing list