[pacman-dev] [patch] add support for scriptlets functions embedded in $BUILDSCRIPT

Alessio 'mOLOk' Bolognino themolok.ml at gmail.com
Tue Sep 4 23:19:55 EDT 2007


On Fri 2007-08-03 15:18 , Aaron Griffin wrote:
> On 8/3/07, Alessio 'mOLOk' Bolognino <themolok.ml at gmail.com> wrote:
> > On Fri 2007-08-03 02:34 , Alessio 'mOLOk' Bolognino wrote:
> > > but I can't see any non-hackish way to handle it.
> >       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > But I can code an hackish way to do it! :)
> 
> Ok, one suggestion and I think I'll be ok with it - can you do two
> things as part of this patch:
> a) document that complex variable usage will fail in the man page
> b) Output a warning if variables are found - something that says
> "don't do crazy stuff!"
> 
> Assuming that's all in there (so you get credit), I don't think I'd
> have a problem with merging this - anyone else?

Uhm... this took a while, I almost forgot about this :) 
Here it is my patch, all critics are welcome:

---
 doc/PKGBUILD.5        |   10 ++++++++--
 scripts/makepkg.sh.in |   34 +++++++++++++++++++++++++++++++---
 2 files changed, 39 insertions(+), 5 deletions(-)

diff --git a/doc/PKGBUILD.5 b/doc/PKGBUILD.5
index 747b9f1..f69f1c0 100644
--- a/doc/PKGBUILD.5
+++ b/doc/PKGBUILD.5
@@ -220,8 +220,8 @@ script is run right before files are removed.
 script is run right after files are removed.
 
 .P
-To use this feature, create a file such as 'pkgname.install' and put it in
-the same directory as the \fB\*(PB\fP script.  Then use the \fBinstall\fP
+To use this feature, you can create a file such as 'pkgname.install' and put it
+in the same directory as the \fB\*(PB\fP script.  Then use the \fBinstall\fP
 directive:
 
 .RS
@@ -233,6 +233,12 @@ install=pkgname.install
 The install script does not need to be specified in the \fBsource\fP array.
 A template install file is available in the ABS tree (/var/abs/install.proto).
 
+You can also embed the scripts in the \fB\*(PB\fP. In this case you can use 
+global variables (such as pkgver, pkgname, etc.) inside the scripts, but this
+is deprecated if not strictly needed. Note that the usage of global 
+variables in arithmetical expansion expressions or in other complex expressions
+will likely fail.
+
 .SH EXAMPLE
 The following is an example \fB\*(PB\fP for the 'modutils' package. For more
 examples, look through the ABS tree.
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index cd5dbf5..37ca87f 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -833,10 +833,37 @@ 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
+
+		if [[ "$glob_vars" != "" ]]; then
+			msg2 "$(gettext "Global variables usage in scriptlets found")"
+			msg2 "$(gettext "NOTE: this is deprecated if not strictly needed")"
+		fi
+
+		comp_files="$comp_files .INSTALL"
+	elif [ "$install" != "" ]; then
 		msg2 "$(gettext "Adding install script...")"
 		cp "$startdir/$install" .INSTALL
 		comp_files="$comp_files .INSTALL"
@@ -1178,6 +1205,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.3

-- 
Alessio 'mOLOk' Bolognino
Arch Linux Trusted User

Please send personal email to themolok at 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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://archlinux.org/pipermail/pacman-dev/attachments/20070905/a7019afa/attachment.pgp>


More information about the pacman-dev mailing list