Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: - Pack script and dependencies into self-extracting bash script

by Anonymous Monk
on Aug 21, 2012 at 19:35 UTC ( #988836=note: print w/ replies, xml ) Need Help??

in reply to - Pack script and dependencies into self-extracting bash script

Congratulations, you've reinvented shar/ fatpack

Congratulations, pp --perlscript can almost do that too :) provided you use -X coremod to exclude core modules

system qw{ pp -M Data::Dump::FilterContext -M Data::Dump::Filtered -M Data::Dump -X File::Glob -X threads -X Symbol -X subs -X overload -X Exporter -X vars -X utf8 -X strict -X base -X Carp -X Config -X Exporter::Heavy -X feature -X XSLoader -X DynaLoader -X Scalar::Util -X mro -X warnings::register -X integer -X warnings -X MIME::Base64 -X Text::ParseWords -X List::Util -C CACHEFILE --perlscript -o ddvars -e } => 'use Data::Dump; dd\@INC,\%ENV; ';

Sure various lib/unicore/lib/IDC/ get packed as well, but no binary components get packed, no .dll's or .so's

Replies are listed 'Best First'.
Re^2: - Pack script and dependencies into self-extracting bash script
by Anonymous Monk on Aug 21, 2012 at 20:02 UTC

    So here is my version :)

    #!/usr/bin/perl -- use strict; use warnings; use Data::Dump; use Module::Corelist; @ARGV or die "Usage: $0 outfile infile infile infile\n"; my $outfile = shift || 'ddname'; my @script = @ARGV ? @ARGV : qw[ ]; my @cache = qw[ -C CACHEFILE ]; my %exclude; # we don't pack core modules available in this perl my %include; for ( qx[scandeps @cache -B -V @script ] ){ /^'([^']+)'/ or next; my $mod = $1; my $first = Module::CoreList->first_release($mod); my $removed = Module::CoreList->removed_from($mod); $exclude{$mod}++ if defined $first and $first < $] ; # core in + this perl $include{$mod}++ if defined $removed and $] >= $removed; # removed + (not core) in this perl } my @exclude = map {; '-X', $_ } keys %exclude; my @include = map {; '-M', $_ } keys %include; #~ my @args = ( qw[ pp --perlscript --output ] => $outfile, @exclude, +@include, @script ); my @args = ( qw[ pp -P -o ] => $outfile, @exclude, @include, @script ) +; dd \@args; system @args; __END__

      Impressive coding and deft manipulation - nicely done. I downloaded it and tweaked it to actually run (a typo and Dump->Dumper, print Dumper instead of dd, etc) - nicely done indeed.

      However, the resulting file from PAR still gives an error when run on another machine:

      Can't locate PAR/ in @INC (@INC contains: ...snip...) at /usr/bin/ line 348.

      I even attempted to force inclusion of PAR::Heavy by adding push @include, qw(-M PAR::Heavy); after my @include (Admittedly, I gave up after a few moments of it not working - I didn't try *too* hard) - unfortunately, that didn't change the error message on the other machine at all.

        Well it does require PAR to be installed on the other machine :/
Re^2: - Pack script and dependencies into self-extracting bash script
by jbryan (Acolyte) on Aug 21, 2012 at 20:06 UTC

    Ahh, so is that different than what the following does:

    # From % pp -P -o file % pp -B -p -o file

    Neither of the resulting files would run cross-platform (e.g. when copied from 64bit laptop to 64bit machine, both running CentOS, or the other way around - 32bit to 64bit.) Even though no .so/etc were copied, the header on the file that PAR added require'd DynaLoader, which caused it to fail with an error like Undefined subroutine &DynaLoader::bootstrap called at /usr/lib64/perl5/ line 111. (This is from a file generated with pp on my 64bit laptop last night and ran on my 32bit desktop here at the office.)

    I spent several hours googling and trying various options, though I admit I didn't try that -X option (must have glossed over that thru my sleep-deprived hazy vision!)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://988836]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2016-06-30 02:06 GMT
Find Nodes?
    Voting Booth?
    My preferred method of making French fries (chips) is in a ...

    Results (388 votes). Check out past polls.