miyagawa / cpanminus

cpanminus - get, unpack, build and install modules from CPAN
http://cpanmin.us
746 stars 213 forks source link

`Menlo::CLI::Compat`: `x_static_install` opt in regression between Perl 5.16 and 5.18 #668

Closed zmughal closed 9 months ago

zmughal commented 9 months ago

I'm not sure why this is happening, but I wanted to make sure it got recorded somewhere:

for v in 5.16 5.18; do
        docker run --rm -it perl:$v bash -c '
                cpanm -nq Menlo::CLI::Compat ;
                cpanm -nq --installdeps RDF::NS ;

                perl -MMenlo::CLI::Compat  -e '\''
                my $app = Menlo::CLI::Compat->new;
                $app->parse_options(@ARGV);
                $app->run;
                '\'' -- --verbose --test-only RDF::NS
                ';
done

Under the 5.16 Docker, the build fails because the share dir file prefix.cc is not copied:

Building and testing RDF-NS-20230619 ... cp lib/RDF/NS/Trine.pm blib/lib/RDF/NS/Trine.pm
cp lib/RDF/SN.pm blib/lib/RDF/SN.pm
cp lib/RDF/NS.pm blib/lib/RDF/NS.pm
cp lib/App/rdfns.pm blib/lib/App/rdfns.pm
cp lib/RDF/NS/URIS.pm blib/lib/RDF/NS/URIS.pm
t/compile.t ..... ok
t/history.t ..... Failed to find shared file 'prefix.cc' for dist 'RDF-NS' at /root/.cpanm/work/1695617964.3212/RDF-NS-20230619/blib/lib/RDF/NS.pm line 65.
t/history.t ..... Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t/namespaces.t .. Failed to find shared file 'prefix.cc' for dist 'RDF-NS' at /root/.cpanm/work/1695617964.3212/RDF-NS-20230619/blib/lib/RDF/NS.pm line 65.
t/namespaces.t .. Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t/prefix.t ...... Failed to find shared file 'prefix.cc' for dist 'RDF-NS' at /root/.cpanm/work/1695617964.3212/RDF-NS-20230619/blib/lib/RDF/NS.pm line 65.
t/prefix.t ...... Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t/rdfns.t ....... Failed to find shared file 'prefix.cc' for dist 'RDF-NS' at /root/.cpanm/work/1695617964.3212/RDF-NS-20230619/blib/lib/RDF/NS.pm line 65.
t/rdfns.t ....... Dubious, test returned 2 (wstat 512, 0x200)
No subtests run
t/trine.t ....... # RDF::Trine missing: 0 - skip tests of RDF::NS::Trine
t/trine.t ....... ok
t/uris.t ........ Failed to find shared file 'prefix.cc' for dist 'RDF-NS' at /root/.cpanm/work/1695617964.3212/RDF-NS-20230619/blib/lib/RDF/NS.pm line 65.
t/uris.t ........ Dubious, test returned 2 (wstat 512, 0x200)
No subtests run

while under 5.18 Docker, it is:

Building and testing RDF-NS-20230619 ... cp lib/RDF/NS.pm blib/lib/RDF/NS.pm
cp share/prefix.cc blib/lib/auto/share/dist/RDF-NS/prefix.cc
cp script/rdfns blib/script/rdfns
cp lib/RDF/SN.pm blib/lib/RDF/SN.pm
cp lib/App/rdfns.pm blib/lib/App/rdfns.pm
cp lib/RDF/NS/URIS.pm blib/lib/RDF/NS/URIS.pm
cp lib/RDF/NS/Trine.pm blib/lib/RDF/NS/Trine.pm
t/compile.t ..... ok
t/history.t ..... ok
t/namespaces.t .. ok
t/prefix.t ...... ok
t/rdfns.t ....... ok
t/trine.t ....... # RDF::Trine missing: 0 - skip tests of RDF::NS::Trine
t/trine.t ....... ok
t/uris.t ........ ok
All tests successful.

It appears that both the share/ and script/ directories are not being processed under Perl 5.16.

My current workaround is to use the --no-static-install flag.

Connects with https://github.com/kjetilk/URI-NamespaceMap/pull/19.

skaji commented 9 months ago

It seems that the following script prints "match" and "not match" on perl 5.16 or lower:

#!/usr/bin/env perl
use strict;
use warnings;

print( "x" =~ // ? "match\n" : "not match\n" );

my $module_name = "Foo-Bar";
$module_name =~ s/-/::/g;

print( "x" =~ // ? "match\n" : "not match\n" );

And this was changed in perl 5.18 (see https://github.com/Perl/perl5/issues/11549).


Due to this, qr// in find(qr//, 'share') at https://github.com/miyagawa/cpanminus/blob/devel/Menlo/lib/Menlo/Builder/Static.pm#L51 may be qr/-/ which is the successful pattern at https://github.com/miyagawa/cpanminus/blob/devel/Menlo-Legacy/lib/Menlo/CLI/Compat.pm#L1990

So Menlo::Builder::Static may not find share or script files on perl 5.16 or lower.

skaji commented 9 months ago

I think the following patch fixes this issue:

diff --git Menlo/lib/Menlo/Builder/Static.pm Menlo/lib/Menlo/Builder/Static.pm
index 574fbdf..73e4616 100644
--- Menlo/lib/Menlo/Builder/Static.pm
+++ Menlo/lib/Menlo/Builder/Static.pm
@@ -47,8 +47,8 @@ my %actions = (
    build => sub {
        my %opt = @_;
        my %modules = map { $_ => catfile('blib', $_) } find(qr/\.p(?:m|od)$/, 'lib');
-       my %scripts = map { $_ => catfile('blib', $_) } find(qr//, 'script');
-       my %shared  = map { $_ => catfile(qw/blib lib auto share dist/, $opt{meta}->name, abs2rel($_, 'share')) } find(qr//, 'share');
+       my %scripts = map { $_ => catfile('blib', $_) } find(qr/(?^:)/, 'script');
+       my %shared  = map { $_ => catfile(qw/blib lib auto share dist/, $opt{meta}->name, abs2rel($_, 'share')) } find(qr/(?^:)/, 'share');
        pm_to_blib({ %modules, %scripts, %shared }, catdir(qw/blib lib auto/));
        make_executable($_) for values %scripts;
        mkpath(catdir(qw/blib arch/), $opt{verbose});
miyagawa commented 9 months ago

This code is a copy/fork of Module::Build::Tiny so it would be best to fix there first.