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...
'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
12-27-2009, 08:57 AM
Allan McRae
Handling splitpkg overrides in scripts
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...
'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
12-27-2009, 01:17 PM
Daenyth Blank
Handling splitpkg overrides in scripts
On Sun, Dec 27, 2009 at 04:57, Allan McRae <allan@archlinux.org> wrote:
> It can handle the following syntax:
> for=('a' 'b'
> * * * * 'c' )
Does it correctly handle the case where the is not there? It's not
needed inside an array declaration.
12-28-2009, 08:58 PM
Allan McRae
Handling splitpkg overrides in scripts
Daenyth Blank wrote:
On Sun, Dec 27, 2009 at 04:57, Allan McRae <allan@archlinux.org> wrote:
It can handle the following syntax:
for=('a' 'b'
'c' )
Does it correctly handle the case where the is not there? It's not
needed inside an array declaration.
Yes it does. It was just an example of the syntax that is widely (and
unnecessarily) used.