Hack 60. Rebuild Your Distributions


Rebuild your distributions with ease.

If you work with Perl modules built in the standard CPAN format (and you should, as the many available tools make your life easier this way), you generally will have a Makefile.PL or Build.PL file, lib/ and t/ directories, manifests, and so on. If the module uses ExtUtils::MakeMaker, you change your tests, update the module and rebuild the distribution again with a command such as:

$ make realclean && perl Makefile.PL && make && make test          

Modules that use Module::Build require instead:

$ ./Build realclean && perl Build.PL && perl ./Build && perl ./Build test          

It gets annoying typing this over and over again. Worse, if you do this for patches you send to others, you might forget and assume you have a Makefile when using Module::Build or a Build file when using ExtUtils::MakeMaker. This is tiresome.

The Hack

Instead, put this rebuild script in your path and set the appropriate permissions:

#!/bin/bash if [ -f Build.PL ]; then     makeprog=Build     makecommand="perl ./Build" elif [ -f Makefile.PL ]; then     makeprog=Makefile     makecommand=make else     echo Nothing to reload!     exit 1 fi if [ -f $makeprog ]; then     $makecommand realclean fi perl $makeprog.PL && $makecommand && $makecommand test

Running the Hack

Whenever you want to rebuild your project, type rebuild at the command line in the parent directory of the project and don't worry about whether you're using Module::Build or ExtUtils::MakeMaker.

Hacking the Hack

If you really want to get carried away, bash scripts put their command line arguments in variables named $1, $2, and so on. It's trivial to add extra commands to build your distribution, your manifest, or whatever else you like:

if [ "$1" = dist ]; then     $makecommand dist fi



Perl Hacks
Perl Hacks: Tips & Tools for Programming, Debugging, and Surviving
ISBN: 0596526741
EAN: 2147483647
Year: 2004
Pages: 141

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net