Building RPMs from CPAN Distributions

Regular readers will know that in the past I’ve shown some interest in building RPMs from CPAN distributions. It’s been a while since I did much work in this area (although I do still release the occasional module to my RPM repository.

Over the weekend I was at FOSDEM and I attended Gabor’s talk on packaging CPAN modules for Linux distributions. This has rekindled my interest in this area and I spent most of the train journey back from Brussels hacking around the area.

There’s one thing that has been bothering me in particular recently. The standard RPM building mechanism (or, at least, the way it’s configured in Fedora and Centos) does something incredible brain dead when trying to work out what other modules the current module depends on. It does it by parsing the source code and looking for “use” statements. This means that a module that might only be used in really obscure cases is going to be listed as a mandatory requirement for your module.

Gabor and I actually saw an example of this over the weekend when the Fedora packaging team raised a bug against Padre because it requires Win32::API. Padre, of course, only uses Win32::API when being used on Windows. And for that reason Win32::API is not listed as a dependency in its META.yml.

And that’s, of course, where the RPM builders should be going to get a list of dependencies. META.yml contains the list of other modules that the author wants the module to depend on. This should be seen as the definitive list. Of course, there might be errors in that list – but that should be addressed by raising a bug against the module.

I’ve poked at this problem a few times, trying to work out how the RPM system parses the code and trying to replace that with code that looks at META.yml instead. But the RPM system uses a baroque system of interdependent macros and eventually they all lead to a piece of rather clunky Perl code. So each time I’ve approached this problem, I’ve backed off again.

The problem became more urgent when I wanted to package Plack for Fedora. Plack supports all sorts of hosting environments and therefore includes “use” statements loading a number of modules that most people will never use. Fedora includes Apache2, so Apache::Request (which is for Apache1) will never be available. It’s not listed in META.YML, but it is used by one of the modules. The RPM build system was therefore insisting that it should be present. An impasse was reached.

Then I decided to turn the problem on its head. RPM building has two steps. You create a spec file for the RPM and then you build the RPM using the spec file and your original tarball. I started wondering if I could ensure that the spec had all of the requirements (from the META.yml). Once I’d done that I would only need to find some way to turn off the RPM build system’s default behaviour.

People packaging CPAN modules for Fedora (and Centos) use a program called ‘cpanspec’ to generate spec files. I started digging into the code there in order to find out how to insert the list of correct dependencies.

Only to find that it has already been done. cpanspec is already doing the right thing and generating a list of ‘Requires’ statements from the data in META.yml.

Then all I needed to do was to see if I could turn off the (broken) default RPM build behaviour which was adding spurious extra dependencies. That proved to be easy too. It’s just a case of adding %__perl_requires %{nil} to your .rpmmacros files.

So now all of my RPMs will have only the correct dependencies listed. This makes me very happy.

I suppose I should go back and rebuild all of the older ones too.

Oh, and because I’ve worked out a really easy way to generate this – here’s a spreadsheet listing which CPAN modules are available as RPMs for Fedora. I plan to keep this list up to date (and make it much longer). [Link now fixed]

p.s. More about my trip to FOSDEM and the Perl marketing push there over the next couple of days.

5 thoughts on “Building RPMs from CPAN Distributions

  1. Where I bang my head is Fedora has a ton of Perl modules but RHEL has a scant few. It is maddening sometimes.
    Is there a process by which we can get Red Hat to move modules into the server realm as well?

  2. I find Centos (and, therefore, RHEL) unusable without additional repos. I use the EPEL which repackages Fedora RPMs for RHEL and its clones. I also find RPMForge useful, and there’s also my own repo.

  3. META.yml and Building RPMs

    An email has flooded in. It was in response to my piece about Building RPMs from CPAN Distributions and it was from Andreas Koenig. Andreas runs PAUSE, which is the service CPAN authors use to upload stuff to CPAN, so…

  4. The problem is that META.yml exists *only* for CPAN modules. RPM needs a general means to identify dependencies for all *.pl scripts. Hence the rather clunky means of using *RE’s applied to *.pl (and all #!/usr/bin/perl) scripts.
    But if all you wish is full control of deps in CPAN modules, disabling %__perl_requires and %__perl_provides and using META.yml to generate CPAN *.spec files will most definitely “work”. Just insufficiently general.

    1. >n3npq.jbj

      I don’t understand why you have to identify dependencies for all *.pl scripts to create RPMs. Fedora / CentOS packagers are building RPMs for Perl modules, all of which are CPAN modules. Some CPAN modules may contain *.pl scripts, but Perl developers won’t be importing those scripts.

Leave a Reply