[pacman-dev] Parsing variables in PKGBUILD packaging functions.
Hi, Is there any way to _unequivocally_ parse PKGBUILD variables within a "package" function, e.g. "depends", without executing the entire code block? Please tell me that you don't actually need to build the package(s) to get all of the variables. Thanks, Xyne *holds breath and hopes*
Xyne wrote:
Hi,
Is there any way to _unequivocally_ parse PKGBUILD variables within a "package" function, e.g. "depends", without executing the entire code block?
Please tell me that you don't actually need to build the package(s) to get all of the variables.
Thanks,
Xyne
*holds breath and hopes*
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
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
participants (2)
-
Allan McRae
-
Xyne