@@ -252,6 +252,28 @@ def setup_profiled
252252 # install the vendored ruby
253253 # @return [Boolean] true if it installs the vendored ruby and false otherwise
254254 def install_ruby
255+ if system_ruby
256+ install_system_ruby system_ruby
257+ else
258+ install_ruby_orig
259+ end
260+ end
261+
262+ def install_system_ruby ( ruby )
263+ instrument 'ruby.install_system_ruby' do
264+ dir = File . dirname ( ruby )
265+ file = File . basename ( ruby )
266+
267+ install_symlink ( "ruby" , "#{ dir } /#{ file } " )
268+ install_symlink ( "gem" , "#{ dir } /#{ file . gsub ( "ruby" , "gem" ) } " )
269+ install_symlink ( "ri" , "#{ dir } /#{ file . gsub ( "ruby" , "ri" ) } " )
270+ install_symlink ( "rdoc" , "#{ dir } /#{ file . gsub ( "ruby" , "rdoc" ) } " )
271+
272+ ENV [ "PATH" ] = "#{ File . expand_path ( "bin" ) } :#{ ENV [ "PATH" ] } "
273+ end
274+ end
275+
276+ def install_ruby_orig
255277 instrument 'ruby.install_ruby' do
256278 return false unless ruby_version
257279
@@ -416,14 +438,26 @@ def install_binary(name)
416438 end
417439 end
418440
441+ def install_symlink ( name , file )
442+ bin_dir = "bin"
443+ FileUtils . mkdir_p bin_dir
444+ Dir . chdir ( bin_dir ) do |dir |
445+ File . symlink ( file , name ) unless File . exists? ( name )
446+ end
447+ end
448+
419449 # removes a binary from the slug
420450 # @param [String] relative path of the binary on the slug
421451 def uninstall_binary ( path )
422452 FileUtils . rm File . join ( 'bin' , File . basename ( path ) ) , :force => true
423453 end
424454
455+ def system_ruby
456+ ENV [ "SYSTEM_RUBY" ]
457+ end
458+
425459 def load_default_cache?
426- new_app? && ruby_version . default?
460+ new_app? && ruby_version . default? && ! system_ruby
427461 end
428462
429463 # loads a default bundler cache for new apps to speed up initial bundle installs
0 commit comments