Skip to content

Commit

Permalink
Revert commit 59c2e8, add test for PM_FILTER, fix RT-144085
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Mar 7, 2025
1 parent 3966577 commit 154730c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 28 deletions.
15 changes: 11 additions & 4 deletions .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,16 @@ skip_tags: true ## do not build on tags

environment:
matrix:
# this has dmake "Version 4.12 (Windows / MinGW)"
- Perl_VERSION: "5.12"
- Perl_VERSION: "5.10"
- Perl_VERSION: "5.8.9"
# these have dmake -V "Version 4.8-20070327-SHAY (Windows / MS Visual C++)"
# which appear to be broken with the PM_FILTER fix; when running `dmake`
# with EUMM's Makefile, it says
# "C:\strawberry\perl\bin\perl.exe" "-Iblib\arch" "-Iblib\lib" -MExtUtils::Command -e mkpath -- blib\lib\ExtUtils
# The system cannot find the path specified.
# dmake: Error code 129, while making 'blib\lib\ExtUtils\.exists'
# - Perl_VERSION: "5.10"
# - Perl_VERSION: "5.8.9"
global:
AUTOMATED_TESTING: 1
CI_CACHE_DIR: "C:\\cache"
Expand Down Expand Up @@ -130,12 +137,12 @@ before_build:

build_script:
- ps: ; write-host $("[{0:HH:mm:ss}].build.build_script" -f $($mark = get-date; $mark)) -f darkgray
- ps: . "${env:CI_HELPERS}\#build-build_script.PS1"
- dmake NOECHO=
- ps: ; write-host $("[{0:HH:mm:ss}].build.build_script ... done ({1:0.0}s)" -f $(get-date; $($(get-date) - $mark).totalseconds)) -f green

test_script:
- ps: ; write-host $("[{0:HH:mm:ss}].test.test_script" -f $($mark = get-date; $mark)) -f darkgray
- ps: . "${env:CI_HELPERS}\#test-test_script.PS1"
- dmake test NOECHO=
- ps: ; write-host $("[{0:HH:mm:ss}].test.test_script ... done ({1:0.0}s)" -f $(get-date; $($(get-date) - $mark).totalseconds)) -f green

after_test:
Expand Down
14 changes: 12 additions & 2 deletions lib/ExtUtils/MM_Any.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2499,6 +2499,10 @@ sub tools_other {
my($self) = shift;
my @m;

my $is_nmake = $self->is_make_type('nmake');
push @m, <<'EOF' if $is_nmake;
EUMM_NMAKE_HASH = ^# # to get hash character into strings - yes, horrible
EOF
# We set PM_FILTER as late as possible so it can see all the earlier
# on macro-order sensitive makes such as nmake.
for my $tool (qw{ SHELL CHMOD CP MV NOOP NOECHO RM_F RM_RF TEST_F TOUCH
Expand All @@ -2515,8 +2519,14 @@ sub tools_other {
CP_NONEMPTY
} )
{
next unless defined $self->{$tool};
push @m, "$tool = $self->{$tool}\n";
next unless defined(my $value = $self->{$tool});
# https://learn.microsoft.com/en-us/cpp/build/reference/contents-of-a-makefile?view=msvc-170#special-characters-in-a-makefile
if ($is_nmake) {
$value =~ s/#/\$(EUMM_NMAKE_HASH)/g
} else {
$value =~ s/#/\\#/g
}
push @m, "$tool = $value\n";
}

return join "", @m;
Expand Down
20 changes: 8 additions & 12 deletions lib/ExtUtils/MM_Unix.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2151,11 +2151,6 @@ sub init_PERL {
# already escaped spaces.
$self->{FULLPERL} =~ tr/"//d if $Is{VMS};

# `dmake` can fail for image (aka, executable) names which start with double-quotes
# * push quote inward by at least one character (or the drive prefix, if present)
# * including any initial directory separator preserves the `file_name_is_absolute` property
$self->{FULLPERL} =~ s/^"(\S(:\\|:)?)/$1"/ if $self->is_make_type('dmake');

# Little hack to get around VMS's find_perl putting "MCR" in front
# sometimes.
$self->{ABSPERL} = $self->{PERL};
Expand All @@ -2178,11 +2173,6 @@ sub init_PERL {
# already escaped spaces.
$self->{PERL} =~ tr/"//d if $Is{VMS};

# `dmake` can fail for image (aka, executable) names which start with double-quotes
# * push quote inward by at least one character (or the drive prefix, if present)
# * including any initial directory separator preserves the `file_name_is_absolute` property
$self->{PERL} =~ s/^"(\S(:\\|:)?)/$1"/ if $self->is_make_type('dmake');

# Are we building the core?
$self->{PERL_CORE} = $ENV{PERL_CORE} unless exists $self->{PERL_CORE};
$self->{PERL_CORE} = 0 unless defined $self->{PERL_CORE};
Expand Down Expand Up @@ -3201,11 +3191,17 @@ pm_to_blib : $(FIRST_MAKEFILE) $(TO_INST_PM)

# VMS will swallow '' and PM_FILTER is often empty. So use q[]
my $pm_to_blib = $self->oneliner(<<CODE, ['-MExtUtils::Install']);
pm_to_blib({\@ARGV}, '$autodir', q[\$(PM_FILTER)], '\$(PERM_DIR)')
\$i=0; \$i++ until \$i > \$#ARGV or \$ARGV[\$i] eq "--";
die "Failed to find -- in ".join("|",\@ARGV) if \$i > \$#ARGV;
\@parts=splice \@ARGV,0,\$i+1;
pop \@parts; \$filter=join " ", map qq{"\$_"}, \@parts;
pm_to_blib({\@ARGV}, '$autodir', \$filter, '\$(PERM_DIR)')
CODE
$pm_to_blib .= q[ $(PM_FILTER) --];

my @cmds = $self->split_command($pm_to_blib,
map { ($self->quote_literal($_) => $self->quote_literal($self->{PM}->{$_})) } sort keys %{$self->{PM}});
map +($self->quote_literal($_) => $self->quote_literal($self->{PM}{$_})),
sort keys %{$self->{PM}});

$r .= join '', map { "\t\$(NOECHO) $_\n" } @cmds;
$r .= qq{\t\$(NOECHO) \$(TOUCH) pm_to_blib\n};
Expand Down
13 changes: 4 additions & 9 deletions lib/ExtUtils/MakeMaker.pm
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@ END
} else {
my $value = $self->{$key};
# not going to test in FS so only stripping start
$value =~ s/"// if $key =~ /PERL$/ and $self->is_make_type('dmake');
$value =~ s/^"// if $key =~ /PERL$/;
$value = $self->catdir("..", $value)
unless $self->file_name_is_absolute($value);
Expand Down Expand Up @@ -2650,17 +2649,13 @@ to stdout) that is passed on each .pm file during the build (in the
pm_to_blib() phase). It is empty by default, meaning no filtering is done.
You could use:
PM_FILTER => 'perl -ne "print unless /^\\#/"',
PM_FILTER => 'perl -ne "print unless /^#/"',
to remove all the leading comments on the fly during the build. In order
to be as portable as possible, please consider using a Perl one-liner
rather than Unix (or other) utilities, as above. The # is escaped for
the Makefile, since what is going to be generated will then be:
PM_FILTER = perl -ne "print unless /^\#/"
Without the \ before the #, we'd have the start of a Makefile comment,
and the macro would be incorrectly defined.
rather than Unix (or other) utilities, as above. MakeMaker will escape the
C<#> for the Makefile, since what goes in the Makefile will depend on
which C<make> implementation is being targeted.
You will almost certainly be better off using the C<PL_FILES> system,
instead. See above, or the L<ExtUtils::MakeMaker::FAQ> entry.
Expand Down
14 changes: 13 additions & 1 deletion t/basic.t
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use ExtUtils::MM;
use Test::More
!MM->can_run(make()) && $ENV{PERL_CORE} && $Config{'usecrosscompile'}
? (skip_all => "cross-compiling and make not available")
: (tests => 195);
: (tests => 198);
use File::Find;
use File::Spec;
use File::Path;
Expand Down Expand Up @@ -472,6 +472,18 @@ $realclean_out = run("$make realclean");
rmtree 'Liar';
rmtree $DUMMYINST;

# test PM_FILTER - RT#144085
$text = $preserve_MPL;
ok(($text =~ s:\);: PM_FILTER => '\$(ABSPERLRUN) -ne "print unless /^#/"',\n$&:), 'successful M.PL edit');
write_file($file, $text);
@mpl_out = run(qq{$perl Makefile.PL});
$test_out = run("$make test NOECHO=");
like( $test_out, qr/All tests successful/, 'make test' );
is( $?, 0, ' exited normally' ) ||
diag $test_out;
write_file($file, $preserve_MPL); # restore Makefile.PL
$realclean_out = run("$make realclean");

sub _normalize {
my $hash = shift;
%$hash= map { lc($_) => $hash->{$_} } keys %$hash;
Expand Down

0 comments on commit 154730c

Please sign in to comment.