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

Respect perl6 in hashbang #14661

Closed
p5pRT opened this issue Apr 19, 2015 · 15 comments
Closed

Respect perl6 in hashbang #14661

p5pRT opened this issue Apr 19, 2015 · 15 comments

Comments

@p5pRT
Copy link

p5pRT commented Apr 19, 2015

Migrated from rt.perl.org#124346 (status was 'open')

Searchable as RT124346$

@p5pRT
Copy link
Author

p5pRT commented Apr 19, 2015

From @Leont

This is a bug report for perl from fawaka@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.


Currently, when perl tries to run a script and it encounters a hashbang
line not containing the string "perl" (e.g. /usr/bin/python), it will
instead run that executable. This works for most other languages, but for
perl6 this doesn't switch gracefully for obvious reasons.

The attached patch tries to fix that, so that #!perl6 files will DWIM.



Flags​:
  category=core
  severity=wishlist


Site configuration information for perl 5.20.1​:

Configured by leon at Tue Oct 21 13​:31​:28 CEST 2014.

Summary of my perl5 (revision 5 version 20 subversion 1) configuration​:

  Platform​:
  osname=linux, osvers=3.13.0-37-generic,
archname=x86_64-linux-thread-multi
  uname='linux leon-laptop 3.13.0-37-generic #64-ubuntu smp mon sep 22
21​:28​:38 utc 2014 x86_64 x86_64 x86_64 gnulinux '
  config_args='-de -Dprefix=/home/leon/perl5/perlbrew/perls/perl-5.20.1
-Duseshrplib -DDEBUGGING -Dusethreads
-Aeval​:scriptdir=/home/leon/perl5/perlbrew/perls/perl-5.20.1/bin'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=define, usemultiplicity=define
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include
-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2 -g',
  cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -DDEBUGGING
-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.8.2', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
  libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
  libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
-lgdbm_compat
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
  libc=libc-2.19.so, so=so, useshrplib=true, libperl=libperl.so
  gnulibc_version='2.19'
  Dynamic Linking​:
  dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
-Wl,-rpath,/home/leon/perl5/perlbrew/perls/perl-5.20.1/lib/5.20.1/x86_64-linux-thread-multi/CORE'
  cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib
-fstack-protector'


@​INC for perl 5.20.1​:

/home/leon/perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1/x86_64-linux-thread-multi
  /home/leon/perl5/perlbrew/perls/perl-5.20.1/lib/site_perl/5.20.1

/home/leon/perl5/perlbrew/perls/perl-5.20.1/lib/5.20.1/x86_64-linux-thread-multi
  /home/leon/perl5/perlbrew/perls/perl-5.20.1/lib/5.20.1
  .


Environment for perl 5.20.1​:
  HOME=/home/leon
  LANG=en_US.UTF-8
  LANGUAGE=en_US​:en
  LC_ADDRESS=en_US.UTF-8
  LC_IDENTIFICATION=en_US.UTF-8
  LC_MEASUREMENT=en_US.UTF-8
  LC_MONETARY=en_US.UTF-8
  LC_NAME=en_US.UTF-8
  LC_NUMERIC=en_US.UTF-8
  LC_PAPER=en_US.UTF-8
  LC_TELEPHONE=en_US.UTF-8
  LC_TIME=en_US.UTF-8
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)

PATH=/home/leon/.rakudobrew/bin​:/home/leon/perl5/perlbrew/bin​:/home/leon/perl5/perlbrew/perls/perl-5.20.1/bin​:/home/leon/bin​:/usr/local/sbin​:/usr/local/bin​:/usr/sbin​:/usr/bin​:/sbin​:/bin​:/usr/games​:/usr/local/games
  PERLBREW_BASHRC_VERSION=0.71
  PERLBREW_HOME=/home/leon/.perlbrew
  PERLBREW_MANPATH=/home/leon/perl5/perlbrew/perls/perl-5.20.1/man

PERLBREW_PATH=/home/leon/perl5/perlbrew/bin​:/home/leon/perl5/perlbrew/perls/perl-5.20.1/bin
  PERLBREW_PERL=perl-5.20.1
  PERLBREW_ROOT=/home/leon/perl5/perlbrew
  PERLBREW_VERSION=0.71
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Apr 19, 2015

From @Leont

0001-Respect-hashbangs-containing-perl6.patch
From f39a39ab79624a58283ef25ddb94a2b39f73ac06 Mon Sep 17 00:00:00 2001
From: Leon Timmermans <fawaka@gmail.com>
Date: Sun, 19 Apr 2015 13:03:28 +0200
Subject: [PATCH] Respect hashbangs containing perl6

---
 toke.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/toke.c b/toke.c
index 294cb8f..077ab08 100644
--- a/toke.c
+++ b/toke.c
@@ -4863,6 +4863,8 @@ Perl_yylex(pTHX)
 		d = instr(s,"perl -");
 		if (!d) {
 		    d = instr(s,"perl");
+                    if (d && d[4] == '6')
+                        d = NULL;
 #if defined(DOSISH)
 		    /* avoid getting into infinite loops when shebang
 		     * line contains "Perl" rather than "perl" */
-- 
1.9.1

@p5pRT
Copy link
Author

p5pRT commented Apr 19, 2015

From zefram@fysh.org

Leon Timmermans wrote​:

The attached patch tries to fix that, so that #!perl6 files will DWIM.

That #! hack is obsolete. We should not change its behaviour for perl6.
We should either leave it totally unchanged or remove it entirely.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Apr 19, 2015

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented May 26, 2015

From @rjbs

* Zefram <zefram@​fysh.org> [2015-04-19T10​:12​:48]

Leon Timmermans wrote​:

The attached patch tries to fix that, so that #!perl6 files will DWIM.

That #! hack is obsolete. We should not change its behaviour for perl6.
We should either leave it totally unchanged or remove it entirely.

I find both sides of this tempting, because I constantly write "perl
my-perl6-program" and like to imagine that it would help. I'd need to have a
perl6 shebang, though, which I rarely do in the things I'm running, which are
tests or libraries. If I did have a shebang, it would probably be to run env,
sadly, and then I start getting nervous about the idea of picking our
executable based on things like secondary args in the shebang (although we
already do it).

Obviously, I'm just a single data point here. My gut, though, is that this
will be added complexity with very little actual gain. It's also very little
added complexity, though.

Anybody care to convince me otherwise?

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2015

From @Leont

On Tue, May 26, 2015 at 1​:20 PM, Ricardo Signes <perl.p5p@​rjbs.manxome.org>
wrote​:

* Zefram <zefram@​fysh.org> [2015-04-19T10​:12​:48]

Leon Timmermans wrote​:

The attached patch tries to fix that, so that #!perl6 files will DWIM.

That #! hack is obsolete. We should not change its behaviour for perl6.
We should either leave it totally unchanged or remove it entirely.

I find both sides of this tempting, because I constantly write "perl
my-perl6-program" and like to imagine that it would help. I'd need to
have a
perl6 shebang, though, which I rarely do in the things I'm running, which
are
tests or libraries. If I did have a shebang, it would probably be to run
env,
sadly, and then I start getting nervous about the idea of picking our
executable based on things like secondary args in the shebang (although we
already do it).

Obviously, I'm just a single data point here. My gut, though, is that this
will be added complexity with very little actual gain. It's also very
little
added complexity, though.

Anybody care to convince me otherwise?

There are programs out there that depend on perl acting as a switchbox, in
particular prove is such a program. This patch doesn't help anyone in
perl5-land, but it would help a lot of people in perl6-land.

Leon

@p5pRT
Copy link
Author

p5pRT commented Jun 20, 2015

From @ap

* Leon Timmermans <fawaka@​gmail.com> [2015-06-20 21​:50]​:

There are programs out there that depend on perl acting as
a switchbox, in particular prove is such a program. This
patch doesn't help anyone in perl5-land, but it would help
a lot of people in perl6-land.

+1

It doesn’t even add any conceptual complexity – all behaviours
already exist, and the patch achieves its purpose by narrowing
down the special case (i.e. perl). I find this pleasing.

Regards,
--
Aristotle Pagaltzis // <http​://plasmasturm.org/>

@p5pRT
Copy link
Author

p5pRT commented Jun 21, 2015

From @ribasushi

On 06/20/2015 09​:47 PM, Leon Timmermans wrote​:

...
This patch doesn't help anyone in
perl5-land, but it would help a lot of people in perl6-land.

+1

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2015

From @rjbs

* Leon Timmermans <perlbug-followup@​perl.org> [2015-04-19T09​:53​:21]

Currently, when perl tries to run a script and it encounters a hashbang
line not containing the string "perl" (e.g. /usr/bin/python), it will
instead run that executable. This works for most other languages, but for
perl6 this doesn't switch gracefully for obvious reasons.

The attached patch tries to fix that, so that #!perl6 files will DWIM.

Okay, go for it.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2015

From @avar

On Sun, Apr 19, 2015 at 3​:53 PM, Leon Timmermans
<perlbug-followup@​perl.org> wrote​:

# New Ticket Created by Leon Timmermans
# Please include the string​: [perl #124346]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=124346 >

This is a bug report for perl from fawaka@​gmail.com,
generated with the help of perlbug 1.40 running under perl 5.20.1.

-----------------------------------------------------------------

Currently, when perl tries to run a script and it encounters a hashbang
line not containing the string "perl" (e.g. /usr/bin/python), it will
instead run that executable. This works for most other languages, but for
perl6 this doesn't switch gracefully for obvious reasons.

The attached patch tries to fix that, so that #!perl6 files will DWIM.

I think this patch makes sense, but I wonder if other cases could also
DWYM. Currently these shebangs trigger these behaviors, where "exec"
is "execute other interpreter" and "ignore" is "treat it as a
comment"​:

#!/bin/sh => exec
#!sh => exec
#!rakudo => exec
#!perl => exec
#!/bin/perl => ignore
#!thewordperlinthemiddleofastring => ignore
#!perl5.18.2 => ignore
#!perl6 => ignore
#!/bin/perl6 => ignore
#!rakudoperl6 => ignore
#!rakudoperlsix => ignore
#!company-perl => ignore
#!company-perl5.18.2 => ignore

You patch would alter the behavior of these​:

#!perl6 => exec
#!/bin/perl6 => exec
#!rakudoperl6 => exec

I think that makes sense, but I wonder if we're being overly eager
currently about recognizing the "perl" substring anywhere in the
shebang. But on the other hand we have things like
"#!/usr/local/bin/company-perl5.18.2" which relies on this behavior.
So I don't know.

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2015

From perl@profvince.com

Can we have support for php and python next?

Vincent

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2015

From zefram@fysh.org

Vincent Pit (VPIT) wrote​:

Can we have support for php and python next?

Already got that. perl does general shebang redirection for any shebang
that does not contain the substring "perl"; the issue is about extending
that redirection to some strings that do contain that substring.

-zefram

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2015

From net@profvince.com

Le 22/06/2015 09​:49, Zefram a écrit :

Vincent Pit (VPIT) wrote​:

Can we have support for php and python next?

Already got that. perl does general shebang redirection for any shebang
that does not contain the substring "perl"; the issue is about extending
that redirection to some strings that do contain that substring.

-zefram

Thanks, that makes sense then.

@p5pRT
Copy link
Author

p5pRT commented Jun 22, 2015

From @ikegami

On Mon, Jun 22, 2015 at 8​:36 AM, Ævar Arnfjörð Bjarmason <avarab@​gmail.com>
wrote​:

#!perl => exec
#!/bin/perl => ignore

I think that's a typo?

@Leont
Copy link
Contributor

Leont commented Jan 31, 2020

Given the perl6 -> raku namechange, I think this ticket can be closed :-)

@Leont Leont closed this as completed Jan 31, 2020
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

2 participants