From 2e6f1ae9c4f7857e86f85fde07fe1af1254c4600 Mon Sep 17 00:00:00 2001 From: David Mitchell Date: Fri, 7 Apr 2017 12:39:53 +0100 Subject: [PATCH] fix and test execution of non-empty .bs files During the build of XS modules, an empty Foo.bs file is normally created for each Foo.so file. If a Foo_BS file is present, instead this triggers the auto-generatation of a .bs file which may have executable perl content. However, nothing in core currently generates a non-empty .bs file. So add a test that this mechanism works, and fix up the three dynamic lib loaders which implement the 'do $bs if -s $bs' mechanism to not rely on the process having '.' present in @INC. As it happens this already works currently, because the name of the .bs file to load will usually be something like ../../lib/auto/Foo/Foo.bs and the presence of the leading '..' causes 'do' to load the file directly rather than via @INC. But locally fix up @INC anyway, in case '../' isn't always the case. --- MANIFEST | 2 ++ dist/XSLoader/XSLoader_pm.PL | 4 ++-- ext/DynaLoader/DynaLoader_pm.PL | 4 ++-- ext/XS-APItest/APItest_BS | 7 +++++++ ext/XS-APItest/t/bootstrap.t | 17 +++++++++++++++++ win32/ce-helpers/makedist.pl | 1 + 6 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 ext/XS-APItest/APItest_BS create mode 100644 ext/XS-APItest/t/bootstrap.t diff --git a/MANIFEST b/MANIFEST index 185766cbb5f2..ebad534a42ec 100644 --- a/MANIFEST +++ b/MANIFEST @@ -4189,6 +4189,7 @@ ext/Win32CORE/Win32CORE.c Win32CORE extension ext/Win32CORE/Win32CORE.pm Win32CORE extension (stubs for Win32 CORE subs) ext/XS-APItest/APItest.pm XS::APItest extension ext/XS-APItest/APItest.xs XS::APItest extension +ext/XS-APItest/APItest_BS autogenerate APItest.bs ext/XS-APItest/core.c Test API functions when PERL_CORE is defined ext/XS-APItest/core_or_not.inc Code common to core.c and notcore.c ext/XS-APItest/exception.c XS::APItest extension @@ -4203,6 +4204,7 @@ ext/XS-APItest/t/Block.pm Helper for ./blockhooks.t ext/XS-APItest/t/blockasexpr.t test recursive descent block parsing ext/XS-APItest/t/blockhooks.t XS::APItest: tests for PL_blockhooks ext/XS-APItest/t/blockhooks-csc.t XS::APItest: more tests for PL_blockhooks +ext/XS-APItest/t/bootstrap.t XS::APItest: test APItest.bs ext/XS-APItest/t/call.t Test calling perl from C ext/XS-APItest/t/call_checker.t test call checker plugin API ext/XS-APItest/t/caller.t XS::APItest: tests for caller_cx diff --git a/dist/XSLoader/XSLoader_pm.PL b/dist/XSLoader/XSLoader_pm.PL index ddf68f8818d4..8012e35e3214 100644 --- a/dist/XSLoader/XSLoader_pm.PL +++ b/dist/XSLoader/XSLoader_pm.PL @@ -11,7 +11,7 @@ print OUT <<'EOT'; package XSLoader; -$VERSION = "0.26"; +$VERSION = "0.27"; #use strict; @@ -145,7 +145,7 @@ print OUT <<'EOT'; if (-s $bs) { # only read file if it's not empty # print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug; - eval { do $bs; }; + eval { local @INC = ('.'); do $bs; }; warn "$bs: $@\n" if $@; goto \&XSLoader::bootstrap_inherit; } diff --git a/ext/DynaLoader/DynaLoader_pm.PL b/ext/DynaLoader/DynaLoader_pm.PL index 24c8bea36c12..bd9562582247 100644 --- a/ext/DynaLoader/DynaLoader_pm.PL +++ b/ext/DynaLoader/DynaLoader_pm.PL @@ -85,7 +85,7 @@ package DynaLoader; # Tim.Bunce@ig.co.uk, August 1994 BEGIN { - $VERSION = '1.41'; + $VERSION = '1.42'; } EOT @@ -373,7 +373,7 @@ sub bootstrap { $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; # look for .bs 'beside' the library if (-s $bs) { # only read file if it's not empty print STDERR "BS: $bs ($^O, $dlsrc)\n" if $dl_debug; - eval { do $bs; }; + eval { local @INC = ('.'); do $bs; }; warn "$bs: $@\n" if $@; } diff --git a/ext/XS-APItest/APItest_BS b/ext/XS-APItest/APItest_BS new file mode 100644 index 000000000000..270dc9c682f5 --- /dev/null +++ b/ext/XS-APItest/APItest_BS @@ -0,0 +1,7 @@ +# +# test that non-empty .bs files get executed + +$bscode = <<'EOF'; +$::bs_file_got_executed = 1; +EOF + diff --git a/ext/XS-APItest/t/bootstrap.t b/ext/XS-APItest/t/bootstrap.t new file mode 100644 index 000000000000..6992b108505a --- /dev/null +++ b/ext/XS-APItest/t/bootstrap.t @@ -0,0 +1,17 @@ +#!perl -w +# +# check that .bs files are loaded and executed. +# During build of XS::APItest, the presence of APItest_BS should +# cause a non-empty APItest.bs file to auto-generated. When loading +# APItest.so, the .bs should be automatically executed, which should +# set $::bs_file_got_executed. + +use strict; + +use Test::More; +use XS::APItest; + +is $::bs_file_got_executed, 1, "BS file was executed"; + +done_testing(); + diff --git a/win32/ce-helpers/makedist.pl b/win32/ce-helpers/makedist.pl index 2ad0f70c9fb0..daf4f3e96c44 100644 --- a/win32/ce-helpers/makedist.pl +++ b/win32/ce-helpers/makedist.pl @@ -237,6 +237,7 @@ sub bootstrap { my $bs = $file; $bs =~ s/(\.\w+)?(;\d*)?$/\.bs/; if (-s $bs) { # only read file if it's not empty + local @INC = ('.'); do $bs; warn "$bs: $@\n" if $@; }