diff options
-rw-r--r-- | Makefile.PL | 2 | ||||
-rw-r--r-- | URPM.xs | 28 | ||||
-rw-r--r-- | t/parse.t | 8 |
3 files changed, 36 insertions, 2 deletions
diff --git a/Makefile.PL b/Makefile.PL index 748876e..14dfd3f 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -54,7 +54,7 @@ WriteMakefile( CCFLAGS => '-Wall', OPTIMIZE => '-O3 -fomit-frame-pointer -fno-exceptions -pipe -s -ffast-math -fexpensive-optimizations', VERSION_FROM => 'URPM.pm', - LIBS => [ '-lrpm -lrpmio -lrpmdb -lpopt -lz' ], + LIBS => [ '-lrpm -lrpmio -lrpmdb -lrpmbuild -lpopt -lz' ], INC => '-I/usr/include/rpm', dist => { COMPRESS => "bzip2", SUFFIX => ".bz2" }, realclean => { FILES => "t/RPMS/noarch/*" }, @@ -34,6 +34,7 @@ #include <rpm/rpmps.h> #include <rpm/rpmpgp.h> #include <rpm/rpmcli.h> +#include <rpm/rpmbuild.h> struct s_Package { char *info; @@ -3646,6 +3647,33 @@ Urpm_stream2header(fp) } void +Urpm_spec2srcheader(specfile) + char *specfile + PREINIT: + rpmts ts = rpmtsCreate(); + URPM__Package pkg; + Spec spec = NULL; + PPCODE: +#define SPEC_ANYARCH 1 +#define SPEC_FORCE 1 + if (!parseSpec(ts, specfile, "/", NULL, 0, NULL, NULL, SPEC_ANYARCH, SPEC_FORCE)) { + spec = rpmtsSetSpec(ts, NULL); + if ( ! spec->sourceHeader) + initSourceHeader(spec); + pkg = (URPM__Package)malloc(sizeof(struct s_Package)); + memset(pkg, 0, sizeof(struct s_Package)); + pkg->h = headerLink(spec->sourceHeader); + SV *sv_pkg; + EXTEND(SP, 1); + sv_pkg = sv_newmortal(); + sv_setref_pv(sv_pkg, "URPM::Package", (void*)pkg); + PUSHs(sv_pkg); + spec = freeSpec(spec); + } + ts = rpmtsFree(ts); + + +void expand(name) char * name PPCODE: @@ -4,7 +4,7 @@ use strict; use warnings; -use Test::More tests => 24; +use Test::More tests => 26; use MDV::Packdrakeng; use URPM; use URPM::Build; @@ -62,3 +62,9 @@ ok(URPM::rpmvercmp("1:1-1mdk", "2:1-1mdk") == -1, "epoch 1 vs 2 = -1"); ok($pkg->queryformat("%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}") eq "test-rpm-1.0-1mdk.noarch"); close $hdfh; } + +{ + my $pkg = URPM::spec2srcheader("test-rpm.spec"); + ok(defined $pkg, "Parsing a spec works"); + ok($pkg->get_tag(1000) eq 'test-rpm'); +} |