diff --git a/lib/language_pack/ruby.rb b/lib/language_pack/ruby.rb index 7837ed03..e079293f 100644 --- a/lib/language_pack/ruby.rb +++ b/lib/language_pack/ruby.rb @@ -88,6 +88,20 @@ def best_practice_warnings end end + def warn_bad_binstubs + Dir["bin/{rake,bundle,rails}"].select do |binstub| + begin + if File.file?(binstub) + shebang = File.open(binstub, &:readline) + if !shebang.match %r{\A#!/usr/bin/env ruby(.exe)?\z} + warn("Binstub #{binstub} contains shebang #{shebang}. This may cause issues if the program specified is unavailable.", inline: true) + end + end + rescue EOFError + end + end + end + def compile instrument 'ruby.compile' do # check for new app at the beginning of the compile @@ -95,6 +109,7 @@ def compile Dir.chdir(build_path) remove_vendor_bundle warn_bundler_upgrade + warn_bad_binstubs install_ruby install_jvm setup_language_pack_environment diff --git a/spec/installers/heroku_ruby_installer_spec.rb b/spec/installers/heroku_ruby_installer_spec.rb index 6648a870..925e3a6c 100644 --- a/spec/installers/heroku_ruby_installer_spec.rb +++ b/spec/installers/heroku_ruby_installer_spec.rb @@ -48,4 +48,5 @@ end end + end diff --git a/spec/ruby_spec.rb b/spec/ruby_spec.rb index 02d9c97f..bc88d44c 100644 --- a/spec/ruby_spec.rb +++ b/spec/ruby_spec.rb @@ -2,18 +2,18 @@ describe LanguagePack::Ruby do describe "#install_binary" do - context "installing yarn" do - before do - @old_path = ENV['PATH'] - @old_stack = ENV['STACK'] - ENV['STACK'] = 'cedar-14' - end + before do + @old_path = ENV['PATH'] + @old_stack = ENV['STACK'] + ENV['STACK'] = 'cedar-14' + end - after do - ENV['PATH'] = @old_path - ENV['STACK'] = @old_stack - end + after do + ENV['PATH'] = @old_path + ENV['STACK'] = @old_stack + end + context "installing yarn" do it "sets up PATH" do Dir.mktmpdir do |build_path| Dir.mktmpdir do |cache_path| @@ -27,5 +27,45 @@ end end + describe "#warn_bad_binstubs" do + it "warns about malformed shebangs" do + Dir.mktmpdir do |build_path| + Dir.mktmpdir do |cache_path| + Dir.chdir(build_path) do + Dir.mkdir("bin") + File.open("bin/rake", 'w') { |f| f.write("#!/usr/bin/env ruby") } + File.open("bin/rails", 'w') { |f| f.write("#!/usr/bin/env ruby.exe") } + File.open("bin/bundle", 'w') { |f| f.write("#!/usr/bin/env ruby1.7") } + + ruby = LanguagePack::Ruby.new(build_path, cache_path) + output = capture(:stdout) { ruby.send(:warn_bad_binstubs) } + + expect(output).to include(<<-WARNING) +###### WARNING: + Binstub bin/bundle contains shebang #!/usr/bin/env ruby1.7. This may cause issues if the program specified is unavailable. + WARNING + end + end + end + end + + def capture(stream) + stream = stream.to_s + captured_stream = Tempfile.new(stream) + stream_io = eval("$#{stream}") + origin_stream = stream_io.dup + stream_io.reopen(captured_stream) + + yield + + stream_io.rewind + return captured_stream.read + ensure + captured_stream.close + captured_stream.unlink + stream_io.reopen(origin_stream) + end end + end + end