Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version range warning #260

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
7.11_06

Enhancements:
- Warn if use version range but no specify minimum EUMM >= 7.11_01

7.11_05 Sat Mar 19 09:41:02 GMT 2016

Bug fixes:
Expand Down
39 changes: 34 additions & 5 deletions lib/ExtUtils/MakeMaker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ our @EXPORT_OK = qw($VERSION &neatvalue &mkbootstrap &mksymlists
&WriteEmptyMakefile &open_for_writing &write_file_via_tmp
&_sprintf562);

my @PREREQ_KEYS = qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES);

# These will go away once the last of the Win32 & VMS specific code is
# purged.
my $Is_VMS = $^O eq 'VMS';
Expand Down Expand Up @@ -425,6 +427,28 @@ sub _has_cpan_meta_requirements {
};
}

sub _min_EUMM {
my ($self) = @_;
my $cr = ($self->{CONFIGURE_REQUIRES} && $self->{CONFIGURE_REQUIRES}{'ExtUtils::MakeMaker'});
return $cr if $cr;
my @meta_versions = sort grep defined, map {
(exists $_->{prereqs} and
exists $_->{prereqs}{configure} and
exists $_->{prereqs}{configure}{requires})
? $_->{prereqs}{configure}{requires}{'ExtUtils::MakeMaker'}
: ()
} grep $_, @{$self}{qw(META_ADD META_MERGE)};
return 0 unless @meta_versions;
$meta_versions[0] || 0;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$self->{CONFIGURE_REQUIRES} && $self->{CONFIGURE_REQUIRES}{'ExtUtils::MakeMaker'} || 0


sub _got_version_ranges {
my ($self) = @_;
my @all_versions = map values %$_, grep defined, @{$self}{@PREREQ_KEYS};
return 0 unless @all_versions;
grep /[^v\d\._]/, @all_versions;
}

sub new {
my($class,$self) = @_;
my($key);
Expand All @@ -444,9 +468,13 @@ sub new {

# Cleanup all the module requirement bits
my %key2cmr;
for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) {
my $has_cpan_meta_requirements = _has_cpan_meta_requirements;
warn "Warning: version range without prerequisite of EUMM >= 7.11_01"
if $has_cpan_meta_requirements and $self->_min_EUMM < 7.1101
and $self->_got_version_ranges;
for my $key (@PREREQ_KEYS) {
$self->{$key} ||= {};
if (_has_cpan_meta_requirements) {
if ($has_cpan_meta_requirements) {
my $cmr = CPAN::Meta::Requirements->from_string_hash(
$self->{$key},
{
Expand Down Expand Up @@ -551,14 +579,14 @@ END
my $cmr;
if (_has_cpan_meta_requirements) {
$cmr = CPAN::Meta::Requirements->new;
for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) {
for my $key (@PREREQ_KEYS) {
$cmr->add_requirements($key2cmr{$key}) if $key2cmr{$key};
}
foreach my $prereq ($cmr->required_modules) {
$prereq2version{$prereq} = $cmr->requirements_for_module($prereq);
}
} else {
for my $key (qw(PREREQ_PM BUILD_REQUIRES CONFIGURE_REQUIRES TEST_REQUIRES)) {
for my $key (@PREREQ_KEYS) {
next unless my $module2version = $self->{$key};
$prereq2version{$_} = $module2version->{$_} for keys %$module2version;
}
Expand Down Expand Up @@ -2681,7 +2709,8 @@ A hash of modules that are needed to run your module. The keys are
the module names ie. Test::More, and the minimum version is the
value. If the required version number is 0 any version will do.
The versions given may be a Perl v-string (see L<version>) or a range
(see L<CPAN::Meta::Requirements>).
(see L<CPAN::Meta::Requirements>). If you give a range, you need to
specify a minimum EUMM of at least C<7.11_01> in C<CONFIGURE_REQUIRES>.

This will go into the C<requires> field of your F<META.yml> and the
C<runtime> of the C<prereqs> field of your F<META.json>.
Expand Down
48 changes: 44 additions & 4 deletions t/prereq.t
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ BEGIN {

use strict;
use Config;
use Test::More tests => 21;
use Test::More tests => 24;
use File::Temp qw[tempdir];

use TieOut;
Expand Down Expand Up @@ -57,7 +57,7 @@ ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
is $warnings, '', 'basic prereq';

SKIP: {
skip 'No CMR, no version ranges', 1
skip 'No CMR, no version ranges', 4
unless ExtUtils::MakeMaker::_has_cpan_meta_requirements;
$warnings = '';
WriteMakefile(
Expand All @@ -66,15 +66,55 @@ ok( chdir 'Big-Dummy', "chdir'd to Big-Dummy" ) ||
strict => '>= 0, <= 99999',
}
);
is $warnings, '', 'version range';
isnt $warnings, '', 'version range, no min EUMM specified';

$warnings = '';
WriteMakefile(
NAME => 'Big::Dummy',
PREREQ_PM => {
strict => '>= 0, <= 99999',
},
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => '7.04',
},
);
isnt $warnings, '', 'version range and insufficient EUMM specified';

$warnings = '';
WriteMakefile(
NAME => 'Big::Dummy',
PREREQ_PM => {
strict => '>= 0, <= 99999',
},
CONFIGURE_REQUIRES => {
'ExtUtils::MakeMaker' => 7.11_01,
},
);
is $warnings, '', 'version range and sufficient EUMM specified';

$warnings = '';
WriteMakefile(
NAME => 'Big::Dummy',
PREREQ_PM => {
strict => '>= 0, <= 99999',
},
META_MERGE => {
prereqs => {
configure => {
requires => { 'ExtUtils::MakeMaker' => 7.1101 },
},
},
},
);
is $warnings, '', 'version range and sufficient EUMM specified meta';
}

$warnings = '';
WriteMakefile(
NAME => 'Big::Dummy',
PREREQ_PM => {
strict => 99999
}
},
);
is $warnings,
sprintf("Warning: prerequisite strict 99999 not found. We have %s.\n",
Expand Down
3 changes: 2 additions & 1 deletion t/vstrings.t
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ sub capture_make {

WriteMakefile(
NAME => 'VString::Test',
PREREQ_PM => { $package , $version }
PREREQ_PM => { $package , $version },
CONFIGURE_REQUIRES => { 'ExtUtils::MakeMaker' => 7.1101 },
);

return $warnings;
Expand Down