Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails 4 prints help for "rails new" when running "rails console" #9843

Merged
merged 4 commits into from Apr 9, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 20 additions & 10 deletions railties/lib/rails/app_rails_loader.rb
Expand Up @@ -12,25 +12,35 @@ def self.exec_app_rails
exe ||= find_executable_in_parent_path
return unless exe

exec RUBY, exe, *ARGV if find_executable
Dir.chdir("..") do
# Recurse in a chdir block: if the search fails we want to be sure
# the application is generated in the original working directory.
exec_app_rails unless cwd == Dir.pwd
if File.read(exe) =~ /(APP|ENGINE)_PATH/
# This is a Rails-generated binstub, let's use it
exec RUBY, exe, *ARGV if find_executable
Dir.chdir("..") do
# Recurse in a chdir block: if the search fails we want to be sure
# the application is generated in the original working directory.
exec_app_rails unless cwd == Dir.pwd
end
elsif exe.match(%r(bin/rails$))
# this is a Bundler binstub, so we load the app ourselves
Object.const_set(:APP_PATH, File.expand_path('config/application', Dir.pwd))
require File.expand_path('../boot', APP_PATH)
puts "Rails 4 no longer supports Bundler's --binstubs option. You " \
"will need to disable it and update your bin/rails file.\n" \
"Please run: `bundle config --delete bin && rm -rf bin`, then " \
"`rake rails:update:bin` and add the resulting bin/ to git."
require 'rails/commands'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This'll work if you installed the rails 4 gem and call rails in a Rails 4 app.

Consider a Rails 3 app, though: we'll try to load the app directly, but using a possibly-wrong Ruby version and an already-activated Rails 4 gem.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errr... how is that possible if both the Rails 3 app and the Rails 4 app are using Bundler? I'm having trouble reproducing that scenario. In fact, in my testing, it's impossible to get the wrong one unless you delete the Gemfile with Rails 3 in it:

andre ~/sw/gems/bundler-testcases/binstubs-rails4/rails3 $ rails _4.0.0.beta1_ -v
Rails 3.2.13
andre ~/sw/gems/bundler-testcases/binstubs-rails4/rails3 $ rm Gemfile
andre ~/sw/gems/bundler-testcases/binstubs-rails4/rails3 $ rails _4.0.0.beta1_ -v
Rails 4.0.0.beta1

end
rescue SystemCallError
# could not chdir, no problem just return
end

def self.find_executable
EXECUTABLES.find do |exe|
File.exists?(exe) && File.read(exe) =~ /(APP|ENGINE)_PATH/
end
EXECUTABLES.find { |exe| File.exists?(exe) }
end

def self.find_executable_in_parent_path(path = Pathname.new(Dir.pwd))
def self.find_executable_in_parent_path(path = Pathname.new(Dir.pwd).parent)
EXECUTABLES.find do |exe|
File.exists?(File.join(path, exe)) || !path.root? && find_executable_in_parent_path(path.parent)
File.exists?(exe) || !path.root? && find_executable_in_parent_path(path.parent)
end
end
end
Expand Down