Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 9215

Show
Ignore:
Timestamp:
04/02/08 17:48:30 (8 months ago)
Author:
rick
Message:

Flesh out rake gems:unpack to unpack all gems, and add rake gems:build for native extensions. Closes #11513 [ddollar]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/railties/CHANGELOG

    r9204 r9215  
    11*SVN* 
     2 
     3* Flesh out rake gems:unpack to unpack all gems, and add rake gems:build for native extensions.  [ddollar] 
     4 
     5  rake gems:unpack             # unpacks all gems 
     6  rake gems:unpack GEM=mygem   # unpacks only the gem 'mygem' 
     7   
     8  rake gems:build              # builds all unpacked gems 
     9  rake gems:build GEM=mygem    # builds only the gem 'mygem' 
    210 
    311* Add config.active_support for future configuration options.  Also, add more new Rails 3 config settings to new_rails_defaults.rb [rick] 
  • trunk/railties/lib/initializer.rb

    r9211 r9215  
    88require 'rails/plugin/locator' 
    99require 'rails/plugin/loader' 
     10require 'rails/gem_builder' 
    1011require 'rails/gem_dependency' 
    1112 
  • trunk/railties/lib/rails/gem_dependency.rb

    r9197 r9215  
    3434      puts $!.to_s 
    3535    end 
     36     
     37    def gem_dir(base_directory) 
     38      File.join(base_directory, specification.full_name) 
     39    end 
    3640 
    3741    def load 
     
    5559      Gem::GemRunner.new.run(install_command) 
    5660    end 
     61     
     62    def specification 
     63      @spec ||= Gem.source_index.search(Gem::Dependency.new(@name, @requirement)).sort_by { |s| s.version }.last 
     64    end 
    5765 
    5866    def unpack_to(directory) 
     
    6068      Dir.chdir directory do 
    6169        Gem::GemRunner.new.run(unpack_command) 
     70      end 
     71       
     72      # copy the gem's specification into GEMDIR/.specification so that 
     73      # we can access information about the gem on deployment systems 
     74      # without having the gem installed 
     75      spec_filename = File.join(gem_dir(directory), '.specification') 
     76      File.open(spec_filename, 'w') do |file| 
     77        file.puts specification.to_yaml 
    6278      end 
    6379    end 
  • trunk/railties/lib/tasks/gems.rake

    r9140 r9215  
    77 
    88namespace :gems do 
     9  desc "Build any native extensions for unpacked gems" 
     10  task :build do 
     11    Dir[File.join(RAILS_ROOT, 'vendor', 'gems', '*')].each do |gem_dir| 
     12      spec_file = File.join(gem_dir, '.specification') 
     13      next unless File.exists?(spec_file) 
     14      specification = YAML::load_file(spec_file) 
     15      next unless ENV['GEM'].blank? || ENV['GEM'] == specification.name 
     16      Rails::GemBuilder.new(specification, gem_dir).build_extensions 
     17      puts "Built gem: '#{gem_dir}'" 
     18    end 
     19  end 
     20   
    921  desc "Installs all required gems for this application." 
    1022  task :install => :environment do 
     
    1628  desc "Unpacks the specified gem into vendor/gems." 
    1729  task :unpack do 
    18     raise "Specify name of gem in the config.gems array with GEM=" if ENV['GEM'].blank? 
    1930    Rake::Task["environment"].invoke 
    2031    require 'rubygems' 
    2132    require 'rubygems/gem_runner' 
    22     unless Rails.configuration.gems.select do |gem| 
    23       if gem.loaded? && gem.name == ENV['GEM'] 
    24         gem.unpack_to(File.join(RAILS_ROOT, 'vendor', 'gems')) 
    25         true 
    26       end 
    27     end.any? 
    28       puts "No gem named #{ENV['GEM'].inspect} found." 
     33    Rails.configuration.gems.each do |gem| 
     34      next unless ENV['GEM'].blank? || ENV['GEM'] == gem.name 
     35      gem.unpack_to(File.join(RAILS_ROOT, 'vendor', 'gems')) if gem.loaded? 
    2936    end 
    3037  end