Skip to content

Commit ac301de

Browse files
fglockcodex
andcommitted
fix: preserve CPAN blibs for resumed tests
Store the CPAN-computed PERL5LIB in the build directory before make test runs, then have generated PerlOnJava Makefiles include it for future make test invocations. This keeps tested-but-not-installed dependency blibs visible when debugging or resuming a CPAN build outside the original jcpan process. Generated with [OpenAI Codex](https://openai.com/codex) Co-Authored-By: OpenAI Codex <codex@openai.com>
1 parent 624c0fd commit ac301de

3 files changed

Lines changed: 17 additions & 5 deletions

File tree

src/main/perl/lib/CPAN/Distribution.pm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3859,6 +3859,11 @@ sub test {
38593859
$self->debug("Changed directory to $self->{build_dir}")
38603860
if $CPAN::DEBUG;
38613861

3862+
if (open my $perlonjava_perl5lib_fh, ">", ".perlonjava-cpan-perl5lib") {
3863+
print {$perlonjava_perl5lib_fh} $ENV{PERL5LIB} || "";
3864+
close $perlonjava_perl5lib_fh;
3865+
}
3866+
38623867
if ($^O eq 'MacOS') {
38633868
Mac::BuildTools::make_test($self);
38643869
$self->post_test();

src/main/perl/lib/ExtUtils/MM_PerlOnJava.pm

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,16 +102,21 @@ sub test {
102102

103103
return '' unless $tests;
104104

105-
# Set PERL5LIB to add blib/lib and blib/arch to @INC for test subprocesses
105+
# Set PERL5LIB to add blib/lib and blib/arch to @INC for test subprocesses.
106+
# CPAN.pm also writes .perlonjava-cpan-perl5lib during jcpan test runs so
107+
# resumed/manual make test invocations keep tested-but-not-installed deps.
106108
# Test::Harness runs each test file as a subprocess, so we need PERL5LIB
107109
# Use "undef *Test::Harness::Switches" to disable the default -w switch,
108110
# matching standard ExtUtils::MakeMaker behavior (MM_Any::test_via_harness)
109111
return <<"MAKE_FRAG";
112+
PERLONJAVA_CPAN_PERL5LIB = \$(shell test -f .perlonjava-cpan-perl5lib && cat .perlonjava-cpan-perl5lib)
113+
PERLONJAVA_TEST_PERL5LIB = \$(INST_LIB):\$(INST_ARCHLIB):\$(PERLONJAVA_CPAN_PERL5LIB):\$\$PERL5LIB
114+
110115
test :: pure_all
111-
PERL5LIB="\$(INST_LIB):\$(INST_ARCHLIB):\$\$PERL5LIB" \$(FULLPERL) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests
116+
PERL5LIB="\$(PERLONJAVA_TEST_PERL5LIB)" \$(FULLPERL) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests
112117
113118
test_dynamic :: pure_all
114-
PERL5LIB="\$(INST_LIB):\$(INST_ARCHLIB):\$\$PERL5LIB" \$(FULLPERL) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests
119+
PERL5LIB="\$(PERLONJAVA_TEST_PERL5LIB)" \$(FULLPERL) "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(\$(TEST_VERBOSE), '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $tests
115120
116121
test_static ::
117122
\@echo "No static tests for PerlOnJava"

src/main/perl/lib/ExtUtils/MakeMaker.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,10 +603,10 @@ sub _create_install_makefile {
603603
} elsif ($test_glob) {
604604
# Use ExtUtils::Command::MM::test_harness with undef *Test::Harness::Switches
605605
# to disable the default -w switch, matching standard MakeMaker behavior
606-
$test_cmd = qq{PERL5LIB="\$(INST_LIB):\$(INST_ARCHLIB):\$\$PERL5LIB" $perl "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $test_glob};
606+
$test_cmd = qq{PERL5LIB="\$(PERLONJAVA_TEST_PERL5LIB)" $perl "-MExtUtils::Command::MM" "-MTest::Harness" "-e" "undef *Test::Harness::Switches; test_harness(0, '\$(INST_LIB)', '\$(INST_ARCHLIB)')" $test_glob};
607607
} elsif (-f 'test.pl') {
608608
# Legacy convention: some older CPAN dists use test.pl instead of t/*.t
609-
$test_cmd = qq{PERL5LIB="\$(INST_LIB):\$(INST_ARCHLIB):\$\$PERL5LIB" $perl test.pl};
609+
$test_cmd = qq{PERL5LIB="\$(PERLONJAVA_TEST_PERL5LIB)" $perl test.pl};
610610
} else {
611611
$test_cmd = qq{$perl -e "print qq{PerlOnJava: No tests found (no t/ directory)\\n}"};
612612
}
@@ -795,6 +795,8 @@ INST_LIB = $inst_lib
795795
INST_ARCHLIB = $inst_archlib
796796
INST_LIBDIR = \$(INST_LIB)
797797
INST_ARCHLIBDIR = \$(INST_ARCHLIB)
798+
PERLONJAVA_CPAN_PERL5LIB = \$(shell test -f .perlonjava-cpan-perl5lib && cat .perlonjava-cpan-perl5lib)
799+
PERLONJAVA_TEST_PERL5LIB = \$(INST_LIB):\$(INST_ARCHLIB):\$(PERLONJAVA_CPAN_PERL5LIB):\$\$PERL5LIB
798800
$siteprefix_var
799801
INSTALLSITELIB = $installsitelib
800802
NOECHO = \@

0 commit comments

Comments
 (0)