aboutsummaryrefslogtreecommitdiffstats
path: root/railties/lib
diff options
context:
space:
mode:
Diffstat (limited to 'railties/lib')
-rw-r--r--railties/lib/commands/server.rb1
-rw-r--r--railties/lib/console_app.rb2
-rw-r--r--railties/lib/initializer.rb33
-rw-r--r--railties/lib/rails/backtrace_cleaner.rb3
-rw-r--r--railties/lib/rails/gem_dependency.rb21
-rw-r--r--railties/lib/rails/plugin.rb3
-rw-r--r--railties/lib/tasks/gems.rake18
-rw-r--r--railties/lib/tasks/misc.rake6
8 files changed, 72 insertions, 15 deletions
diff --git a/railties/lib/commands/server.rb b/railties/lib/commands/server.rb
index ebe34a42cd..91ac7752ef 100644
--- a/railties/lib/commands/server.rb
+++ b/railties/lib/commands/server.rb
@@ -1,4 +1,3 @@
-require 'active_support'
require 'action_controller'
require 'fileutils'
diff --git a/railties/lib/console_app.rb b/railties/lib/console_app.rb
index d7d01d703f..5c8302634a 100644
--- a/railties/lib/console_app.rb
+++ b/railties/lib/console_app.rb
@@ -1,3 +1,5 @@
+require 'active_support'
+require 'active_support/core/all'
require 'active_support/test_case'
require 'action_controller'
diff --git a/railties/lib/initializer.rb b/railties/lib/initializer.rb
index a03be59a2b..71366a4480 100644
--- a/railties/lib/initializer.rb
+++ b/railties/lib/initializer.rb
@@ -5,12 +5,9 @@ require 'pathname'
$LOAD_PATH.unshift File.dirname(__FILE__)
require 'railties_path'
require 'rails/version'
-require 'rails/plugin/locator'
-require 'rails/plugin/loader'
require 'rails/gem_dependency'
require 'rails/rack'
-
RAILS_ENV = (ENV['RAILS_ENV'] || 'development').dup unless defined?(RAILS_ENV)
module Rails
@@ -159,6 +156,8 @@ module Rails
add_support_load_paths
+ check_for_unbuilt_gems
+
load_gems
load_plugins
@@ -244,6 +243,7 @@ module Rails
# Set the paths from which Rails will automatically load source files, and
# the load_once paths.
def set_autoload_paths
+ require 'active_support/dependencies'
ActiveSupport::Dependencies.load_paths = configuration.load_paths.uniq
ActiveSupport::Dependencies.load_once_paths = configuration.load_once_paths.uniq
@@ -263,6 +263,8 @@ module Rails
# list. By default, all frameworks (Active Record, Active Support,
# Action Pack, Action Mailer, and Active Resource) are loaded.
def require_frameworks
+ require 'active_support'
+ require 'active_support/core/all'
configuration.frameworks.each { |framework| require(framework.to_s) }
rescue LoadError => e
# Re-raise as RuntimeError because Mongrel would swallow LoadError.
@@ -289,10 +291,12 @@ module Rails
# Adds all load paths from plugins to the global set of load paths, so that
# code from plugins can be required (explicitly or automatically via ActiveSupport::Dependencies).
def add_plugin_load_paths
+ require 'active_support/dependencies'
plugin_loader.add_plugin_load_paths
end
def add_gem_load_paths
+ require 'rails/gem_dependency'
Rails::GemDependency.add_frozen_gem_path
unless @configuration.gems.empty?
require "rubygems"
@@ -306,6 +310,25 @@ module Rails
end
end
+ def check_for_unbuilt_gems
+ unbuilt_gems = @configuration.gems.select(&:frozen?).reject(&:built?)
+ if unbuilt_gems.size > 0
+ # don't print if the gems:build rake tasks are being run
+ unless $gems_build_rake_task
+ abort <<-end_error
+The following gems have native components that need to be built
+ #{unbuilt_gems.map { |gem| "#{gem.name} #{gem.requirement}" } * "\n "}
+
+You're running:
+ ruby #{Gem.ruby_version} at #{Gem.ruby}
+ rubygems #{Gem::RubyGemsVersion} at #{Gem.path * ', '}
+
+Run `rake gems:build` to build the unbuilt gems.
+ end_error
+ end
+ end
+ end
+
def check_gem_dependencies
unloaded_gems = @configuration.gems.reject { |g| g.loaded? }
if unloaded_gems.size > 0
@@ -568,7 +591,7 @@ Run `rake gems:install` to install the missing gems.
Rails::Rack::Metal.metal_paths += plugin_loader.engine_metal_paths
configuration.middleware.insert_before(
- :"ActionDispatch::RewindableInput",
+ :"ActionDispatch::ParamsParser",
Rails::Rack::Metal, :if => Rails::Rack::Metal.metals.any?)
end
@@ -1037,12 +1060,14 @@ Run `rake gems:install` to install the missing gems.
end
def default_plugin_locators
+ require 'rails/plugin/locator'
locators = []
locators << Plugin::GemLocator if defined? Gem
locators << Plugin::FileSystemLocator
end
def default_plugin_loader
+ require 'rails/plugin/loader'
Plugin::Loader
end
diff --git a/railties/lib/rails/backtrace_cleaner.rb b/railties/lib/rails/backtrace_cleaner.rb
index 923ed8b31d..1605429e8b 100644
--- a/railties/lib/rails/backtrace_cleaner.rb
+++ b/railties/lib/rails/backtrace_cleaner.rb
@@ -1,3 +1,6 @@
+require 'active_support/backtrace_cleaner'
+require 'rails/gem_dependency'
+
module Rails
class BacktraceCleaner < ActiveSupport::BacktraceCleaner
ERB_METHOD_SIG = /:in `_run_erb_.*/
diff --git a/railties/lib/rails/gem_dependency.rb b/railties/lib/rails/gem_dependency.rb
index 3062a77104..ee3d0d81ba 100644
--- a/railties/lib/rails/gem_dependency.rb
+++ b/railties/lib/rails/gem_dependency.rb
@@ -29,6 +29,15 @@ module Rails
end
end
+ def self.from_directory_name(directory_name)
+ directory_name_parts = File.basename(directory_name).split('-')
+ name = directory_name_parts[0..-2].join('-')
+ version = directory_name_parts.last
+ self.new(name, :version => version)
+ rescue ArgumentError => e
+ raise "Unable to determine gem name and version from '#{directory_name}'"
+ end
+
def initialize(name, options = {})
require 'rubygems' unless Object.const_defined?(:Gem)
@@ -101,8 +110,12 @@ module Rails
end
def built?
- # TODO: If Rubygems ever gives us a way to detect this, we should use it
- false
+ return false unless frozen?
+ specification.extensions.each do |ext|
+ makefile = File.join(unpacked_gem_directory, File.dirname(ext), 'Makefile')
+ return false unless File.exists?(makefile)
+ end
+ true
end
def framework_gem?
@@ -155,9 +168,9 @@ module Rails
specification && File.exists?(unpacked_gem_directory)
end
- def build
+ def build(options={})
require 'rails/gem_builder'
- unless built?
+ if options[:force] || !built?
return unless File.exists?(unpacked_specification_filename)
spec = YAML::load_file(unpacked_specification_filename)
Rails::GemBuilder.new(spec, unpacked_gem_directory).build_extensions
diff --git a/railties/lib/rails/plugin.rb b/railties/lib/rails/plugin.rb
index dd840ef058..0f924724cd 100644
--- a/railties/lib/rails/plugin.rb
+++ b/railties/lib/rails/plugin.rb
@@ -1,6 +1,3 @@
-require 'active_support/core_ext/kernel/reporting'
-require 'active_support/dependencies'
-
module Rails
# The Plugin class should be an object which provides the following methods:
#
diff --git a/railties/lib/tasks/gems.rake b/railties/lib/tasks/gems.rake
index ed07bf2016..efadb1da3b 100644
--- a/railties/lib/tasks/gems.rake
+++ b/railties/lib/tasks/gems.rake
@@ -20,8 +20,16 @@ namespace :gems do
desc "Build any native extensions for unpacked gems"
task :build do
$gems_build_rake_task = true
- Rake::Task['gems:unpack'].invoke
- current_gems.each &:build
+ frozen_gems.each &:build
+ end
+
+ namespace :build do
+ desc "Force the build of all gems"
+ task :force do
+ $gems_build_rake_task = true
+ Rake::Task['gems:unpack'].invoke
+ current_gems.each { |gem| gem.build(:force => true) }
+ end
end
desc "Installs all required gems."
@@ -53,6 +61,12 @@ def current_gems
gems
end
+def frozen_gems
+ Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*-*')].map do |gem_dir|
+ Rails::GemDependency.from_directory_name(gem_dir)
+ end
+end
+
def print_gem_status(gem, indent=1)
code = case
when gem.framework_gem? then 'R'
diff --git a/railties/lib/tasks/misc.rake b/railties/lib/tasks/misc.rake
index 9e6f96db5b..a2c338aa5b 100644
--- a/railties/lib/tasks/misc.rake
+++ b/railties/lib/tasks/misc.rake
@@ -12,10 +12,10 @@ end
desc 'Generate a crytographically secure secret key. This is typically used to generate a secret for cookie sessions.'
task :secret do
+ require 'active_support/secure_random'
puts ActiveSupport::SecureRandom.hex(64)
end
-require 'active_support'
namespace :time do
namespace :zones do
desc 'Displays names of all time zones recognized by the Rails TimeZone class, grouped by offset. Results can be filtered with optional OFFSET parameter, e.g., OFFSET=-6'
@@ -30,6 +30,8 @@ namespace :time do
desc 'Displays names of time zones recognized by the Rails TimeZone class with the same offset as the system local time'
task :local do
+ require 'active_support'
+ require 'active_support/core/time'
jan_offset = Time.now.beginning_of_year.utc_offset
jul_offset = Time.now.beginning_of_year.change(:month => 7).utc_offset
offset = jan_offset < jul_offset ? jan_offset : jul_offset
@@ -38,6 +40,8 @@ namespace :time do
# to find UTC -06:00 zones, OFFSET can be set to either -6, -6:00 or 21600
def build_time_zone_list(method, offset = ENV['OFFSET'])
+ require 'active_support'
+ require 'active_support/core/time'
if offset
offset = if offset.to_s.match(/(\+|-)?(\d+):(\d+)/)
sign = $1 == '-' ? -1 : 1