Author: dagolden
Date: Thu Nov 12 09:53:56 2009
New Revision: 13488
Added:
Module-Build/trunk/lib/Module/Build/Bundling.pod
- copied unchanged from r13487,
/Module-Build/branches/inc-bundling/lib/Module/Build/Bundling.pod
Module-Build/trunk/lib/inc/
- copied from r13487, /Module-Build/branches/inc-bundling/lib/inc/
Module-Build/trunk/lib/inc/latest/
- copied from r13487, /Module-Build/branches/inc-bundling/lib/inc/latest/
Module-Build/trunk/lib/inc/latest.pm
- copied unchanged from r13487,
/Module-Build/branches/inc-bundling/lib/inc/latest.pm
Module-Build/trunk/lib/inc/latest/private.pm
- copied unchanged from r13487,
/Module-Build/branches/inc-bundling/lib/inc/latest/private.pm
Module-Build/trunk/t/bundle_inc.t
- copied unchanged from r13487,
/Module-Build/branches/inc-bundling/t/bundle_inc.t
Removed:
Module-Build/trunk/contrib/bundle.pl
Module-Build/trunk/inc/latest.pm
Modified:
Module-Build/trunk/ (props changed)
Module-Build/trunk/Build.PL
Module-Build/trunk/Changes
Module-Build/trunk/MANIFEST
Module-Build/trunk/lib/Module/Build/Base.pm
Module-Build/trunk/t/lib/DistGen.pm
Module-Build/trunk/t/properties/share_dir.t (props changed)
Log:
merged inc-bundling branch
Modified: Module-Build/trunk/Build.PL
==============================================================================
--- Module-Build/trunk/Build.PL (original)
+++ Module-Build/trunk/Build.PL Thu Nov 12 09:53:56 2009
@@ -35,6 +35,7 @@
'File::Path' => 0,
'File::Spec' => ($^O eq 'MSWin32' ? 3.30 : '0.82'), # rel2abs()
'ExtUtils::Install' => 0,
+ 'ExtUtils::Installed' => 0,
'ExtUtils::Manifest' => 0,
'ExtUtils::Mkbootstrap' => 0,
'IO::File' => 1.13, # fixes binmode bug on perl < 5.8.8
Modified: Module-Build/trunk/Changes
==============================================================================
--- Module-Build/trunk/Changes (original)
+++ Module-Build/trunk/Changes Thu Nov 12 09:53:56 2009
@@ -2,6 +2,11 @@
0.35_06 -
+ Enhancements:
+
+ - Added experimental inc/ bundling; see Module::Build::Bundling for
+ details. [David Golden and Eric Wilhelm]
+
Bug fixes:
- Made MYMETA generation non-fatal if fields required for META.yml
Modified: Module-Build/trunk/MANIFEST
==============================================================================
--- Module-Build/trunk/MANIFEST (original)
+++ Module-Build/trunk/MANIFEST Thu Nov 12 09:53:56 2009
@@ -1,7 +1,6 @@
Build.PL
Changes
contrib/bash_completion.module-build
-contrib/bundle.pl
INSTALL
lib/Module/Build.pm
lib/Module/Build/API.pod
Modified: Module-Build/trunk/lib/Module/Build/Base.pm
==============================================================================
--- Module-Build/trunk/lib/Module/Build/Base.pm (original)
+++ Module-Build/trunk/lib/Module/Build/Base.pm Thu Nov 12 09:53:56 2009
@@ -52,6 +52,8 @@
}
}
+ $self->set_bundle_inc;
+
$self->dist_name;
$self->dist_version;
$self->_guess_module_name unless $self->module_name;
@@ -862,6 +864,8 @@
__PACKAGE__->add_property(build_elements => [qw(PL support pm xs share_dir pod
script)]);
__PACKAGE__->add_property(build_script => 'Build');
__PACKAGE__->add_property(build_bat => 0);
+__PACKAGE__->add_property(bundle_inc => []);
+__PACKAGE__->add_property(bundle_inc_preload => []);
__PACKAGE__->add_property(config_dir => '_build');
__PACKAGE__->add_property(include_dirs => []);
__PACKAGE__->add_property(license => 'unknown');
@@ -1214,6 +1218,68 @@
$self->{phash}{$_}->write() foreach qw(notes cleanup features auto_features
config_data runtime_params);
}
+{
+ # packfile map -- keys are guts of regular expressions; If they match,
+ # values are module names corresponding to the packlist
+ my %packlist_map = (
+ '^File::Spec' => 'Cwd',
+ '^Devel::AssertOS' => 'Devel::CheckOS',
+ );
+
+ sub _find_packlist {
+ my ($self, $inst, $mod) = @_;
+ my $lookup = $mod;
+ my $packlist = eval { $inst->packlist($lookup) };
+ if ( ! $packlist ) {
+ # try from packlist_map
+ while ( my ($re, $new_mod) = each %packlist_map ) {
+ if ( $mod =~ qr/$re/ ) {
+ $lookup = $new_mod;
+ $packlist = eval { $inst->packlist($lookup) };
+ last;
+ }
+ }
+ }
+ return $packlist ? $lookup : undef;
+ }
+
+ sub set_bundle_inc {
+ my $self = shift;
+ my $bundle_inc = $self->{properties}{bundle_inc};
+ my $bundle_inc_preload = $self->{properties}{bundle_inc_preload};
+ # We're in author mode if inc::latest is loaded, but not from cwd
+ return unless inc::latest->can('loaded_modules');
+ require ExtUtils::Installed;
+ # ExtUtils::Installed is buggy about finding additions to default @INC
+ my $inst = ExtUtils::Installed->new(extra_libs => [$self->_added_to_INC]);
+ my @bundle_list = map { [ $_, 0 ] } inc::latest->loaded_modules;
+
+ # XXX TODO: Need to get ordering of prerequisites correct so they are
+ # are loaded in the right order. Use an actual tree?!
+
+ while( @bundle_list ) {
+ my ($mod, $prereq) = @{ shift @bundle_list };
+
+ # XXX TODO: Append prereqs to list
+ # skip if core or already in bundle or preload lists
+ # push @bundle_list, [$_, 1] for prereqs()
+
+ # Locate packlist for bundling
+ my $lookup = $self->_find_packlist($inst,$mod);
+ if ( ! $lookup ) {
+ # XXX Really needs a more helpful error message here
+ die << "NO_PACKLIST";
+Could not find a packlist for '$mod'. If it's a core module, try
+force installing it from CPAN.
+NO_PACKLIST
+ }
+ else {
+ push @{ $prereq ? $bundle_inc_preload : $bundle_inc }, $lookup;
+ }
+ }
+ } # sub check_bundling
+}
+
sub check_autofeatures {
my ($self) = @_;
my $features = $self->auto_features;
@@ -1285,6 +1351,17 @@
$self->_add_prereq('configure_requires', 'Module::Build', $ver);
}
+ # if we're in author mode, add inc::latest modules to
+ # configure_requires if not already set. If we're not in author mode
+ # then configure_requires will have been satisfied, or we'll just
+ # live with what we've bundled
+ if ( inc::latest->can('loaded_module') ) {
+ for my $mod ( inc::latest->loaded_modules ) {
+ next if exists $p->{configure_requires}{$mod};
+ $self->_add_prereq('configure_requires', $mod, $mod->VERSION);
+ }
+ }
+
# If needs_compiler is not explictly set, automatically set it
# If set, we need ExtUtils::CBuilder (and a compiler)
my $xs_files = $self->find_xs_files;
@@ -3583,6 +3660,15 @@
}
}
+sub do_create_bundle_inc {
+ my $self = shift;
+ my $dist_inc = File::Spec->catdir( $self->dist_dir, 'inc' );
+ require inc::latest;
+ inc::latest->write($dist_inc, @{$self->bundle_inc_preload});
+ inc::latest->bundle_module($_, $dist_inc) for @{$self->bundle_inc};
+ return 1;
+}
+
sub ACTION_distdir {
my ($self) = @_;
@@ -3609,6 +3695,8 @@
my $new = $self->copy_if_modified(from => $file, to_dir => $dist_dir,
verbose => 0);
}
+ $self->do_create_bundle_inc if @{$self->bundle_inc};
+
$self->_sign_dir($dist_dir) if $self->{properties}{sign};
}
Modified: Module-Build/trunk/t/lib/DistGen.pm
==============================================================================
--- Module-Build/trunk/t/lib/DistGen.pm (original)
+++ Module-Build/trunk/t/lib/DistGen.pm Thu Nov 12 09:53:56 2009
@@ -91,6 +91,7 @@
my %data = (
no_manifest => 0,
xs => 0,
+ inc => 0,
%options,
);
%$self = %data;
@@ -143,17 +144,32 @@
$self->add_file($member, $data) unless($self->{filedata}{$member});
};
- $self->$add_unless('Build.PL', undent(<<" ---"));
- use strict;
- use Module::Build;
+ if ( ! $self->{inc} ) {
+ $self->$add_unless('Build.PL', undent(<<" ---"));
+ use strict;
+ use Module::Build;
- my \$builder = Module::Build->new(
- module_name => '$self->{name}',
- license => 'perl',
- );
+ my \$builder = Module::Build->new(
+ module_name => '$self->{name}',
+ license => 'perl',
+ );
- \$builder->create_build_script();
- ---
+ \$builder->create_build_script();
+ ---
+ }
+ else {
+ $self->$add_unless('Build.PL', undent(<<" ---"));
+ use strict;
+ use inc::latest 'Module::Build';
+
+ my \$builder = Module::Build->new(
+ module_name => '$self->{name}',
+ license => 'perl',
+ );
+
+ \$builder->create_build_script();
+ ---
+ }
my $module_filename =
join( '/', ('lib', split(/::/, $self->{name})) ) . '.pm';