Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hakonhagland opened this issue May 12, 2021 · 5 comments
Closed

Comments

@hakonhagland
Copy link

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
Copy link
Owner

rschupp commented May 12, 2021

Is this a bug, or is it expected behavior?

Both 😄 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
Copy link

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)
        [email protected]

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
Copy link
Owner

rschupp commented May 13, 2021

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

@rschupp rschupp reopened this May 13, 2021
@leandrocombr
Copy link

Perfect!

It worked 100%, it solved the problem.

Thank you so much!

@rschupp rschupp closed this as completed May 14, 2021
@rschupp
Copy link
Owner

rschupp commented May 14, 2021

Thanks for confirmation!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Dec 18, 2023
1.35  2023-11-05

- massive speed up, esp. for scripts using stuff from
  the Moose ecosystem, thanks to @shawnlaffan:

  - add package level caches for INC searches (_find_in_inc, _glob_in_inc)
  - faster add_deps on case insensitive systems AKA Windows

1.34  2023-09-24

- Fix issue #19 (AKA rschupp/PAR-Packer#78): invalid paths in zip file

  - Restore behaviour from version 1.31 when using "pp --execute ..." or
    "scandeps.pl --execute ...".

    When using "scan_deps(execute => 1, ...)", %INC as gleaned from
    running the script must be sanitized. Contrary to documentation
    "The  key  is the filename you specified (with module names
    converted to pathnames)" %INC *may* contain keys that are
    *absolute pathnames* (or start with "./relativ/path" when
    "relative/path" is in @path). Examples are autosplitted modules
    (for autosplit.ix and *.al files). pp will pack these absolute
    paths into the zip (Archive::Zip doesn't complain) which
    results in strange error messages when the packed executable
    tries to unpack them under CACHEDIR/inc on Windows.

    Add t/19-autosplit.t to test for this.
    Add IPC::Run3 to TEST_REQUIRES, used in t/19-autosplit.t

- Add GitHub CI

1.33  2023-08-04

- Recognize Moose/Moo/Mouse style inheritance ("extends")
  or composition ("with") statements.

- Add %Preload entries for known dependants of XS::Parse::Keyword.

  Note: XS::Parse::Keyword is loaded from XS code, grep.metacpan.org
  for calls of boot_xs_parse_keyword() in *.xs files.

1.32  2023-07-05

- Ensure $inc gets removed from the start of $File::Find::name

  On Windows, if $inc contains backslashes then it won't always get removed
  from the start of $File::Find::name because the latter may be canonicalized
  to only contain forward slashes.

- Provide dedicated test scripts for some tests instead of using
  the test scripts themselves: Test::More draws in all kinds of stuff,
  totally unpredictable

- Rewrite test helpers in t/Utils.pm to use Test::More's subtest feature

- Code cleanup; fix detection of 'do STRING' (cf PR #15)

- scandeps.pl:  sort items in "used by" column

- Handle spaces after quote operator, e.g. eval qq {Some::Module}

- Fixes #12: share dir not returned when require module is in an eval

- Recognize constructs like "eval qq{require Inline::C}".

- Recognize idioms like "if (eval { require Foo }) { ..."

- Add %preload rules for some Mojo resource files

  Fixes rschupp/PAR-Packer#44

- Bump perl dependency to guard against ancient perls without FindBin::again()

- Add tool to trace when (and from where) Perl searches for a module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants