Skip to content

Commit f3e1b0e

Browse files
committed
Add script to fix shebangs when using --enable-load-relative
* See ruby/setup-ruby#98 (comment)
1 parent 02bdc3f commit f3e1b0e

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ jobs:
4444
run: ruby-install --prefix ~/build_prefix/${{ matrix.ruby }} --no-install-deps -j4 ${{ matrix.ruby }} -- --enable-shared --enable-rpath --enable-load-relative --disable-install-doc
4545
env:
4646
CPPFLAGS: "-DENABLE_PATH_CHECK=0" # https://github.com/actions/virtual-environments/issues/267
47+
- name: Fix load-relative shebangs
48+
run: ~/build_prefix/${{ matrix.ruby }}/bin/ruby --disable-gems fix-load-relative-shebangs.rb
4749
- name: Create archive
4850
run: tar czf ${{ matrix.ruby }}-${{ matrix.os }}.tar.gz -C ~/build_prefix ${{ matrix.ruby }}
4951
- name: Install Bundler if needed

‎fix-load-relative-shebangs.rb‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'rbconfig'
2+
3+
bindir = RbConfig::CONFIG["bindir"]
4+
5+
FIRST_LINE = "#!/bin/sh\n"
6+
RUBY_SHEBANG = %r{^#!/usr/bin/env ruby$}
7+
8+
Dir.glob("#{bindir}/*") do |file|
9+
if File.binread(file, FIRST_LINE.bytesize) == FIRST_LINE
10+
puts "Found load-relative prolog in #{file}, removing it"
11+
contents = File.binread(file)
12+
puts "Before:\n#{contents}\n===" if $VERBOSE
13+
14+
index = contents =~ RUBY_SHEBANG
15+
raise "Could not find ruby shebang in:\n#{contents}" unless index
16+
contents = contents[index..-1]
17+
18+
puts "After:\n#{contents}\n===" if $VERBOSE
19+
File.binwrite(file, contents)
20+
end
21+
end

0 commit comments

Comments
 (0)