diff options
Diffstat (limited to 'railties/lib/rails')
-rw-r--r-- | railties/lib/rails/app_rails_loader.rb | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/railties/lib/rails/app_rails_loader.rb b/railties/lib/rails/app_rails_loader.rb index aae628290d..4a17803f1c 100644 --- a/railties/lib/rails/app_rails_loader.rb +++ b/railties/lib/rails/app_rails_loader.rb @@ -4,28 +4,7 @@ module Rails module AppRailsLoader RUBY = File.join(*RbConfig::CONFIG.values_at("bindir", "ruby_install_name")) + RbConfig::CONFIG["EXEEXT"] EXECUTABLES = ['bin/rails', 'script/rails'] - - def self.exec_app_rails - original_cwd = Dir.pwd - - until exe = find_executable - # If we exhaust the search there is no executable, this could be a - # call to generate a new application, so restore the original cwd. - Dir.chdir(original_cwd) and return if Pathname.new(Dir.pwd).root? - - # Otherwise keep moving upwards in search of a executable. - Dir.chdir('..') - end - - contents = File.read(exe) - - # This is the Rails executable, let's use it - if contents =~ /(APP|ENGINE)_PATH/ - exec RUBY, exe, *ARGV - - # This is a Bundler binstub. Stop and explain how to upgrade. - elsif exe =~ /bin\/rails$/ && contents =~ /This file was generated by Bundler/ - $stderr.puts <<-end_bin_upgrade_warning + BUNDLER_WARNING = <<EOS Looks like your app's ./bin/rails is a stub that was generated by Bundler. In Rails 4, your app's bin/ directory contains executables that are versioned @@ -45,14 +24,34 @@ generate it and add it to source control: bundle binstubs some-gem-name git add bin/new-executable - end_bin_upgrade_warning +EOS + + def self.exec_app_rails + original_cwd = Dir.pwd + + loop do + if exe = find_executable + contents = File.read(exe) + + if contents =~ /(APP|ENGINE)_PATH/ + exec RUBY, exe, *ARGV + break # non reachable, hack to be able to stub exec in the test suite + elsif exe.end_with?('bin/rails') && contents.include?('This file was generated by Bundler') + $stderr.puts(BUNDLER_WARNING) + Object.const_set(:APP_PATH, File.expand_path('config/application', Dir.pwd)) + require File.expand_path('../boot', APP_PATH) + require 'rails/commands' + break + end + end - Object.const_set(:APP_PATH, File.expand_path('config/application', Dir.pwd)) - require File.expand_path('../boot', APP_PATH) - require 'rails/commands' + # If we exhaust the search there is no executable, this could be a + # call to generate a new application, so restore the original cwd. + Dir.chdir(original_cwd) and return if Pathname.new(Dir.pwd).root? + + # Otherwise keep moving upwards in search of a executable. + Dir.chdir('..') end - rescue SystemCallError - # could not chdir, no problem just return end def self.find_executable |