> 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

Attachment: kernel26
Description: Binary data

#!/usr/bin/perl
use strict;
use warnings;

use Xyne::Arch::PKGBUILD qw/parse_pkgbuild/;

use Xyne::Common::Functions qw/str/;
use Xyne::Common::JSON qw/obj_to_json/;

foreach my $pkgbuild (@ARGV)
{
  foreach my $o (&parse_pkgbuild($pkgbuild))
  {
    print &str($o,1);
    #print &obj_to_json($o,1);
    print "\n\n";
  }
}
#print &obj_to_json(&parse_pkgbuild(@ARGV),1);




Reply via email to