Skip to content

Commit

Permalink
Make life easier for packagers with BUILDING_AS_PACKAGE
Browse files Browse the repository at this point in the history
Also README.packaging and bundled/README.
  • Loading branch information
schwern committed Oct 26, 2011
1 parent ae3e30d commit 78f8c8b
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 8 deletions.
6 changes: 6 additions & 0 deletions Changes
Expand Up @@ -7,6 +7,12 @@
* my::bundle::copy_bundles() will only load File::Copy::Recursive if * my::bundle::copy_bundles() will only load File::Copy::Recursive if
it needs it, allowing vendors packaging MakeMaker to just delete it needs it, allowing vendors packaging MakeMaker to just delete
bundled/* bundled/*
* Bundling can be overridden by setting the BUILDING_AS_PACKAGE
environment variable. This makes life easier for vendor packagers.

Docs
* README.packaging explains how to package MakeMaker
* bundled/README explains what the bundled directory is about.




6.63_01 Sun Oct 23 16:57:24 PDT 2011 6.63_01 Sun Oct 23 16:57:24 PDT 2011
Expand Down
33 changes: 29 additions & 4 deletions Makefile.PL
Expand Up @@ -18,6 +18,8 @@ use lib qw(lib); # build ourself with ourself
use File::Spec; use File::Spec;
use ExtUtils::MakeMaker 6.50; use ExtUtils::MakeMaker 6.50;


my $BUILDING_AS_PACKAGE = $ENV{BUILDING_AS_PACKAGE};

BEGIN { BEGIN {
die "You have File::Spec version $File::Spec::VERSION\n" . "ExtUtils::MakeMaker requires File::Spec >= 0.8 to build at all.\n" die "You have File::Spec version $File::Spec::VERSION\n" . "ExtUtils::MakeMaker requires File::Spec >= 0.8 to build at all.\n"
if $File::Spec::VERSION < 0.8; if $File::Spec::VERSION < 0.8;
Expand Down Expand Up @@ -46,19 +48,42 @@ CHANGE_WARN
# Test::Harnesses prior to 2.00 shoved all of @INC onto the command line # Test::Harnesses prior to 2.00 shoved all of @INC onto the command line
# when a test had -T. This made it too long. So we need a Test::Harness # when a test had -T. This made it too long. So we need a Test::Harness
# > 2.00 on VMS for t/testlib.t # > 2.00 on VMS for t/testlib.t
my %prereq = (); my %Extra_Prereqs = ();
$prereq{'Test::Harness'} = 2.00 if $^O eq 'VMS'; $Extra_Prereqs{'Test::Harness'} = 2.00 if $^O eq 'VMS';


check_environment(); check_environment();


my::bundles::copy_bundles("bundled", "inc"); # Special case for MakeMaker being built as a vendor package
if( $BUILDING_AS_PACKAGE ) {
# Some of these are lower than what we bundle. That's ok, we
# bundle the latest because we might as well, but we don't want to
# burden vendors with having to update everything.
%Extra_Prereqs = (
'CPAN::Meta' => '2.112580',
'CPAN::Meta::YAML' => '0.002',
'ExtUtils::Command' => '1.16',
'ExtUtils::Install' => '1.52',
'ExtUtils::Manifest' => '1.58',
'File::Temp' => '0.22',
'JSON::PP' => '2.27103',
'Parse::CPAN::Meta' => '1.4400',
'Scalar::Util' => '1.13',
'version' => '0.82',
'Version::Requirements' => '0.101020',
);

$Extra_Prereqs{'JSON::PP::Compat5006'} = '1.09' if $] < 5.008;
}
else {
my::bundles::copy_bundles("bundled", "inc");
}


my $MM = WriteMakefile( my $MM = WriteMakefile(
NAME => $PACKAGE, NAME => $PACKAGE,
VERSION_FROM => "lib/$PACKAGE_FILE.pm", # finds $VERSION VERSION_FROM => "lib/$PACKAGE_FILE.pm", # finds $VERSION


PREREQ_PM => { PREREQ_PM => {
%prereq, %Extra_Prereqs,
'File::Spec' => 0.8, # splitpath(), rel2abs() 'File::Spec' => 0.8, # splitpath(), rel2abs()
'Pod::Man' => 0, # manifypods needs Pod::Man 'Pod::Man' => 0, # manifypods needs Pod::Man
'File::Basename' => 0, 'File::Basename' => 0,
Expand Down
23 changes: 23 additions & 0 deletions README.packaging
@@ -0,0 +1,23 @@
If you wish to package MakeMaker in a binary package, here's some tips.

tl;dr version:

1a) Set the BUILDING_AS_PACKAGE environment variable to a true value.
OR
1b) Set the $BUILDING_AS_PACKAGE variable in the Makefile.PL to true.
2) Package normally, but watch out for dependency loops.

MakeMaker cannot have any dependencies, everything depends on it and
that would be a dependency loop. It instead bundles pre-built copies
of all its non-core dependencies in the bundled/ directory. It adds
them to itself if they're not already installed.

This can confuse packagers, it makes it look like MakeMaker contains a
lot more modules than it really does and causes conflicts.

You can tell MakeMaker not to use it's bundles and instead declare the
dependencies normally. This is done either by setting the
BUILDING_AS_PACKAGE environment variable to true or by patching the
Makefile.PL and setting $BUILDING_AS_PACKAGE to true. On the down
side, there will be dependency loops which your packaging system will
have to resolve.
5 changes: 5 additions & 0 deletions bundled/README
@@ -0,0 +1,5 @@
This directory contains CPAN modules which ExtUtils-MakeMaker depends on.
They are bundled with ExtUtils-MakeMaker to avoid dependency loops.

Vendor packages will want to disable this bundling. See README.packaging in the top
level directory for details.
14 changes: 10 additions & 4 deletions my/bundles.pm
Expand Up @@ -3,6 +3,8 @@ package my::bundles;
use strict; use strict;
use warnings; use warnings;


use File::Path;



=head1 NAME =head1 NAME
Expand All @@ -28,11 +30,8 @@ inc/ as a flattened module directory that MakeMaker can install.
=cut =cut


require lib;
my $bundle_dir = "bundled"; my $bundle_dir = "bundled";


use File::Path;

my %special_dist = ( my %special_dist = (
"Scalar-List-Utils" => sub { "Scalar-List-Utils" => sub {
# Special case for Scalar::Util, never override the XS version with a # Special case for Scalar::Util, never override the XS version with a
Expand All @@ -47,16 +46,23 @@ my %special_dist = (
); );




sub import { sub add_bundles_to_inc {
opendir my $dh, $bundle_dir or die "Can't open bundles directory: $!"; opendir my $dh, $bundle_dir or die "Can't open bundles directory: $!";
my @bundles = map { "$bundle_dir/$_" } grep !/^\./, readdir $dh; my @bundles = map { "$bundle_dir/$_" } grep !/^\./, readdir $dh;

require lib;
lib->import(@bundles); lib->import(@bundles);

return;
} }




sub copy_bundles { sub copy_bundles {
my($src, $dest) = @_; my($src, $dest) = @_;


# So we can use them to copy them.
add_bundles_to_inc();

rmtree $dest; rmtree $dest;
mkpath $dest; mkpath $dest;


Expand Down

0 comments on commit 78f8c8b

Please sign in to comment.