Perl-Toolchain-Gang / module-build-tiny

A tiny replacement for Module::Build
10 stars 17 forks source link

t/simple.t fails on Windows Server 2022 #35

Open vrkosk opened 4 months ago

vrkosk commented 4 months ago

I'm using Perl 5.38, built from source using VS2019, on Windows Server 2022. Installing Module::Build::Tiny with:

cpanm Module::Build::Tiny@0.048

Fails with:

#   Failed test 'Script is installed'
#   at t/simple.t line 160.
# Looks like you failed 1 test of 27.
cannot unlink file for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib\arch\auto\Foo\Bar\Bar.dll: Permission denied at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib\arch\auto\Foo\Bar: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib\arch\auto\Foo: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib\arch\auto: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib\arch: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot unlink file for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib\script\simple: Permission denied at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib\script: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar\blib: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714476227.13640\Module-Build-Tiny-0.045\RIMzh2Acqo\Foo-Bar: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:/Users/villek/.cpanm/work/1714476227.13640/Module-Build-Tiny-0.045/RIMzh2Acqo: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
t/simple.t .. 
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/27 subtests 
    (less 1 skipped subtest: 25 okay)

Same thing happens if I run Build test manually. The file arch\auto\Foo\Bar\Bar.dll has been created and it has ordinary access permissions. In my experience, you sometimes get this kind of error if the file is open in a different process, or if File::Temp has a filehandle open to the file. I can't see where File::Temp is used in t/simple.t so must be somewhere else...

Fails in the same way with Module::Build::Tiny 0.045, 0.046, 0.047.

Leont commented 4 months ago

I've seen this sort of action before with an overly eager virus scanner, could that be the problem here?

Also, could you post the whole output of t/simple.t? This rather looks like some information is missing.

vrkosk commented 4 months ago

The above output is from running Build.bat test.

I have ESET Server Security enabled. I've tried pausing"the protection, which should disable real-time file scanning, and it doesn't make any difference.

Here's t/simple.t after installing Module::Build::Tiny (so I'm sure it has the right @INC):

C:Module-Build-Tiny-0.048>perl t\simple.t

compilet-wddna.c
   Creating library compilet.lib and object compilet.exp
Generating code
Finished generating code
Creating new 'Build' script for 'Foo-Bar' version '0.001'
ok 1 - Ran Build.PL
ok 2 - Build created
ok 3 - Build is executable
ok 4 - Build has shebang line with $^X
ok 5 - _build_params created
ok 6 - Could run Build
ok 7 - Build output looks correctly
ok 8 - created blib
ok 9 - created blib/lib
ok 10 - created blib/script
ok 11 - Foo::Bar copied to blib
ok 12 - pm contents are correct
ok 13 - pm file in blib is readonly
ok 14 - bin/simple copied to blib
ok 15 - blib/script/simple contents are correct
ok 16 - blib/script/simple is executable
ok 17 - script in blib is readonly
ok 18 - dist sharedir has been made
ok 19 - dist sharedir file has been made
ok 20 - moduole sharedir has been made
ok 21 - module sharedir file has been made
ok 22 - Dependency on Foo has been inserted
ok 23 - Can run XSub Foo::Bar::foo
ok 24 # skip No manification supported
ok 25 - Could run Build install
ok 26 - Build install output looks correctly
ok 27 - Module is installed
not ok 28 - Script is installed
#   Failed test 'Script is installed'
#   at t\simple.t line 167.
1..28
# Looks like you failed 1 test of 28.
cannot unlink file for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib\arch\auto\Foo\Bar\Bar.dll: Permission denied at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib\arch\auto\Foo\Bar: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib\arch\auto\Foo: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib\arch\auto: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib\arch: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot unlink file for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib\script\simple: Permission denied at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib\script: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar\blib: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:\Users\villek\.cpanm\work\1714481826.12168\Module-Build-Tiny-0.048\zBv0t671Hb\Foo-Bar: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.
cannot remove directory for C:/Users/villek/.cpanm/work/1714481826.12168/Module-Build-Tiny-0.048/zBv0t671Hb: Directory not empty at C:/xyzzy/perl_538/lib/File/Temp.pm line 921.

There may be a genuine error that is unrelated to the above. Running simple.t in debugger and stopping at line 167 shows:

main::(t\simple.t:167):   ok( -f 'install/bin/simple', 'Script is installed');
  DB<2> x -f 'install/bin/simple'
0  undef
  DB<3> x -f catfile(qw(install bin simple))
0  undef

Working directory is:

DB<9> p Cwd::cwd()
C:/Users/villek/.cpanm/work/1714481826.12168/Module-Build-Tiny-0.048/j1Ijzjwb5C/Foo-Bar

And that directory has install\lib directory, but not install\bin. There is a file called 'simple' in Foo-Bar\script\simple -- is that the same file?

twata1 commented 1 month ago

I would suggest that it might be a good idea to try this after you get ExtUtils::InstallPaths version 0.012.

Leont commented 1 month ago

I've also observed this issue in Dist::Build. I guess that does confirm it's probably in their shared infrastructure (such as EU::IP).

There are two separate issues here. The first is that the 'Script is installed' test fails. This is a serious bug that I do not understand yet.

The second issue is that it can't remove the dll file because it's still loaded. I tried fixing that by explicitly unloading it but that doesn't seem like enough. I should try adding an additional sleep in there but other than that I don't really know what more to do.

twata1 commented 1 month ago

The second issue is that it can't remove the dll file because it's still loaded. I tried fixing that by explicitly unloading it but that doesn't seem like enough.

I find it hard to remove dll files on Windows. I am not sure why, since I have seen XS modules renamed after failing to remove dll files during make install. The following is a log of the make install portion of Scalar::ListUtils.

Running make install for PEVANS/Scalar-List-Utils-1.65.tar.gz
"C:\strawberry-perl-5.38.2.1-64bit-portable\perl\bin\perl.exe" -MExtUtils::Command::MM -e cp_nonempty -- Util.bs blib\arch\auto\List\Util\Util.bs 644
WARNING: Unable to unlink 'C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\auto\List\Util\Util.xs.dll': Permission denied

Going to try to rename it to 'C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\auto\List\Util\Util.xs.dll.AAA'.
Rename successful. Scheduling 'C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\auto\List\Util\Util.xs.dll.AAA'
for deletion at reboot.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
WARNING: MoveFileEx 'C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\auto\List\Util\Util.xs.dll.AAA' for deletion at reboot failed: Access is denied
You may try to perform the operation by hand yourself.
(You may need to close other perl processes first).
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Files found in blib\arch: installing files in blib\lib into architecture dependent library tree
Installing C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\auto\List\Util\Util.xs.dll
Installing C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\List\Util.pm
Installing C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\List\Util\XS.pm
Installing C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\Scalar\Util.pm
Installing C:\strawberry-perl-5.38.2.1-64bit-portable\perl\site\lib\Sub\Util.pm
Appending installation info to C:\strawberry-perl-5.38.2.1-64bit-portable\perl\lib/perllocal.pod
  PEVANS/Scalar-List-Utils-1.65.tar.gz
  C:\strawberry-perl-5.38.2.1-64bit-portable\c\bin\gmake.exe install UNINST=1 -- OK

C:\home\skyfish2>

I think the only way around this is to use some method of renaming the file in some way.

Thank you,

Leont commented 1 month ago

I think the only way around this is to use some method of renaming the file in some way.

Or I should leave it in the TMPDIR and leave removing it for the OS whenever it sees fit.

sisyphus commented 5 days ago

The failure of that final test (as illustrated in the initial post to this thread) occurs when $Config{installsitescript} is set to the empty string - which is the default setting. Strawberry Perl avoids this issue by taking steps to set $Config{installsitescript} to its desired location.

A quick fix for any existing perl afflicted by this issue is to set the "installsitescript" entry in Config_heavy.pl (which is located in perl's top level "lib" directory in most perls) to the desired value.

In the perl source, both win32/config.vc (yes, MSVC builds are also afflicted) and win32/config.gc specify the following:

installbin=       '~INST_TOP~~INST_VER~\bin~INST_ARCH~'
installsitebin=   '~INST_TOP~~INST_VER~\bin~INST_ARCH~'
installscript=    '~INST_TOP~~INST_VER~\bin'
installsitescript=''

(I've inserted some spaces in the above to hopefully improve readability.)

Since "installsitebin" and "installbin" are identical, the obvious thing to do is to make "installsitescript" the same as "installscript", (For scripts, we apparently ignore any "\~INST_ARCH\~" specification - which seems reasonable to me.) What do you think ?

With that fixed, t/simple.t will PASS - though the noise in relation to the failure to clean up the temporary folder still persists.

Leont commented 5 days ago

With that fixed, t/simple.t will PASS - though the noise in relation to the failure to clean up the temporary folder still persists.

Oh right, I forgot to fix that in the last release. Will look at it.

Leont commented 1 day ago

The tempdir issue should be fixed now.

sisyphus commented 1 day ago

The tempdir issue should be fixed now.

LGTM

sisyphus commented 1 day ago

As regards the failing test, I can see the following fallback in EU::MM_Any.pm:

    $self->{INSTALLSITESCRIPT} ||= '$(INSTALLSCRIPT)'
      unless $Config{installsitescript};

If that's visible to Windows (and I think it might be) then that could be the reason that this issue has not arisen before. Does Module::Build::Tiny not employ that safeguard ?

Leont commented 1 day ago

If that's visible to Windows (and I think it might be) then that could be the reason that this issue has not arisen before. Does Module::Build::Tiny not employ that safeguard ?

Module::Build contains something similar, but ExtUtils::InstallPaths doesn't. I had not thought it necessary on 5.8+ because it isn't on other platforms. I'm somewhat surprised no one reported this before TBH, I guess really everyone is running Strawberry on Windows.

sisyphus commented 1 day ago

I guess really everyone is running Strawberry on Windows

Yes, that would be it. They've been setting installsitescript for ages. There apparently aren't too many of us on Windows that are using a perl that we've built ourselves from source. And this was the first time that I had ever tried installing M::B::T.