beyondgrep / ack2

**ack 2 is no longer being maintained. ack 3 is the latest version.**
https://github.com/beyondgrep/ack3/
Other
1.48k stars 140 forks source link

better shebang for cross-platform compatibility #269

Closed mcandre closed 11 years ago

mcandre commented 11 years ago

perl isn't always installed in /usr/bin, e.g. Strawberry Perl in Windows.

petdance commented 11 years ago

I do not want to just merge this without some serious thought. I'm very wary of ripple effects.

This should probably only be in the ack-single-file version. The standard Perl version will have its shebang modified.

What about packagers? Will this affect them?

mmcclimon commented 11 years ago

For that matter, does /usr/bin/env work on Windows anyway? It seems like it wouldn't...and the shebang would have to be something like #!C:\strawberry\bin\perl.

mcandre commented 11 years ago

@mmcclimon Short answer: Yes!

I love the humble shebang, but for the most part they're irrelevant in Windows. cmd.exe does not offer the Unix shell dot slash notation (./hello.py), so Windows users would tend to use the longer command python hello.py, if they use the command line at all (rant rant Visual Studio bulky IDE rant rant). Shebangs in Windows are mostly treated as single line comments, with the exception of text editors relying on shebangs in the corner case of determining mimetypes of files with no extension (So Emacs for Windows can correctly interpret the file hello as Python code).

However, Unix-like development environments do exist for Windows (Cygwin/MinGW/msysGit/Git Bash). They're mostly used for cross-compiling dependencies of dependencies blah blah Unix libraries for Windows, for example, readline for tab completion in Windows versions of programming interpreters. Or, if you simply prefer bash to DOS, bash.exe to cmd.exe, Git Bash is rather nice (insert Console 2 plug).

In Cygwin land, development environments are pretty complex. They're not quite Windows. Path names in Cygwin tend to be specified Unix style (/src/hello.py), and .bat files can't be executed easily. But they're not quite Unix either. cron is unavailable, and file permissions are a trick of the light. ./hello.py will work in Git Bash, but for this reason, ./he[TAB] is won't tab complete it for you. C'est la vie.

Why this matters for to ack: Strawberry Perl puts perl.exe in C:\strawberry\perl\bin, or /c/strawberry/perl/bin as Cygwin refers to it. Shebangs in Windows are nothing outside of Cygwinish environments, but they're everything when a Makefile indirectly calls a script three levels deep using dot slash notation, and the shebang is artificially limited to computers with perl in /usr/bin. A little change to #!/usr/bin/env perl enables Windows development again, it goes a long way towards increasing cross-platform compatibility. To be sure, the cross section of Windows users and ack users is fairly small, but it still matters. Personally, I love ack. Until grep gets .grepignore, ack is my man.

Until ack.exe comes out, ack will work best in Windows with a proper env-style shebang (and even then, scripts involved in building ack.exe are still best written with this notation). Windows may not be my favorite OS, but I still place a high value on software supporting Mac, Windows, and Linux. It's amazing when things "just work" in unexpected and unusual environments, and little things like cross-platform shebangs add up.

</endrant>
petdance commented 11 years ago

This is getting frighteningly close to us packaging ack for Windows, and that's not a path I want to go down. We do not have the expertise to do Windows/Cygwin/whatever packaging.

vsespb commented 11 years ago

AFAIK one should not use /usr/bin/env in CPAN-installed scripts http://blogs.perl.org/users/randy_stauner/2011/09/shebangs-with-perlbrew-aliases-and-eumm-and-without-locallib.html

mcandre commented 11 years ago

How about #!perl?

vsespb commented 11 years ago

#!perl won't work on linux.

I think need just have separate bin script for CPAN installation. And for non-CPAN use /usr/bin/env is possible. (Also I heard it's prefered on MacOSX ?)

vsespb commented 11 years ago

Also there is discussion about Debian policy for perl + /usr/bin/env perl http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=683495

mbeijen commented 11 years ago

Just my 2cts: if you install 'App::Ack' on Strawberry Perl or ActiveState Perl, it will create a file 'ack.bat' that actually launches Ack for you. As stated, there's NO need to mess with shebang lines on Windows.

I work a lot on Windows, and the only place I found I really need to adapt it is when I run a Perl script as CGI under apache. Which is not something I would recommend in the first place :)

mcandre commented 11 years ago

Actually, shebangs are very helpful for cygwin Windows environments, where .sh scripts can be run, but not .bat scripts.

On Tue, Sep 17, 2013 at 4:22 AM, Michiel Beijen notifications@github.comwrote:

Just my 2cts: if you install 'App::Ack' on Strawberry Perl or ActiveState Perl, it will create a file 'ack.bat' that actually launches Ack for you. As stated, there's NO need to mess with shebang lines on Windows.

I work a lot on Windows, and the only place I found I really need to adapt it is when I run a Perl script as CGI under apache. Which is not something I would recommend in the first place :)

— Reply to this email directly or view it on GitHubhttps://github.com/petdance/ack2/pull/269#issuecomment-24571323 .

Cheers,

Andrew Pennebaker www.yellosoft.us

mbeijen commented 11 years ago

Cygwin is NOT Windows! Op 18 sep. 2013 03:27 schreef "Andrew Pennebaker" notifications@github.com het volgende:

Actually, shebangs are very helpful for cygwin Windows environments, where .sh scripts can be run, but not .bat scripts.

On Tue, Sep 17, 2013 at 4:22 AM, Michiel Beijen notifications@github.comwrote:

Just my 2cts: if you install 'App::Ack' on Strawberry Perl or ActiveState Perl, it will create a file 'ack.bat' that actually launches Ack for you. As stated, there's NO need to mess with shebang lines on Windows.

I work a lot on Windows, and the only place I found I really need to adapt it is when I run a Perl script as CGI under apache. Which is not something I would recommend in the first place :)

— Reply to this email directly or view it on GitHub< https://github.com/petdance/ack2/pull/269#issuecomment-24571323> .

Cheers,

Andrew Pennebaker www.yellosoft.us

— Reply to this email directly or view it on GitHubhttps://github.com/petdance/ack2/pull/269#issuecomment-24635094 .

mcandre commented 11 years ago

Correct. Cygwin is a common development environment within Windows, that emphasizes traditional Unix/POSIX shell scripting, complete with bash and GNU #include headers, and shebangs. A good shebang makes programming much easier in unexpected environments, such as Cygwin, where .bat files are neither used, nor able to be used.

On Wed, Sep 18, 2013 at 1:12 AM, Michiel Beijen notifications@github.comwrote:

Cygwin is NOT Windows! Op 18 sep. 2013 03:27 schreef "Andrew Pennebaker" < notifications@github.com> het volgende:

Actually, shebangs are very helpful for cygwin Windows environments, where .sh scripts can be run, but not .bat scripts.

On Tue, Sep 17, 2013 at 4:22 AM, Michiel Beijen < notifications@github.com>wrote:

Just my 2cts: if you install 'App::Ack' on Strawberry Perl or ActiveState Perl, it will create a file 'ack.bat' that actually launches Ack for you. As stated, there's NO need to mess with shebang lines on Windows.

I work a lot on Windows, and the only place I found I really need to adapt it is when I run a Perl script as CGI under apache. Which is not something I would recommend in the first place :)

— Reply to this email directly or view it on GitHub< https://github.com/petdance/ack2/pull/269#issuecomment-24571323> .

Cheers,

Andrew Pennebaker www.yellosoft.us

— Reply to this email directly or view it on GitHub< https://github.com/petdance/ack2/pull/269#issuecomment-24635094> .

— Reply to this email directly or view it on GitHubhttps://github.com/petdance/ack2/pull/269#issuecomment-24641358 .

Cheers,

Andrew Pennebaker www.yellosoft.us

vsespb commented 11 years ago

Cygwin is NOT Windows!

Win32 core module is available and works under Cygwin, so, technically, cygwin is Windows and POSIX at same time. However I doubt it matters. Let's just call it Win32 vs Cygwin.

petdance commented 11 years ago

I'm closing this because we're covered on all bases anyway:

~/ack2 $ head -1 blib/script/ack
#!/var/perl588/bin/perl
$ head -1 ack-standalone
#!/usr/bin/env perl

If for some reason you've built with Strawberry Perl and your ack has a shebang that's not appropriate for your environment, then that's a toolchain problem.