ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: "Eregon (Benoit Daloze)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:109609] [Ruby master Bug#18970] CRuby adds an invalid header to bin/bundle (and others) which makes it unusable in Bash on Windows
Date: Sun, 21 Aug 2022 11:11:13 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-98793.20220821111112.772@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18970.20220820135405.772@ruby-lang.org

Issue #18970 has been updated by Eregon (Benoit Daloze).


@nobu Thank you for the explanation, quite clever code.

I think it is still an issue due to being fragile/inconsistent that this header only exists for bin/* files shipped with Ruby but not for bin/* files installed by RubyGems later.

> The rubyinstaller is for Windows, there is no concept of the executable permission.
> On Windows, `bundle.bat` should be executed.

Some people/users do use bash on Windows.
Does bash look at `bundle.bat`?
`$PATHEXT` is `.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC` so I guess maybe yes?

I'm not quite sure what's wrong, I'm no Windows expert, but somehow `bundle install`/`which bundle` doesn't work on Windows without `gem install bundler`.

2.7 with `gem install bundler`:
https://github.com/eregon/setup-ruby/runs/7938304106?check_suite_focus=true
That works fine, because of the `gem install bundler`.
```
-rwxr-xr-x 1 runneradmin None     567 Aug 21 10:56 bundle
-rw-r--r-- 1 runneradmin None      41 Aug 21 10:56 bundle.bat
-rw-r--r-- 1 runneradmin None     672 Apr 19 20:22 bundle.cmd
```
`ls -l` in bash reports bundle as executable, and there is all 3 files.

`bundle install` in bash shell works: https://github.com/eregon/setup-ruby/runs/7938351861?check_suite_focus=true#step:26:1

3.0:
https://github.com/eregon/setup-ruby/runs/7938304140?check_suite_focus=true
```
-rw-r--r-- 1 runneradmin None     672 Apr 19 20:22 bundle.cmd
```
There is no `bin/bundle` file (and also no `bundle.bat`)!
And bundle does not work, when used from a bash shell, I guess as a result of that.
And indeed in https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.0.4-1/rubyinstaller-3.0.4-1-x64.7z I also see no `bin/bundle` or `bundle.bat`.

Is it an issue of RubyInstaller2 or maybe an issue of the build process on Windows or of tool/rbinstall.rb maybe?

`bundle install` in bash shell fails: https://github.com/eregon/setup-ruby/runs/7938351901?check_suite_focus=true#step:26:24
`D:\a\_temp\99c37f86-615f-4118-ab92-9280a5b4f61f.sh: line 1: bundle: command not found`

3.1:
https://github.com/eregon/setup-ruby/runs/7938304170?check_suite_focus=true
```
-rw-r--r-- 1 runneradmin None     707 Apr 19 20:22 bundle
-rw-r--r-- 1 runneradmin None      41 Apr 19 20:22 bundle.bat
```
There is `bundle` and `bundle.bat` but it does not work for `which bundle`. Maybe `bundle.cmd` is needed for `which bundle`?
Note also how `ls -l` reports `bundle` is not executable here. Maybe because of the missing `bundle.cmd`?

`bundle install` in bash shell works: https://github.com/eregon/setup-ruby/runs/7938351950?check_suite_focus=true#step:26:24
But `which bundle` fails: https://github.com/eregon/setup-ruby/runs/7938351950?check_suite_focus=true#step:30:25

----------------------------------------
Bug #18970: CRuby adds an invalid header to bin/bundle (and others) which makes it unusable in Bash on Windows
https://bugs.ruby-lang.org/issues/18970#change-98793

* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Same as https://github.com/oneclick/rubyinstaller2/issues/299, but I figured it's extremely likely to be a bug in CRuby and not in RubyInstaller2.

The original user issue is: https://github.com/ruby/setup-ruby/issues/371.
`bundle` does not work in a Bash shell on Windows -- without an extra `gem install bundler` --, and the reason is building CRuby on Windows either does not produce a `bin/bundle` or it has the wrong permissions and the wrong start.

I downloaded all latest releases from https://github.com/ruby/setup-ruby/blob/master/windows-versions.json and extracted them (I'm on Linux FWIW).
```
$ ls
rubyinstaller-2.4.10-1-x64     rubyinstaller-2.6.10-1-x64     rubyinstaller-3.0.4-1-x64     rubyinstaller-head-x64     ruby-mswin
rubyinstaller-2.4.10-1-x64.7z  rubyinstaller-2.6.10-1-x64.7z  rubyinstaller-3.0.4-1-x64.7z  rubyinstaller-head-x64.7z  ruby-mswin.7z
rubyinstaller-2.5.9-1-x64      rubyinstaller-2.7.6-1-x64      rubyinstaller-3.1.2-1-x64     ruby-mingw                 ruby-ucrt
rubyinstaller-2.5.9-1-x64.7z   rubyinstaller-2.7.6-1-x64.7z   rubyinstaller-3.1.2-1-x64.7z  ruby-mingw.7z              ruby-ucrt.7z
```

Of course only Ruby 2.7+ ships with Bundler, so for <=2.6 it's expected to be missing.

```
$ ls -l */bin/bundle
-rw-r--r--. 1 eregon eregon 707 Apr 19 22:22 rubyinstaller-3.1.2-1-x64/bin/bundle
-rw-r--r--. 1 eregon eregon 707 Aug 19 22:40 rubyinstaller-head-x64/bin/bundle
-rw-rw-rw-. 1 eregon eregon 564 Aug 20 11:15 ruby-mingw/bin/bundle
-rw-rw-rw-. 1 eregon eregon 829 Aug 20 11:09 ruby-mswin/bin/bundle
-rw-rw-rw-. 1 eregon eregon 564 Aug 20 11:20 ruby-ucrt/bin/bundle
```

So only 3.1 and head have bin/bundle.
But those 2 bin/bundle do not have the executable bit set.

They also start like this which sounds invalid for Bash:
```
$ cat rubyinstaller-3.1.2-1-x64/bin/bundle
:""||{ ""=> %q<-*- ruby -*-
@"%~dp0ruby" -x "%~f0" %*
@exit /b %ERRORLEVEL%
};{ #
bindir="${0%/*}" #
exec "$bindir/ruby" "-x" "$0" "$@" #
>,
}
#!/usr/bin/env ruby
#
# This file was generated by RubyGems.
...
```

On https://github.com/eregon/setup-ruby/runs/7843304711?check_suite_focus=true we can see 3.0, 3.1 and head fail for `echo ~ && which -a bundle` in bash.
2.7 avoids the issue in that CI run because the Bundler version is considered too old by setup-ruby and so `gem install bundler` is done there.

## Needed fix

In general, I think it is *very* important that CRuby does NOT modify files in `bin/`, and so that they are exactly the same as when RubyGems would write them when installing the corresponding gem.
This has been a problem not only here but also in these two other issues:
* `gem install bundler` fails on Windows, needs `--force` to workaround: https://github.com/rubygems/rubygems/issues/5245
* `gem install bundler` fails on `--enable-load-relative` Rubies: https://github.com/ruby/setup-ruby/issues/98#issuecomment-719950719

`tool/rbinstall.rb` seems to be responsible for changing the `bin/` files and therefore causing those bugs:
https://github.com/ruby/ruby/blob/209631a45f9682dedf718f4b4a140efe7d21a6fc/tool/rbinstall.rb#L487
Can we remove that?

Not that this issue cannot be solved in RubyGems, it's CRuby breaking `bin/bundle` (and others) in Bash on Windows.



-- 
https://bugs.ruby-lang.org/

  parent reply	other threads:[~2022-08-21 11:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-20 13:54 [ruby-core:109598] [Ruby master Bug#18970] CRuby adds an invalid header to bin/bundle (and others) which makes it unusable in Bash on Windows Eregon (Benoit Daloze)
2022-08-20 14:20 ` [ruby-core:109599] " Eregon (Benoit Daloze)
2022-08-21  4:40 ` [ruby-core:109607] " nobu (Nobuyoshi Nakada)
2022-08-21 11:11 ` Eregon (Benoit Daloze) [this message]
2022-08-21 11:17 ` [ruby-core:109610] " Eregon (Benoit Daloze)
2022-08-21 11:27 ` [ruby-core:109611] " Eregon (Benoit Daloze)
2022-08-21 11:38 ` [ruby-core:109612] " Eregon (Benoit Daloze)
2022-08-22  1:54 ` [ruby-core:109618] " nobu (Nobuyoshi Nakada)
2022-08-22 14:49 ` [ruby-core:109631] " Eregon (Benoit Daloze)
2022-08-22 16:48 ` [ruby-core:109632] " MSP-Greg (Greg L)
2022-08-22 19:31 ` [ruby-core:109634] " austin (Austin Ziegler)
2022-08-23 16:52 ` [ruby-core:109649] " Eregon (Benoit Daloze)
2022-08-23 22:37 ` [ruby-core:109652] " MSP-Greg (Greg L)
2022-08-24 17:08 ` [ruby-core:109663] " MSP-Greg (Greg L)
2022-08-25 14:45 ` [ruby-core:109693] " nobu (Nobuyoshi Nakada)
2022-08-30  1:13 ` [ruby-core:109781] " MSP-Greg (Greg L)
2022-09-01 21:59 ` [ruby-core:109820] " MSP-Greg (Greg L)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-98793.20220821111112.772@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).