From: "MSP-Greg (Greg L)" Date: 2022-08-23T22:37:05+00:00 Subject: [ruby-core:109652] [Ruby master Bug#18970] CRuby adds an invalid header to bin/bundle (and others) which makes it unusable in Bash on Windows Issue #18970 has been updated by MSP-Greg (Greg L). @nobu & @Eregon I just tried the prolog_script script branch. Wondering if the following example would be fine with everyone? It seems to work for me locally. If they're run as 'in path' commands, they work, if they're run from the folder of a 'non-system' Ruby, they run, although, since they don't set Path, any Ruby sub-processes hopefully will use `Gem.ruby` or something similar... I tested the below with MSYS2 bash and Git bash. Windows bash file 'top' ```bash { bindir=$(dirname "$0") exec "$bindir/ruby" "-x" "$0" "$@" } #!/usr/bin/env ruby # # This file was generated by RubyGems. -- remaining code -- ``` Windows *.cmd or *.bat binstub ```bat @ECHO OFF @"%~dp0ruby.exe" -x "%~dpn0" %* ``` I built a test, link is https://github.com/MSP-Greg/ruby-loco-test/releases/download/ruby-master/ruby-mswin.7z. It's the same as the builds used in CI. Note that the bash scripts work the same as the Windows (*.bat, *.cmd) scripts. The launch with the ruby.exe in the same folder, but the ENV Ruby. Finally, the ruby/ruby code isn't generating a 'gem' bash file. ---------------------------------------- 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-98875 * 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/ Unsubscribe: