RPM::Toolbox::Spec - parse RPM specs with macro expansion
use RPM::Toolbox::Spec; $spec = RPM::Toolbox::Spec->parse_file ($filename, %options); $spec = RPM::Toolbox::Spec->parse_string ($spec_text, %options); @packages = $spec->packages; @sources = $spec->sources; @patches = $spec->patches; @icons = $spec->icons; $buildroot = $spec->buildroot; @buildarchs = $spec->buildarchs; @buildrequires = $spec->buildrequires; @buildconflicts = $spec->buildconflicts; $srcrpm = $spec->srcrpm; # "foo-1.0.src.rpm" @rpms = $spec->rpms; # ("foo-1.0.i386.rpm", ...) $name = $spec->name; $epoch = $spec->epoch ($subpackage); # subpackage is optional $version = $spec->version ($subpackage); $release = $spec->release ($subpackage); ... # supported tags are documented below
RPM is a package management system for UNIX-like operating systems; spec files are used by RPM to define and maintain meta information and build commands for a set of related packages.
This module extracts various bits of information from RPM spec files. It aims at arriving at the same conclusions as rpm and rpmbuild commands would on your system by expanding macros, evaluating conditionals, etc. It does so by executing rpm/rpmbuild commands and analyzing their output.
This process is quite slow -- in the order of seconds for complex spec files; caching may be used to store/load the results of processing, providing significant performance improvements when processing the same file multiple times.
This module requires rpm/rpmbuild >= 4.3.3 with lua support compiled-in.
Constructs a new object by parsing a spec file or a string.
The OPTIONS
hash affects various processing parameters:
$spec = RPM::Toolbox::Spec->parse_file ("filename", rpm_command => "/bin/rpm", rpmbuild_command => "/usr/bin/rpmbuild", defines => [ "_topdir /usr/src/redhat", "dist .el4" ], rcfile => "/home/user/rpmrc1:/home/user/rpmrc2", target => "i486-redhat-linux", expand => { expr1 => '%name-%version', expr2 => '@filename', }, cache => "file.cache", debug => 1, workdir = "/tmp/somedir.tmp" );
Commands to invoke rpm
and rpmbuild
; additional arguments will be
appended to these strings:
rpm_command => "/usr/local/bin/rpm", rpmbuild_command => "/usr/local/bin/rpmbuild"
A listref containing the macros to be defined at RPM startup:
defines => [ "_topdir /usr/src/redhat", "dist .el4" ] );
This option is equivalent to rpm's --define
option.
Colon-separated list of alternative rcfiles for RPM, equivalent to rpm's
--rcfile
option:
rcfile => "/home/user/rcfile1:/home/user/rcfile2"
Set %_target
, %_target_cpu
and %_target_os
macros; similar to
rpmbuild's --target
option.
A hashref of expressions to be evaluated at the end of the spec file. The results of each evaluation may be retrieved by calling the "expansion" method with the same key.
All expressions are evaluated in one pass in some unspecified order, as if they were pasted at the end of the spec file.
Expression may be either strings containing RPM macro references or file
names. Expressions that begin with @
specify file names whose contents are
to be evaluated. Expressions that begin with :
are macro-evaluated
directly excluding the leading :
. Expressions whose 1st character is
neither :
nor @
are also macro-evaluated directly, not as file names.
For example, here's how to evaluate a macro and an arbitrary file:
$spec = RPM::Toolbox::Spec->new ("specfile", expand => { key1 => '%name', key2 => '@some_file', } ); my $expanded_name = $spec->expansion ("key1"); my $expanded_file_contents = $spec->expansion ("key2");
Store or load the extracted information to/from a file. Requires YAML module at runtime; if that module is not available this option does nothing.
Reading from cache is much faster than parsing; the cache is invalidated whenever the spec file, user's macros file or any files evaluated using the "expand" option is changed.
cache => "filename.cache"
Setting debug to true will print lots debug messages to STDERR.
Name of directory to save temporary files to. Without this option temporary files will be deleted before the constructor returns. Mainly useful for debugging.
workdir => "/tmp/somedir.tmp"
Returns the list of packages defined in this spec file in order.
Returns the name of the first package (i.e., first item returned by
packages
).
Basename and full path of the source RPM file that would be created by rpmbuild.
These methods return lists of base names and full paths of binary rpm files
that may be generated for all packages defined in the spec file. Note that
rpmbuild
may or may not generate all of these RPMs (by default it doesn't
create packages that contain no files).
Returns the list of build requirements and conflicts for this spec file.
Returns the list of architectures on which this spec file can be built. If this list is empty, the package can be built on any architecture.
Each of these methods returns a list of various types of source files required to build the spec file.
Icons are returned unordered, the ordering of sources and patches is as
follows: if all Source:
and Patch:
directives in the spec file have
unique sequence numbers, the corresponding list will be sorted by sequence;
otherwise the order is unspecified.
sources
, patches
, and icons
return file base names.
sourcefiles
, patchfiles
and iconfiles
return full paths that rpmbuild
would be looking for.
These methods return tags for the (sub-)packages defined in the spec file. You can pass the name of the subpackage as an argument, otherwise the main (first) package will be searched.
conflicts
, requires
, provides
and obsoletes
return lists of
dependencies; these lists are not reliable since most packages generate
dependency information dynamically when the package is built.
The fullversion
method concatenates the version-related fields into
one string of the form "[epoch:]version-release".
binaryrpm
and binaryrpmfile
return the basename and full path of the
binary RPM file that would be generated by rpmbuild
for the specified
package.
All other methods return a scalar or undef
if the corresponding tag is
not defined.
Examples:
$foo_summary = $spec->summary; # summary of main package $foo_devel_summary = $spec->summary ("foo-devel"); @foo_conflicts = $spec->conflicts ("foo"); $foo_devel_rpmpath = $spec->binaryrpmfile ("foo-devel");
Returns the result of evaluating a macro expression passed to the constructor's "expand" option with the given key.
This class doesn't really parse anything, it extracts information by calling rpm and rpmbuild in various ways and analyzing their output. It takes several passes to obtain all of the fields, so the spec is evaluated more than once. This is quite slow; the "cache" option improves that somewhat.
This class redefines '%_sourcedir' to point to a temporary location, so don't rely on this macro in any place that may affect macro expansion, e.g.:
... # this will fail since %_sourcedir will be redefined while parsing Version: %(cat %_sourcedir/version) ... %build # OK, since this class doesn't execute any scriptlets cp %_sourcdir/version . ...
This doesn't affect "expand" expressions though.
rpm(8), rpmbuild(8)
Davlet Panech - dpanech at users dot sourceforge dot net
Copyright (C) 2010 by Davlet Panech
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.