FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Development

 
 
LinkBack Thread Tools
 
Old 12-27-2009, 08:57 AM
Allan McRae
 
Default 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...

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
 
Old 12-27-2009, 08:57 AM
Allan McRae
 
Default 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...

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
 
Old 12-27-2009, 01:17 PM
Daenyth Blank
 
Default 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.
 
Old 12-28-2009, 08:58 PM
Allan McRae
 
Default 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.


Allan
 

Thread Tools




All times are GMT. The time now is 03:10 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org