[Koha-devel] Inconsistent Perl shebangs (new coding guideline?)

dcook at prosentient.com.au dcook at prosentient.com.au
Wed Oct 14 02:45:17 CEST 2020


My point is that I find 1217 instances of '#!/usr/bin/perl' but only 38 instances of '#!/usr/bin/env perl' in the Koha master codebase. It seems to me that we should change those 38 instances of '#!/usr/bin/env perl' to adhere to '#!/usr/bin/perl' so that we're 100% consistent with our Perl shebangs.

Since we're moving away from CGI and over to Plack/Mojo, we really don't need to worry about shebangs for the web app too much. Starman/Morbo/Hypnotoad should have the same shebang as the Perl that was used to compile them (thanks to this aspect of ExtUtils::MakeMaker: https://metacpan.org/pod/ExtUtils%3a%3aMakeMaker#EXE_FILES). In Debian packages, they'll use /usr/bin/perl, but if you installed them in a "virtual environment", they should point to whatever Perl interpreter you're using there. 

At a glance, that leaves a few potential issues:
1. koha-shell has a #!/usr/bin/perl shebang. This might need to be #!/usr/bin/env perl in order to work in a "virtual environment", or somehow rewritten to the desired Perl binary during build. (Miyagawa rewrites the cpanm shebang in Makefile.PL although for a different reason: https://github.com/miyagawa/cpanminus/blob/devel/App-cpanminus/Makefile.PL#L11. In our case, since debian/ isn't affected by Makefile.PL, we'd probably need to do this in debian/rules...).
2. koha-z3950-responder and koha-plack make references to #!/usr/bin/perl in them. They probably should just try to call "perl" and expect that the caller has set their PATH correctly. 

Notes:
1. t/ and xt/ scripts use #!/usr/bin/perl. I think prove will use the Perl used to invoke "prove". The shebang is just used by Test::Harness to determine if it's a Perl script. It looks like prove uses $ENV{HARNESS_PERL}, which is undocumented, or $^X (https://perldoc.perl.org/perlvar#$%5EX) according to https://metacpan.org/source/TAP::Parser::SourceHandler::Perl#L324. So I don't think this is a drama. 
2. Obviously lots of cronjobs and other scripts have #!/usr/bin/perl shebangs, but that shouldn't matter so long as they're called by a Perl interpreter rather than being executed by a shell. 
3. Noticing a few debian/* files using #!/usr/bin/perl, but they're developer scripts, and I imagine they're invoked via "perl" rather than by the shell. Shouldn't be an issue.

For other words on #!/usr/bin/env perl, take a look at the following:
https://github.com/Perl-Toolchain-Gang/ExtUtils-MakeMaker/issues/58 (Discussion about #!/usr/bin/env in the context of EXE_FILES amongst Perl big shots like Miyagawa, Karen Etheridge, Sebastian Riedel, Leon Timmermans, Tim Bunce, etc.)
https://www.python.org/dev/peps/pep-0394/  (Python's own statements about shebang usage for Python scripts.)("For scripts that are only expected to be run in an activated virtual environment, shebang lines can be written as #!/usr/bin/env python, as this instructs the script to respect the active virtual environment.")("When potentially targeting [other] environments, developers may either use a Python package installation tool that rewrites shebang lines for the installed environment, provide instructions on updating shebang lines interactively, or else use more specific shebang lines that are tailored to the target environment.")

Of course, everything after the first sentence of my email is a bit moot, as at the moment we only support Koha in a non-virtual environment scenario. 

David Cook
Software Engineer
Prosentient Systems
72/330 Wattle St
Ultimo, NSW 2007
Australia

Office: 02 9212 0899
Online: 02 8005 0595

-----Original Message-----
From: Koha-devel <koha-devel-bounces at lists.koha-community.org> On Behalf Of MJ Ray
Sent: Wednesday, 14 October 2020 8:19 AM
To: koha-devel at lists.koha-community.org
Subject: Re: [Koha-devel] Inconsistent Perl shebangs (new coding guideline?)

"Renvoize, Martin" <martin.renvoize at ptfs-europe.com> wrote:

> My vague recollection of such a conversation was summarized in this
> post: https://jmmv.dev/2016/09/env-considered-harmful.html
> 
> I'm generally pro /usr/bin/env but they do make some good points in 
> the above that are worth consideration.

Let me consider those six points (converting roman numerals to arabic):

1-3. basically variations on using env might not find the version you want - but that applies to /usr/bin/perl too;

4. cannot pass flags to the interpreter - do we want to?

5. affected by user environment - I think we use some environment variables anyway, so we already need to control the environment, so this is not a problem for Koha.

6. "not suitable to being installed" due to 1-5 plus some arbitrary rules about "the installed script must see the exact same environment that was specified at installation time" which is not true of any system getting security updates, is it? Maybe I don't understand this point.

So I don't think I see a compelling reason against env there.

Have I missed something?

Regards,
-- 

MJR http://mjr.towers.org.uk/
Member of http://www.software.coop/ (but this email is my personal view
only)

_______________________________________________
Koha-devel mailing list
Koha-devel at lists.koha-community.org
https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/




More information about the Koha-devel mailing list