[pacman-dev] Parsing variables in PKGBUILD packaging functions.

Xyne xyne at archlinux.ca
Wed Jan 6 18:36:13 EST 2010


> Well, did you read the post before yours on this list?  It shows a 
> fairly simplistic approach bash that works quite well and is what I will 
> use for the makepkg test suite.  It does require sourcing the PKGBUILD 
> though, so should not be used on untrusted PKGBUILDs...
> 
> Then there is the "parched" scripts being written for AUR2 that use 
> yacc/lexx + python (from memory...)  - see recent posts by Sebastian 
> Nowicki on this list.
> 
> Allan
> 



I came up with my own (possibly clever?) solution.

* check the PKGBUILD with /bin/bash -n to make sure it's well formatted
* wrap the entire PKGBUILD in a function and source it (step one
guarantees that the code is trapped within the wrapping function and
thus not actually executed)
* capture the output of "set" which spits out the code in canonical
format, i.e. normalized whitespace etc which makes it easier to parse
with regexes
* walk the code, finding variables as you go and interpolate what needs
to be interpolated by keeping track of local variables within each
function

Obviously it will fail for some things but so far it seems to work with
the PKGBUILDs that I've tried.


You can find my parser in the latest version of perl-xyne-arch on my
site (major code rewrite so it needs to wait before it hits community).

I've attached a script which will parse PKGBUILDs and spit out a
modifed JSON format of the data (change the comments to get real JSON).

I've also attached the output from parsing kernel26, which is split.

So far I've also added string substitutions and will add other variable
tricks later. I have no idea how far along any of the other methods
are, such as yacc/lexx + python approach, or if this is even
embarassingly simplistic, but it works for bauerbill (see site/forum)
for now.

Xyne
-------------- next part --------------
A non-text attachment was scrubbed...
Name: kernel26
Type: application/octet-stream
Size: 3210 bytes
Desc: not available
URL: <http://mailman.archlinux.org/pipermail/pacman-dev/attachments/20100107/bc8d570d/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pkgbuild_parser.pl
Type: text/x-perl
Size: 373 bytes
Desc: not available
URL: <http://mailman.archlinux.org/pipermail/pacman-dev/attachments/20100107/bc8d570d/attachment.bin>


More information about the pacman-dev mailing list