rschupp / PAR-Packer

(perl) Generate stand-alone executables, perl scripts and PAR files https://metacpan.org/pod/PAR::Packer
Other
48 stars 13 forks source link

pp does not automatically copy resource files from module distribution #44

Closed hakonhagland closed 3 years ago

hakonhagland commented 3 years ago

Hi. Consider this script:

#! /usr/bin/env perl

use strict;
use warnings;
use Mojo::Util;
print "Test Mojo\n";

if I pack this script with:

$ pp -x -c test.pl

and then run the generated executable (Ubuntu 21.04, perl version 5.32.0):

$ ./a.out
Unable to open html entities file (/tmp/par-68616b6f6e/cache-4ffe784165f1ecd36682b1718fe84200a6f323bc/inc/lib/Mojo/resources/html_entities.txt): No such file or directory at script/test.pl line 5.
Compilation failed in require at script/test.pl line 5.
BEGIN failed--compilation aborted at script/test.pl line 5.

See this question on stackoverflow.com for more information.

The problem seems to be that the file Mojo/resources/html_entities.txt was not included in the archive. Is this a bug, or is it expected behavior?

rschupp commented 3 years ago

Is this a bug, or is it expected behavior?

Both :smile: PAR::Packer uses Module::ScanDeps to determine what to pack. In general, Module::ScanDeps only considers Perl source files, i.e. anything acquired via use, require or do. Even that may fail, e.g. if the require target is not a literal string, but evaluated at runtime. That's why there's pp -x ... where we look into %INC after the script has been run to find out what was actually loaded. Unfortunately, there's no standard Perl mechanism how to acquire non-Perl "resource" files (so every CPAN distribution rolls their own) and also no registry like %INC.

Module::ScanDeps has builtin rules for some well known modules to pack their resource files, e.g. the Unicode tables in the Perl core. I just added a rule for the above file. You may retry packing your script after installing Module::ScanDeps from HEAD.

leandrocombr commented 3 years ago

Hello,

apache@node68196 ~/webroot $ cpan -D Module::ScanDeps
Reading '/var/www/.cpan/Metadata'
  Database was generated on Thu, 13 May 2021 18:29:02 GMT
Module::ScanDeps
-------------------------------------------------------------------------
        (no description)
        R/RS/RSCHUPP/Module-ScanDeps-1.31.tar.gz
        /usr/lib/perl5/site_perl/5.32.1/Module/ScanDeps.pm
        Installed: 1.31
        CPAN:      1.31  up to date
        Roderich Schupp (RSCHUPP)
        rschupp@cpan.org

The module was already installed and even then the error still persists.

apache@node68196 ~/webroot $ pp -x -c test.pl
/tmp/I3_yViYEbt syntax OK
apache@node68196 ~/webroot $ ./a.out
Unable to open html entities file (/tmp/par-617061636865/cache-2326ec06084336d46204f7cef6395a20a23dbd89/inc/lib/Mojo/resources/html_entities.txt): No such file or directory at script/test.pl line 8.
Compilation failed in require at script/test.pl line 8.
BEGIN failed--compilation aborted at script/test.pl line 8.
rschupp commented 3 years ago

You may retry packing your script after installing Module::ScanDeps from HEAD.

...not from CPAN, but from its GitHub repo HEAD, e.g.

cpanm git://github.com/rschupp/Module-ScanDeps.git
leandrocombr commented 3 years ago

Perfect!

It worked 100%, it solved the problem.

Thank you so much!

rschupp commented 3 years ago

Thanks for confirmation!