2017-08-14 13:08:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:15:47 -04:00
|
|
|
require "pathname"
|
2017-10-21 09:08:33 -04:00
|
|
|
require "rails/version"
|
2013-01-06 18:13:47 -05:00
|
|
|
|
|
|
|
module Rails
|
2015-04-22 23:05:30 -04:00
|
|
|
module AppLoader # :nodoc:
|
2014-07-07 21:05:30 -04:00
|
|
|
extend self
|
|
|
|
|
2013-09-09 11:06:02 -04:00
|
|
|
RUBY = Gem.ruby
|
2016-08-06 13:15:47 -04:00
|
|
|
EXECUTABLES = ["bin/rails", "script/rails"]
|
2013-04-11 07:18:16 -04:00
|
|
|
BUNDLER_WARNING = <<EOS
|
2017-08-03 16:42:54 -04:00
|
|
|
Beginning in Rails 4, Rails ships with a `rails` binstub at ./bin/rails that
|
|
|
|
should be used instead of the Bundler-generated `rails` binstub.
|
2013-04-09 19:49:01 -04:00
|
|
|
|
2017-08-03 16:42:54 -04:00
|
|
|
If you are seeing this message, your binstub at ./bin/rails was generated by
|
|
|
|
Bundler instead of Rails.
|
2013-04-09 19:49:01 -04:00
|
|
|
|
2017-08-03 16:42:54 -04:00
|
|
|
You might need to regenerate your `rails` binstub locally and add it to source
|
|
|
|
control:
|
|
|
|
|
|
|
|
rails app:update:bin # Bear in mind this generates other binstubs
|
|
|
|
# too that you may or may not want (like yarn)
|
|
|
|
|
|
|
|
If you already have Rails binstubs in source control, you might be
|
2019-02-01 06:12:40 -05:00
|
|
|
inadvertently overwriting them during deployment by using bundle install
|
2017-08-03 16:42:54 -04:00
|
|
|
with the --binstubs option.
|
2017-07-26 21:12:52 -04:00
|
|
|
|
|
|
|
If your application was created prior to Rails 4, here's how to upgrade:
|
2013-04-09 19:49:01 -04:00
|
|
|
|
|
|
|
bundle config --delete bin # Turn off Bundler's stub generator
|
2017-07-26 21:12:52 -04:00
|
|
|
rails app:update:bin # Use the new Rails executables
|
2013-04-09 19:49:01 -04:00
|
|
|
git add bin # Add bin/ to source control
|
|
|
|
|
|
|
|
You may need to remove bin/ from your .gitignore as well.
|
|
|
|
|
|
|
|
When you install a gem whose executable you want to use in your app,
|
|
|
|
generate it and add it to source control:
|
|
|
|
|
|
|
|
bundle binstubs some-gem-name
|
|
|
|
git add bin/new-executable
|
|
|
|
|
2013-04-11 07:18:16 -04:00
|
|
|
EOS
|
|
|
|
|
2015-04-22 23:05:30 -04:00
|
|
|
def exec_app
|
2013-04-11 07:18:16 -04:00
|
|
|
original_cwd = Dir.pwd
|
|
|
|
|
|
|
|
loop do
|
|
|
|
if exe = find_executable
|
|
|
|
contents = File.read(exe)
|
|
|
|
|
2018-07-28 17:37:17 -04:00
|
|
|
if /(APP|ENGINE)_PATH/.match?(contents)
|
2013-04-11 07:18:16 -04:00
|
|
|
exec RUBY, exe, *ARGV
|
|
|
|
break # non reachable, hack to be able to stub exec in the test suite
|
2016-08-06 13:15:47 -04:00
|
|
|
elsif exe.end_with?("bin/rails") && contents.include?("This file was generated by Bundler")
|
2013-04-11 07:18:16 -04:00
|
|
|
$stderr.puts(BUNDLER_WARNING)
|
2016-08-06 13:15:47 -04:00
|
|
|
Object.const_set(:APP_PATH, File.expand_path("config/application", Dir.pwd))
|
|
|
|
require File.expand_path("../boot", APP_PATH)
|
2017-10-21 09:08:33 -04:00
|
|
|
require "rails/commands"
|
2013-04-11 07:18:16 -04:00
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2013-04-09 19:49:01 -04:00
|
|
|
|
2013-04-11 07:18:16 -04:00
|
|
|
# If we exhaust the search there is no executable, this could be a
|
|
|
|
# call to generate a new application, so restore the original cwd.
|
2016-09-01 17:41:49 -04:00
|
|
|
Dir.chdir(original_cwd) && return if Pathname.new(Dir.pwd).root?
|
2013-04-11 07:18:16 -04:00
|
|
|
|
2013-09-13 04:44:35 -04:00
|
|
|
# Otherwise keep moving upwards in search of an executable.
|
2016-08-06 13:15:47 -04:00
|
|
|
Dir.chdir("..")
|
2013-01-06 18:13:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-07-07 21:05:30 -04:00
|
|
|
def find_executable
|
2014-01-24 13:00:31 -05:00
|
|
|
EXECUTABLES.find { |exe| File.file?(exe) }
|
2013-01-06 18:13:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|