Peculiar perl version issue
ryandesign at macports.org
Wed Jun 12 17:14:52 UTC 2019
On Jun 12, 2019, at 10:26, Bruce Miller wrote:
> [This is motivated by the LaTeXML port,
> but is a general question about perl portgroup]
> A colleague suggested the clever shebang line
> #!/usr/bin/env perl
> as a way to easily allow testing against different
> versions of perl, running in sandboxes, etc.
Sounds good to me.
> This has worked fine on all systems, so far,
> including MacPorts...
> That is, until macports installed multiple perl versions!
> (MacPorts 2.5.4, on Mojave, 10.14.5, as it were)
Note that MacPorts has been offering multiple simultaneously-installable versions of perl for over ten years. Many of the other languages you can install with MacPorts -- php, ruby, python, clang, gcc, nodejs -- can also be installed in multiple versions.
> So, apparently the perl portgroup replaces shebang
> lines that it recognizes with a call to the specific
> perl that was specified in the portfile (? is that right?)
> And if so, it doesn't recognize the above line,
> so it leaves it alone.
I can't find any code in the perl5 portgroup that replaces shebang lines. But if you need to do that, it's easy to write an fs-traverse/reinplace loop to do so. Many other ports do something like that, so you can probably find a few lines of code in another portfile that you can copy and paste.
> Since LaTeXML specifies perl 5.26 (Yes, I know
> I need to update it, but that's only a shortterm fix),
> and macports is installing both 5.26 and 5.28,
> all of LaTeXML's modules go under
> and env perl -v shows
> This is perl 5, version 28...
FYI, env perl -v shows version 5.28 because you have installed the perl5 port with the +perl5_28 variant. But a user might install it with a different variant and then env perl -v would be a different version for them. Point being: you can't rely on "perl" being a particular version on a user's system.
> So; is there a simple way to tell the portgroup
> to replace the shebang line? Or some other nice
> (hopefully short of replacing all my shebang lines
> with "proper" ones).
> (And ideally, I'd avoid the whole version business,
> since LaTeXML *should* work with any version of perl
> after, I think, 5.10)
I'm sure it would, but the portfile still needs to specify which of those versions it would like to use. The port is going to install the modules into a directory that is specific to some version of perl, and the perl binary that gets used needs to be the one that goes with that modules directory. If you want to give the user a choice, you can make variants for the different perl versions. The perl5 portgroup provides a procedure perl5.create_variants to do that for you.
More information about the macports-dev