in reply to Re^3: making tcl.pm and Tcl movable
in thread making tcl.pm and Tcl movable

Actually the task is very simple: my department needs to deploy on 50+ macOS laptops a script that needs to call Tcl. This script needs to run in a nutshell, with its own Perl and Tcl version (I know that both are already present on any macOS, but not the desired versions). They do not want to install on all machines Tcl, tcl.pm, and Perl. My task: pack the Perl script + Perl into an executable (which I can do with zero problems with PAR or pp). My problem is to link the script/executable to the Tcl version I will put together with the executable, all packed in a zip file, on the target machines. In the target computer: unpack the zip and run the executable. Inside the zip file:

The problems I have is to link to these Tcl binaries.

No matter what I try, the executable in the target machines is always linked to the standard Tcl distribution, not the one inside the zip). I tried to install tcl.pm against my Tcl binaries. It works, but as soon as I 'move' around my folder with executable+Tcl, it stops to work, since Tcl is no more in sight of the module. I tried with the ENV variable, as pointed out above and in some forum about Tkx, but could not reach any success. Any suggestion would be very much appreciated.

Replies are listed 'Best First'.
Re^5: making tcl.pm and Tcl movable
by swl (Prior) on Nov 18, 2018 at 22:32 UTC

    Is the problem that you need to update your path in the script to include the packed location?

    If so then something along the lines of the code below might be sufficient. It assumes the files are packed with the executable, so adjust paths as needed.

    BEGIN { if ($ENV{PAR_0}) { use Config; $ENV{PATH} .= "$Config{path_sep}$ENV{PAR_TEMP}"; } #print $ENV{PATH}; };

    Or, if they are in a directory at some arbitrary level above the script's location then something more complex like:

    # not fully tested, not properly adapted to the Tk case, # and likely has side effects BEGIN { # Search up the tree until we find the tk dir that contains a bin + folder use Path::Class; use Config; use FindBin qw /$Bin/; #say "PAR_PROGNAME: $ENV{PAR_PROGNAME}"; my $prog_name = $ENV{PAR_PROGNAME} || $Bin; my @paths; use Config; my $tk_dir ='tk'; # add the tk bin dir to the path my $origin_dir = Path::Class::file($prog_name)->dir; ORIGIN_DIR: while ($origin_dir) { my $inner_path = Path::Class::dir($origin_dir, $origin_dir); #say "Checking $inner_path"; my $bin_path = Path::Class::dir($inner_path, 'bin'); if (-d $bin_path) { #say "Adding $bin_path to the path"; push @paths, $bin_path; } my $old_dir = $origin_dir; $origin_dir = $origin_dir->parent; last ORIGIN_DIR if $old_dir eq $origin_dir; } my $sep = $Config{path_sep}; $ENV{PATH} = join $sep, @paths, $ENV{PATH}; }

    You could also try pp_simple if it's just the dynamic libs that need to be packed.

Re^5: making tcl.pm and Tcl movable
by LanX (Saint) on Nov 18, 2018 at 22:22 UTC
    Did you dump @INC and $ENV{PATH} to be sure that the path to system TCL comes after bundled TCL?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Hi Land

      I add it this way

      BEGIN { my $frameworkpath; $frameworkpath = "$Bin/Frameworks/Tcl.framework/Tcl"; $ENV{'PERL_TCL_DL_PATH'} = $frameworkpath; }

      it is not in $ENV{PATH}, as tcl.pm reads $ENV{'PERL_TCL_DL_PATH'}, am I right? Frameworks are in the same folder as the script.

        Please also note that I have not instructed tcl.pm - while installing it - of the existence of these frameworks.