On Thu 2007-08-02 17:12 , Aaron Griffin wrote:
On 8/1/07, Alessio 'mOLOk' Bolognino <themolok.ml@gmail.com> wrote:
Ping? A "Won't merge because..." would be appreciated too :)
Sorry sorry. Blame me, I've been slacking in my duties for too long.
I actually think I like this. Have you tested it? I just want to verify that it is backwards compatible and all that.
I tested it on few packages, it is backwards compatible because it checks for the existence of a .install file too, BUT if you simply concatenate the PKGBUILD and the .install, then it could not work because of shared variables between the .install functions and others particular operation on the .install file made by the build function (as Travis and VMiklos pointed out).
The variables like KERNEL_VERSION should be added in all {post,pre}_{install,upgrade,remove} function and I admit this is not the best way and not even very intuitive, but I can't see any non-hackish way to handle it. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ But I can code an hackish way to do it! :) With this patch, makepkg checks which global variables are used in the
On Fri 2007-08-03 02:34 , Alessio 'mOLOk' Bolognino wrote: the scriptlets and add them on the top of the .INSTALL file. Works fine for variables used like: $variable ${variable} ${variable/foo/bar} ${variable##foo} ${variable%%bar} but DOESN'T work with "complex" operations such as $(( variable1 + variable2 )) This is a limitation, might be confusing, and have unexpected behaviour but probably no one will ever need to do arithmetic operations with global variables. This patch lets you use PKGBUILD variables like $pkgname $license etc. in the {post,pre}_{upgrade,remove,install} functions. Is it useful? Probably it is not, but you _can_ do it, you don't _have_to_ do it :) Enjoy: --- scripts/makepkg.sh.in | 28 +++++++++++++++++++++++++--- 1 files changed, 25 insertions(+), 3 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index a3e4d9c..415ac00 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -830,10 +830,31 @@ create_package() { fi local comp_files=".PKGINFO .FILELIST" - - # check for an install script + # check for scriptlets fuctions or an install script # TODO: should we include ${pkgname}.install if it exists and $install is unset? - if [ "$install" != "" ]; then + local scriptlet="$(declare -f {post,pre}_{install,remove,upgrade} || return 0)" + if [ "$scriptlet" != "" ]; then + # check global variables used by scriptlet functions + local scr_vars="$(echo $scriptlet \ + | egrep -o '\$\{?[[:alpha:]_][[:alnum:]_#%/-]*\}?' \ + | sed -e 's@[#%/].*@@g' -e 's@[{}$]@@g' | sort -u)" + + for scr_var in $scr_vars; do + local glob_var=$( set | egrep "^${scr_var}=" || return 0) + if [[ "$glob_var" != "" ]]; then + local glob_vars=$(echo -e "${glob_vars}\n${glob_var}") + fi + done + + msg2 "$(gettext "Adding scriptlet functions (install script will be ignored)...")" + ( echo "$glob_vars" + echo "$scriptlet" + echo 'op=$1' + echo 'shift' + echo '[ "$(type -t "$op")" = "function" ] && $op "$@"' + ) > .INSTALL + comp_files="$comp_files .INSTALL" + elif [ "$install" != "" ]; then msg2 "$(gettext "Adding install script...")" cp "$startdir/$install" .INSTALL comp_files="$comp_files .INSTALL" @@ -1175,6 +1196,7 @@ fi unset pkgname pkgver pkgrel pkgdesc url license groups provides md5sums force unset replaces depends conflicts backup source install build makedepends unset options noextract +unset {post,pre}_{install,remove,upgrade} if [ ! -f "$BUILDSCRIPT" ]; then error "$(gettext "%s does not exist.")" "$BUILDSCRIPT" -- 1.5.2.4 -- Alessio 'mOLOk' Bolognino Arch Linux Trusted User Please send personal email to themolok@gmail.com Public Key http://pgp.mit.edu:11371/pks/lookup?op=get&search=0xFE0270FB GPG Key ID = 1024D / FE0270FB 2007-04-11 Key Fingerprint = 9AF8 9011 F271 450D 59CF 2D7D 96C9 8F2A FE02 70FB