lib/Module/Build/t/ext.t Module::Build
lib/Module/Build/t/files.t Module::Build
lib/Module/Build/t/help.t Module::Build
+lib/Module/Build/t/install_extra_target.t Module::Build tests
lib/Module/Build/t/install.t Module::Build
lib/Module/Build/t/lib/DistGen.pm Module::Build
lib/Module/Build/t/lib/MBTest.pm Module::Build
'Module::Build' =>
{
'MAINTAINER' => 'kwilliams',
- 'DISTRIBUTION' => 'DAGOLDEN/Module-Build-0.340201.tar.gz',
+ 'DISTRIBUTION' => 'DAGOLDEN/Module-Build-0.35.tar.gz',
'FILES' => q[lib/Module/Build lib/Module/Build.pm],
'EXCLUDED' => [ qw{ t/par.t t/signature.t scripts/bundle.pl}, ],
'CPAN' => 1,
use vars qw($VERSION @ISA);
@ISA = qw(Module::Build::Base);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
# Okay, this is the brute-force method of finding out what kind of
This parameter determines whether Module::Build will add itself
automatically to configure_requires (and build_requires) if Module::Build
-is not already there. The default value is true.
+is not already there. The required version will be the last 'major' release,
+as defined by the decimal version truncated to two decimal places (e.g. 0.34,
+instead of 0.3402). The default value is true.
=item auto_features
(
module_name => 'Foo::Bar',
get_options => {
- loud => { store => \$loud },
- dbd => { type => '=s' },
- quantity => { type => '+' },
+ Loud => { store => \$loud },
+ Dbd => { type => '=s' },
+ Quantity => { type => '+' },
}
);
print STDERR "HEY, ARE YOU LISTENING??\n" if $loud;
- print "We'll use the ", $build->args('dbd'), " DBI driver\n";
+ print "We'll use the ", $build->args('Dbd'), " DBI driver\n";
print "Are you sure you want that many?\n"
- if $build->args('quantity') > 2;
+ if $build->args('Quantity') > 2;
The arguments for such a specification can be called like so:
- perl Build.PL --loud --dbd=DBD::pg --quantity --quantity --quantity
+ perl Build.PL --Loud --Dbd=DBD::pg --Quantity --Quantity --Quantity
B<WARNING:> Any option specifications that conflict with Module::Build's own
-options (defined by its properties) will throw an exception.
+options (defined by its properties) will throw an exception. Use capitalized
+option names to avoid unintended conflicts with future Module::Build options.
Consult the Getopt::Long documentation for details on its usage.
=item install_base()
-=item install_sets()
-
=item installdirs()
=item libdoc_dirs()
=item orig_dir()
-=item original_prefix()
-
=item perl()
=item pm_files()
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
BEGIN { require 5.00503 }
$self->dist_name;
$self->dist_version;
- $self->_set_install_paths;
$self->_find_nested_builds;
return $self;
$self->{invoked_action} = $self->{action} ||= 'build';
- $self->_set_install_paths;
-
return $self;
}
}
-sub _set_install_paths {
+# install paths must be generated when requested to be sure all changes
+# to config (from various sources) are included
+sub _default_install_paths {
my $self = shift;
my $c = $self->{config};
- my $p = $self->{properties};
+ my $p = {};
my @libstyle = $c->get('installstyle') ?
File::Spec->splitdir($c->get('installstyle')) : qw(lib perl5);
libhtml => ['html'],
},
};
-
+ return $p
}
sub _find_nested_builds {
sub _merge_arglist {
my( $self, $opts1, $opts2 ) = @_;
+ $opts1 ||= {};
+ $opts2 ||= {};
my %new_opts = %$opts1;
while (my ($key, $val) = each %$opts2) {
if ( exists( $opts1->{$key} ) ) {
my $outfile = File::Spec->catfile($mandir, $manpage);
next if $self->up_to_date( $file, $outfile );
$self->log_info("Manifying $file -> $outfile\n");
- $parser->parse_from_file( $file, $outfile );
+ eval { $parser->parse_from_file( $file, $outfile ); 1 }
+ or $self->log_warn("Error creating '$outfile': $@\n");
$files->{$file} = $outfile;
}
}
my $outfile = File::Spec->catfile( $mandir, $manpage);
next if $self->up_to_date( $file, $outfile );
$self->log_info("Manifying $file -> $outfile\n");
- $parser->parse_from_file( $file, $outfile );
+ eval { $parser->parse_from_file( $file, $outfile ); 1 }
+ or $self->log_warn("Error creating '$outfile': $@\n");
$files->{$file} = $outfile;
}
}
&& $self->auto_configure_requires
&& ! exists $prereq_types{'configure_requires'}{'Module::Build'}
) {
- $prereq_types{configure_requires}{'Module::Build'} = $VERSION;
+ (my $ver = $VERSION) =~ s/^(\d+\.\d\d).*$/$1/; # last major release only
+ $prereq_types{configure_requires}{'Module::Build'} = $ver;
}
for my $t ( keys %prereq_types ) {
$self->do_system($self->split_like_shell($self->{args}{tar}), $tar_flags, "$file.tar", $dir);
$self->do_system($self->split_like_shell($self->{args}{gzip}), "$file.tar") if $self->{args}{gzip};
} else {
- require Archive::Tar;
+ eval { require Archive::Tar && Archive::Tar->VERSION(1.08); 1 }
+ or die "You must install Archive::Tar to make a distribution tarball\n".
+ "or specify a binary tar program with the '--tar' option.\n".
+ "See the documentation for the 'dist' action.\n";
# Archive::Tar versions >= 1.09 use the following to enable a compatibility
# hack so that the resulting archive is compatible with older clients.
return $map->{$type} = $value;
}
+sub install_sets {
+ # Usage: install_sets('site'), install_sets('site', 'lib'),
+ # or install_sets('site', 'lib' => $value);
+ my ($self, $dirs, $key, $value) = @_;
+ $dirs = $self->installdirs unless defined $dirs;
+ # update property before merging with defaults
+ if ( @_ == 4 && defined $dirs && defined $key) {
+ # $value can be undef; will mask default
+ $self->{properties}{install_sets}{$dirs}{$key} = $value;
+ }
+ my $map = { $self->_merge_arglist(
+ $self->{properties}{install_sets},
+ $self->_default_install_paths->{install_sets}
+ )};
+ if ( defined $dirs && defined $key ) {
+ return $map->{$dirs}{$key};
+ }
+ elsif ( defined $dirs ) {
+ return $map->{$dirs};
+ }
+ else {
+ croak "Can't determine installdirs for install_sets()";
+ }
+}
+
+sub original_prefix {
+ # Usage: original_prefix(), original_prefix('lib'),
+ # or original_prefix('lib' => $value);
+ my ($self, $key, $value) = @_;
+ # update property before merging with defaults
+ if ( @_ == 3 && defined $key) {
+ # $value can be undef; will mask default
+ $self->{properties}{original_prefix}{$key} = $value;
+ }
+ my $map = { $self->_merge_arglist(
+ $self->{properties}{original_prefix},
+ $self->_default_install_paths->{original_prefix}
+ )};
+ return $map unless defined $key;
+ return $map->{$key}
+}
+
sub install_base_relpaths {
# Usage: install_base_relpaths(), install_base_relpaths('lib'),
# or install_base_relpaths('lib' => $value);
my $self = shift;
- my $map = $self->{properties}{install_base_relpaths};
+ if ( @_ > 1 ) { # change values before merge
+ $self->_set_relpaths($self->{properties}{install_base_relpaths}, @_);
+ }
+ my $map = { $self->_merge_arglist(
+ $self->{properties}{install_base_relpaths},
+ $self->_default_install_paths->{install_base_relpaths}
+ )};
return $map unless @_;
- return $self->_relpaths($map, @_);
+ my $relpath = $map->{$_[0]};
+ return defined $relpath ? File::Spec->catdir( @$relpath ) : undef;
}
-
-# Translated from ExtUtils::MM_Any::init_INSTALL_from_PREFIX
-sub prefix_relative {
- my ($self, $type) = @_;
- my $installdirs = $self->installdirs;
-
- my $relpath = $self->install_sets($installdirs)->{$type};
-
- return $self->_prefixify($relpath,
- $self->original_prefix($installdirs),
- $type,
- );
+# Defaults to use in case the config install paths cannot be prefixified.
+sub prefix_relpaths {
+ # Usage: prefix_relpaths('site'), prefix_relpaths('site', 'lib'),
+ # or prefix_relpaths('site', 'lib' => $value);
+ my $self = shift;
+ my $installdirs = shift || $self->installdirs
+ or croak "Can't determine installdirs for prefix_relpaths()";
+ if ( @_ > 1 ) { # change values before merge
+ $self->{properties}{prefix_relpaths}{$installdirs} ||= {};
+ $self->_set_relpaths($self->{properties}{prefix_relpaths}{$installdirs}, @_);
+ }
+ my $map = {$self->_merge_arglist(
+ $self->{properties}{prefix_relpaths}{$installdirs},
+ $self->_default_install_paths->{prefix_relpaths}{$installdirs}
+ )};
+ return $map unless @_;
+ my $relpath = $map->{$_[0]};
+ return defined $relpath ? File::Spec->catdir( @$relpath ) : undef;
}
-sub _relpaths {
+sub _set_relpaths {
my $self = shift;
- my( $map, $type, $value ) = ( @_, '<empty>' );
+ my( $map, $type, $value ) = @_;
Carp::croak( 'Type argument missing' )
unless defined( $type );
- my @value = ();
-
- # delete existing value if $value is literal undef()
- unless ( defined( $value ) ) {
- delete( $map->{$type} );
- return undef;
- }
-
- # return existing value if no new $value is given
- elsif ( $value eq '<empty>' ) {
- return undef unless exists $map->{$type};
- @value = @{ $map->{$type} };
+ # set undef if $value is literal undef()
+ if ( ! defined( $value ) ) {
+ $map->{$type} = undef;
+ return;
}
-
# set value if $value is a valid relative path
else {
Carp::croak( "Value must be a relative path" )
if File::Spec::Unix->file_name_is_absolute($value);
- @value = split( /\//, $value );
+ my @value = split( /\//, $value );
$map->{$type} = \@value;
}
-
- return File::Spec->catdir( @value );
}
-# Defaults to use in case the config install paths cannot be prefixified.
-sub prefix_relpaths {
- # Usage: prefix_relpaths('site'), prefix_relpaths('site', 'lib'),
- # or prefix_relpaths('site', 'lib' => $value);
- my $self = shift;
- my $installdirs = shift || $self->installdirs;
- my $map = $self->{properties}{prefix_relpaths}{$installdirs};
- return $map unless @_;
- return $self->_relpaths($map, @_);
-}
+# Translated from ExtUtils::MM_Any::init_INSTALL_from_PREFIX
+sub prefix_relative {
+ my ($self, $type) = @_;
+ my $installdirs = $self->installdirs;
+ my $relpath = $self->install_sets($installdirs)->{$type};
+
+ return $self->_prefixify($relpath,
+ $self->original_prefix($installdirs),
+ $type,
+ );
+}
# Translated from ExtUtils::MM_Unix::prefixify()
sub _prefixify {
Revision history for Perl extension Module::Build.
+0.35 - Thu Aug 27 09:12:02 EDT 2009
+
+ Bug fixes:
+ - Fix t/destinations.t segfault on 5.6.2
+
+0.34_06 - Sat Aug 22 21:58:26 EDT 2009
+
+ Bug fixes:
+ - Multiple test fixes for OS2 [Ilya Zakharevich]
+ - Generated.ppd files use :utf8 if possible (RT#48827) [Olivier Mengue]
+ - Fixed preservation of custom install_paths on resume (RT#41166)
+ [David Golden]
+ - Warn instead of crashing when Pod::Man tries to create files with
+ colons on vfat partitions on unix (RT#45544) [David Golden]
+
+0.34_05 - Sun Aug 9 22:31:37 EDT 2009
+
+ Bug fixes:
+ - When auto_configure_requires is true (the default), Module::Build will
+ only add last 'major' version of Module:Build (e.g. 0.XX) to
+ configure_requires to avoid specifying a minor development release not
+ available on CPAN [David Golden]
+
+0.34_04 - Sat Aug 8 11:02:24 EDT 2009
+
+ Other:
+ - Added documentation warning that 'get_options' should be capitalized
+ to avoid conflicting with future Module::Build options and changed
+ the examples accordingly.
+
+0.34_03 - Sat Aug 8 07:39:16 EDT 2009
+
+ Bug fixes:
+ - Fixed failing xs.t if /tmp is mounted noexec (RT#47331) [David Golden]
+ - Fixed failing debug.t on VMS (RT#48362) [Craig Berry]
+ - Prevent par.t from dying on error in .zip extraction [David Golden]
+ - Fixed potential runthrough.t failure on 5.6.2 [David Golden]
+
+ Other:
+ - Archive::Tar changed from 'requires' to 'recommends' so non-authors
+ without IO::Zlib can still use Module::Build to install modules
+ [reported by Matt Trout, fix by David Golden]
+
0.340201 - Sun Aug 9 22:11:04 EDT 2009
Other:
Bug-fixes:
- Bundled Module::Build::Version updated to bring into sync with CPAN
- version.pm 0.77
+ version.pm 0.77 [John Peacock]
0.34_01 - Sat Jul 18 16:32:09 EDT 2009
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
use File::Basename ();
use File::Spec;
my $unlink = $class->oneliner('1 while unlink $ARGV[0]', [], [$args{makefile}]);
$unlink =~ s/\$/\$\$/g unless $class->is_vmsish;
- my $maketext = <<"EOF";
+ my $maketext = ($^O eq 'os2' ? "SHELL = sh\n\n" : '');
+
+ $maketext .= <<"EOF";
all : force_do_it
$perl $Build
realclean : force_do_it
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Config;
package Module::Build::Cookbook;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
=head1 NAME
package Module::Build::Dumper;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
# This is just a split-out of a wrapper function to do Data::Dumper
# stuff "the right way". See:
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use File::Spec;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Data::Dumper;
use IO::File;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
# This code is mostly borrowed from ExtUtils::MM_Unix 6.10_03, with a
my $ppd_file = "$dist{name}.ppd";
my $fh = IO::File->new(">$ppd_file")
or die "Cannot write to $ppd_file: $!";
+ $fh->binmode(":utf8") if $fh->can("binmode");
print $fh $ppd;
close $fh;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use vars qw(@ISA);
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Base;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Config;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Platform::Unix;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Platform::Unix;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Platform::Unix;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use Module::Build::Platform::Unix;
use strict;
use vars qw($VERSION);
-$VERSION = '0.340201';
+$VERSION = '0.35';
$VERSION = eval $VERSION;
use vars qw(@ISA);
my %cleanup = map { $_ => 1 } $mb->cleanup;
is($cleanup{foo}, undef, "generated special file not added to cleanup");
-
+ $dist->chdir_original if $dist->did_chdir;
}
ok $err = $@, 'Should catch exception for invalid "installdirs" value';
like $err, qr/ERROR: installdirs must be one of "core", "site", or "vendor"/,
'And it should suggest the proper values in the error message';
+
+$dist->chdir_original if $dist->did_chdir;
my $libarch2 = File::Spec->catdir($libdir2, 'arch');
SKIP: {
+ my @cases = (
+ {
+ label => "INSTALLDIRS=vendor",
+ args => [ 'INSTALLDIRS=vendor', "INSTALLVENDORLIB=$libdir2", "INSTALLVENDORARCH=$libarch2"],
+ check => qr/\Q$libdir2\E .* Simple\.pm/ix,
+ },
+ {
+ label => "PREFIX=\$libdir2",
+ args => [ "PREFIX=$libdir2"],
+ check => qr/\Q$libdir2\E .* Simple\.pm/ix,
+ },
+ {
+ label => "PREFIX=\$libdir2 LIB=mylib",
+ args => [ "PREFIX=$libdir2", "LIB=mylib" ],
+ check => qr{\Q$libdir2\E[/\\]mylib[/\\]Simple\.pm}ix,
+ },
+ );
+
require ExtUtils::Install;
- skip "Needs ExtUtils::Install 1.32 or later", 2
+ skip "Needs ExtUtils::Install 1.32 or later", 2 * @cases
if ExtUtils::Install->VERSION < 1.32;
- my @make_args = ('INSTALLDIRS=vendor', "INSTALLVENDORLIB=$libdir2", "INSTALLVENDORARCH=$libarch2");
-
- if ($is_vms_mms) { # VMS MMK/MMS macros use different syntax.
- $make_args[0] = '/macro=("' . join('","',@make_args) . '")';
- pop @make_args while scalar(@make_args) > 1;
- }
-
- ($output) = stdout_stderr_of(
- sub {
- $ran_ok = $mb->do_system(@make, 'fakeinstall', @make_args);
+ for my $c (@cases) {
+ my @make_args = @{$c->{args}};
+ if ($is_vms_mms) { # VMS MMK/MMS macros use different syntax.
+ $make_args[0] = '/macro=("' . join('","',@make_args) . '")';
+ pop @make_args while scalar(@make_args) > 1;
}
- );
-
- ok $ran_ok, "make fakeinstall with INSTALLDIRS=vendor ran ok";
- $output =~ s/^/# /gm; # Don't confuse our own test output
- like $output,
- qr/\Q$libdir2\E .* Simple\.pm/ix,
- 'Should have installdirs=vendor';
+ ($output) = stdout_stderr_of(
+ sub {
+ $result = $mb->run_perl_script('Makefile.PL', [], \@make_args);
+ $ran_ok = $mb->do_system(@make, 'fakeinstall');
+ }
+ );
+
+ ok $ran_ok, "fakeinstall $c->{label} ran ok";
+ $output =~ s/^/# /gm; # Don't confuse our own test output
+ like $output, $c->{check},
+ "Saw destination directory for $c->{label}";
+ }
}
stdout_of( sub { $mb->do_system(@make, 'realclean'); } );
# Test debug output
{
my $output;
- $output = stdout_of sub {
- Module::Build->run_perl_script('Build.PL', [], [])
- };
- $output = stdout_of sub {
- Module::Build->run_perl_script('Build', [], ['--debug'])
- };
+ $output = stdout_of sub { $dist->run_build_pl };
+ $output = stdout_of sub { $dist->run_build('--debug') };
like($output, '/Starting ACTION_build.*?Starting ACTION_code.*?Finished ACTION_code.*?Finished ACTION_build/ms',
"found nested ACTION_* debug statements"
);
}
# Poke at the innards of MB to change the default install locations.
- local $mb->install_sets->{site} = \%test_config;
+ my $old = $mb->install_sets->{site} = \%test_config;
$mb->config(siteprefixexp => catdir(File::Spec->rootdir,
'wierd', 'prefix'));
my $prefix = catdir('another', 'prefix');
$mb->prefix($prefix);
test_prefix($prefix, \%test_config);
+ $mb->install_sets->{site} = $old;
}
my $restart = sub {
$dist->clean();
- chdir( $cwd );
+ DistGen::chdir_all( $cwd );
File::Path::rmtree( $tmp );
# we're redefining the same package as we go, so...
delete($::{'MyModuleBuilder::'});
# cleanup
$dist->clean();
-chdir( $cwd );
+DistGen::chdir_all($cwd);
File::Path::rmtree( $tmp );
# vim:ts=2:sw=2:et:sta
--- /dev/null
+#!perl -w
+# Contributed by: Thorben Jaendling
+
+use strict;
+use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
+use MBTest tests => 8;
+
+require_ok 'Module::Build';
+ensure_blib('Module::Build');
+
+use File::Spec::Functions qw( catdir );
+
+my $tmp = MBTest->tmpdir;
+my $output;
+
+use DistGen;
+my $dist = DistGen->new( dir => $tmp );
+
+# note("Dist is in $tmp\n");
+
+$dist->add_file("Build.PL", <<'===EOF===');
+#!perl -w
+
+use strict;
+use Module::Build;
+
+my $subclass = Module::Build->subclass(code => <<'=EOF=');
+sub copy_files
+{
+ my $self = shift;
+ my $dir = shift;
+
+ my $files = $self->rscan_dir($dir, sub {-f $_ and not m!/\.|[#~]$!});
+
+ foreach my $file (@$files) {
+ $self->copy_if_modified(from => $file, to_dir => "blib");
+ }
+}
+
+#Copy etc files to blib
+sub process_etc_files
+{
+ my $self = shift;
+
+ $self->copy_files("etc");
+}
+
+#Copy share files to blib
+sub process_share_files
+{
+ my $self = shift;
+
+ $self->copy_files("share");
+}
+
+1;
+=EOF=
+
+my $build = $subclass->new(
+ module_name => 'Simple',
+ license => 'perl'
+);
+
+$build->add_build_element('etc');
+$build->add_build_element('share');
+
+my $distdir = lc $build->dist_name();
+
+foreach my $id ('core', 'site', 'vendor') {
+ #Where to install these build types when using prefix symantics
+ $build->prefix_relpaths($id, 'share' => "share/$distdir");
+ $build->prefix_relpaths($id, 'etc' => "etc/$distdir");
+
+ #Where to install these build types when using default symantics
+ my $set = $build->install_sets($id);
+ $set->{'share'} = '/usr/'.($id eq 'site' ? 'local/':'')."share/$distdir";
+ $set->{'etc'} = ($id eq 'site' ? '/usr/local/etc/':'/etc/').$distdir;
+}
+
+#Where to install these types when using install_base symantics
+$build->install_base_relpaths('share' => "share/$distdir");
+$build->install_base_relpaths('etc' => "etc/$distdir");
+
+$build->create_build_script();
+
+===EOF===
+
+#Test Build.PL exists ok?
+
+$dist->add_file("etc/config", <<'===EOF===');
+[main]
+Foo = bar
+Jim = bob
+
+[supplemental]
+stardate = 1234344
+
+===EOF===
+
+$dist->add_file("share/data", <<'===EOF===');
+7 * 9 = 42?
+
+===EOF===
+
+$dist->add_file("share/html/index.html", <<'===EOF===');
+<HTML>
+ <BODY>
+ <H1>Hello World!</H1>
+ </BODY>
+</HTML>
+
+===EOF===
+
+$dist->regen;
+$dist->chdir_in;
+
+my $installdest = catdir($tmp, 't', "install_extra_targets-$$");
+
+$output = stdout_of sub { $dist->run_build_pl("--install_base=$installdest") };
+
+$output .= stdout_of sub { $dist->run_build };
+
+my $error;
+$error++ unless ok(-e "blib/etc/config", "Built etc/config");
+$error++ unless ok(-e "blib/share/data", "Built share/data");
+$error++ unless ok(-e "blib/share/html/index.html", "Built share/html");
+diag "OUTPUT:\n$output" if $error;
+
+$output = stdout_of sub { $dist->run_build('install') };
+
+$error = 0;
+$error++ unless ok(-e "$installdest/etc/simple/config", "installed etc/config");
+$error++ unless ok(-e "$installdest/share/simple/data", "installed share/data");
+$error++ unless ok(-e "$installdest/share/simple/html/index.html", "installed share/html");
+diag "OUTPUT:\n$output" if $error;
+
+$dist->remove();
return($string);
}
+
+sub chdir_all ($) {
+ # OS/2 has "current directory per disk", undeletable;
+ # doing chdir() to another disk won't change cur-dir of initial disk...
+ chdir('/') if $^O eq 'os2';
+ chdir shift;
+}
########################################################################
sub new {
$options{dir} ||= Cwd::cwd();
my %data = (
- skip_manifest => 0,
+ no_manifest => 0,
xs => 0,
%options,
);
my $real_filename = $self->_real_filename( $file );
my $fullname = File::Spec->catfile( $dist_dirname, $real_filename );
if ( -e $fullname ) {
- 1 while unlink( $fullname );
+ 1 while unlink( $fullname );
}
print "Unlinking pending file '$file'\n" if $VERBOSE;
delete( $self->{pending}{remove}{$file} );
my $real_filename = $self->_real_filename( $file );
my $fullname = File::Spec->catfile( $dist_dirname, $real_filename );
- if ( ! -e $fullname ||
- ( -e $fullname && $self->{pending}{change}{$file} ) ) {
+ if ( ! -e $fullname ||
+ ( -e $fullname && $self->{pending}{change}{$file} ) ) {
print "Changed file '$file'.\n" if $VERBOSE;
}
my $manifest = File::Spec->catfile( $dist_dirname, 'MANIFEST' );
- unless ( $self->{skip_manifest} ) {
+ unless ( $self->{no_manifest} ) {
if ( -e $manifest ) {
1 while unlink( $manifest );
}
}
}, ($^O eq 'VMS' ? './' : File::Spec->curdir) );
- chdir( $here );
+ chdir_all( $here );
}
sub remove {
croak("never called chdir_in()") unless($self->{original_dir});
my $dir = $self->{original_dir};
- chdir($dir) or die "Can't chdir to '$dir': $!";
+ chdir_all($dir) or die "Can't chdir to '$dir': $!";
}
########################################################################
+sub run_build_pl {
+ my ($self, @args) = @_;
+ require Module::Build;
+ Module::Build->run_perl_script('Build.PL', [], [@args])
+}
+
+sub run_build {
+ my ($self, @args) = @_;
+ require Module::Build;
+ my $build_script = $^O eq 'VMS' ? 'Build.com' : 'Build';
+ Module::Build->run_perl_script($build_script, [], [@args])
+}
+
1;
__END__
use DistGen;
- my $dist = DistGen->new(dir => $tmp);
- ...
+ # create distribution and prepare to test
+ my $dist = DistGen->new(name => 'Foo::Bar', dir => $tmp);
+ $dist->regen;
+ $dist->chdir_in;
+
+ # change distribution files
$dist->add_file('t/some_test.t', $contents);
- ...
+ $dist->change_file('MANIFEST.SKIP', $new_contents);
+ $dist->remove_file('t/some_test.t');
$dist->regen;
- chdir($dist->dirname) or
- die "Cannot chdir to '@{[$dist->dirname]}': $!";
- ...
+ # clean up extraneous files
$dist->clean;
- ...
- chdir($cwd) or die "cannot return to $cwd";
+
+ # exercise the command-line interface
+ $dist->run_build_pl();
+ $dist->run_build('test');
+
+ # finish testing and clean up
+ $dist->chdir_original;
$dist->remove;
+=head1 USAGE
+
+A DistGen object manages a set of files in a distribution directory.
+
+The constructor and some methods only define the target state of the
+distribution. They do B<not> make any changes to the filesystem:
+
+ new
+ add_file
+ change_file
+ change_build_pl
+ remove_file
+
+Other methods then change the filesystem to match the target state of
+the distribution (or to remove it entirely):
+
+ regen
+ clean
+ remove
+
+Other methods are provided for a convenience during testing. The
+most important are ones that manage the current directory:
+
+ chdir_in
+ chdir_original
+
+Additional methods portably encapsulate running Build.PL and Build:
+
+ run_build_pl
+ run_build
+
=head1 API
=head2 Constructor
my $tmp = MBTest->tmpdir;
my $dist = DistGen->new(
- name => 'Foo::Bar',
- dir => $tmp,
- xs => 1,
+ name => 'Foo::Bar',
+ dir => $tmp,
+ xs => 1,
+ no_manifest => 0,
);
The parameters are as follows.
If true, generates an XS based module.
+=item no_manifest
+
+If true, C<regen()> will not create a MANIFEST file.
+
=back
-=head2 Manipulating the Distribution
+The following files are added as part of the default distribution:
-These methods immediately affect the filesystem.
+ Build.PL
+ lib/Simple.pm # based on name parameter
+ t/basic.t
-=head3 regen()
+If an XS module is generated, Simple.pm and basic.t are different and
+the following files are also added:
-Regenerate all missing or changed files.
+ typemap
+ lib/Simple.xs # based on name parameter
- $dist->regen(clean => 1);
+=head2 Adding and editing files
-If the optional C<clean> argument is given, it also removes any
-extraneous files that do not belong to the distribution.
+Note that C<$filename> should always be specified with unix-style paths,
+and are relative to the distribution root directory, e.g. C<lib/Module.pm>.
-=head2 chdir_in
+No changes are made to the filesystem until the distribution is regenerated.
-Change directory into the dist root.
+=head3 add_file()
- $dist->chdir_in;
+Add a $filename containing $content to the distribution.
-=head2 chdir_original
+ $dist->add_file( $filename, $content );
-Returns to whatever directory you were in before chdir_in() (regardless
-of the cwd.)
+=head3 change_file()
- $dist->chdir_original;
+Changes the contents of $filename to $content. No action is performed
+until the distribution is regenerated.
+
+ $dist->change_file( $filename, $content );
+
+=head3 change_build_pl()
+
+A wrapper around change_file specifically for setting Build.PL. Instead
+of file C<$content>, it takes a hash-ref of Module::Build constructor
+arguments:
+
+ $dist->change_build_pl(
+ {
+ module_name => $dist->name,
+ dist_version => '3.14159265',
+ license => 'perl',
+ create_readme => 1,
+ }
+ );
+
+=head3 get_file
+
+Retrieves the target contents of C<$filename>.
+
+ $content = $dist->get_file( $filename );
+
+=head3 remove_file()
+
+Removes C<$filename> from the distribution.
+
+ $dist->remove_file( $filename );
+
+=head2 Changing the distribution directory
+
+These methods immediately affect the filesystem.
+
+=head3 regen()
+
+Regenerate all missing or changed files. Also deletes any files
+flagged for removal with remove_file().
+
+ $dist->regen(clean => 1);
+
+If the optional C<clean> argument is given, it also removes any
+extraneous files that do not belong to the distribution.
=head3 clean()
Removes the entire distribution directory.
-=head2 Editing Files
+=head2 Changing directories
-Note that C<$filename> should always be specified with unix-style paths,
-and are relative to the distribution root directory, e.g. C<lib/Module.pm>.
+=head3 chdir_in
-No filesystem action is performed until the distribution is regenerated.
+Change directory into the dist root.
-=head3 add_file()
+ $dist->chdir_in;
-Add a $filename containing $content to the distribution.
+=head3 chdir_original
- $dist->add_file( $filename, $content );
+Returns to whatever directory you were in before chdir_in() (regardless
+of the cwd.)
-=head3 remove_file()
+ $dist->chdir_original;
-Removes C<$filename> from the distribution.
+=head2 Command-line helpers
- $dist->remove_file( $filename );
+These use Module::Build->run_perl_script() to ensure that Build.PL or Build are
+run in a separate process using the current perl interpreter. (Module::Build
+is loaded on demand). They also ensure appropriate naming for operating
+systems that require a suffix for Build.
-=head3 change_file()
+=head3 run_build_pl
-Changes the contents of $filename to $content. No action is performed
-until the distribution is regenerated.
+Runs Build.PL using the current perl interpreter. Any arguments are
+passed on the command line.
- $dist->change_file( $filename, $content );
+ $dist->run_build_pl('--quiet');
+
+=head3 run_build
+
+Runs Build using the current perl interpreter. Any arguments are
+passed on the command line.
+
+ $dist->run_build(qw/test --verbose/);
=head2 Properties
Returns the name of the distribution.
+ $dist->name: # e.g. Foo::Bar
+
=head3 dirname()
Returns the directory where the distribution is created.
# Setup a temp directory
sub tmpdir {
+ my ($self, $usr_tmp) = @_;
return File::Temp::tempdir( 'MB-XXXXXXXX',
- CLEANUP => 1, DIR => $ENV{PERL_CORE} ? Cwd::cwd : File::Spec->tmpdir
+ CLEANUP => 1, DIR => $ENV{PERL_CORE} ? Cwd::cwd :
+ $usr_tmp ? $usr_tmp : File::Spec->tmpdir
);
}
my $have_c_compiler;
stderr_of( sub {$have_c_compiler = $mb->have_c_compiler} );
- return ($have_c_compiler, $mb->feature('C_support'));
+ # check noexec tmpdir
+ my $tmp_exec;
+ if ( $have_c_compiler ) {
+ my $dir = MBTest->tmpdir;
+ my $c_file = File::Spec->catfile($dir,'test.c');
+ open my $fh, ">", $c_file;
+ print {$fh} "int main() { return 0; }\n";
+ close $fh;
+ my $exe = $mb->cbuilder->link_executable(
+ objects => $mb->cbuilder->compile( source => $c_file )
+ );
+ $tmp_exec = 0 == system( $exe );
+ }
+ return ($have_c_compiler, $mb->feature('C_support'), $tmp_exec);
}
sub have_module {
{
my $mb_prereq = { 'Module::Build' => $Module::Build::VERSION };
+ my $mb_config_req = {
+ 'Module::Build' => int($Module::Build::VERSION * 100)/100
+ };
my $node = $mb->prepare_metadata( {} );
# exists() doesn't seem to work here
is $node->{abstract}, $metadata{dist_abstract};
is_deeply $node->{author}, $metadata{dist_author};
is $node->{license}, $metadata{license};
- is_deeply $node->{configure_requires}, $mb_prereq, 'Add M::B to configure_requires';
+ is_deeply $node->{configure_requires}, $mb_config_req, 'Add M::B to configure_requires';
like $node->{generated_by}, qr{Module::Build};
ok defined( $node->{'meta-spec'}{version} ),
"'meta-spec' -> 'version' field present in META.yml";
skip( 'YAML_support feature is not enabled', 4 )
unless Module::Build::ConfigData->feature('YAML_support');
- my $dist = DistGen->new( dir => $tmp, skip_manifest => 1 );
+ my $dist = DistGen->new( dir => $tmp, no_manifest => 1 );
$dist->regen;
$dist->chdir_in;
use DistGen;
my $dist = DistGen->new( dir => $tmp );
-$dist->remove_file( 't/basic.t' );
$dist->change_build_pl
({
module_name => 'Simple',
#!perl -w
print "Hello, World!\n";
---
-$dist->add_file( 'test.pl', <<'---' );
-#!/usr/bin/perl
-
-use Test;
-plan tests => 2;
-
-ok 1;
-
-require Module::Build;
-skip $ENV{PERL_CORE} && "no blib in core",
- $INC{'Module/Build.pm'}, qr/blib/, 'Module::Build should be loaded from blib';
-
-print "# Cwd: ", Module::Build->cwd, "\n";
-print "# \@INC: (@INC)\n";
-print "Done.\n"; # t/compat.t looks for this
----
$dist->add_file( 'lib/Simple/Script.PL', <<'---' );
#!perl -w
unless ($all_ok) {
# We use diag() so Test::Harness doesn't get confused.
- diag("vvvvvvvvvvvvvvvvvvvvv Simple/test.pl output vvvvvvvvvvvvvvvvvvvvv");
+ diag("vvvvvvvvvvvvvvvvvvvvv Simple/t/basic.t output vvvvvvvvvvvvvvvvvvvvv");
diag($output);
- diag("^^^^^^^^^^^^^^^^^^^^^ Simple/test.pl output ^^^^^^^^^^^^^^^^^^^^^");
+ diag("^^^^^^^^^^^^^^^^^^^^^ Simple/t/basic.t output ^^^^^^^^^^^^^^^^^^^^^");
}
}
cmp_ok $1, '==', $mb->VERSION, "Check version used to create META.yml: $1 == " . $mb->VERSION;
SKIP: {
- skip( "not sure if we can create a tarball on this platform", 1 )
- unless $mb->check_installed_version('Archive::Tar', 0) ||
- $mb->isa('Module::Build::Platform::Unix');
-
+ skip( "Archive::Tar 1.08+ not installed", 1 )
+ unless eval { require Archive::Tar && Archive::Tar->VERSION(1.08); 1 };
$mb->add_to_cleanup($mb->dist_dir . ".tar.gz");
eval {$mb->dispatch('dist')};
is $@, '';
my $yml = YAML::LoadFile('META.yml');
is_deeply($yml->{provides}, \%meta_provides);
}
+$dist->chdir_original if $dist->did_chdir;
is( run_sample( $p => '~/foo' )->$p(), "$home/foo" );
- is( run_sample( $p => '~~' )->$p(), '~~' );
-
- is( run_sample( $p => '~ foo' )->$p(), '~ foo' );
-
is( run_sample( $p => '~/ foo')->$p(), "$home/ foo" );
is( run_sample( $p => '~/fo o')->$p(), "$home/fo o" );
$mb->$p('~');
is( $mb->$p(), '~', 'API does not expand tildes' );
+
+ skip "On OS/2 EMX all users are equal", 2 if $^O eq 'os2';
+ is( run_sample( $p => '~~' )->$p(), '~~' );
+ is( run_sample( $p => '~ foo' )->$p(), '~ foo' );
}
# Again, with named users
use lib $ENV{PERL_CORE} ? '../lib/Module/Build/t/lib' : 't/lib';
use MBTest 'no_plan';
+use DistGen;
+use Cwd;
use_ok 'Module::Build';
ensure_blib 'Module::Build';
{
+ my $cwd = Cwd::cwd;
chdir MBTest->tmpdir();
my $build = Module::Build->new(
like $have, qr/^\Q$head\E/, "default MANIFEST.SKIP used";
like $have, qr/^# Avoid Module::Build generated /ms, "Module::Build specific entries";
like $have, qr/Foo-Bar-/, "distribution tarball entry";
+
+ DistGen::chdir_all($cwd);
}
use Module::Build;
use Config;
+my $tmp;
+
{
- my ($have_c_compiler, $C_support_feature) = check_compiler();
+ my ($have_c_compiler, $C_support_feature, $tmp_exec) = check_compiler();
if (! $C_support_feature) {
plan skip_all => 'C_support not enabled';
} else {
plan tests => 23;
}
+ require Cwd;
+ $tmp = MBTest->tmpdir( $tmp_exec ? undef : Cwd::cwd );
}
ensure_blib('Module::Build');
#########################
-
-my $tmp = MBTest->tmpdir;
-
use DistGen;
my $dist = DistGen->new( dir => $tmp, xs => 1 );
$dist->regen;