Report abuse


			
desc "freeze rails edge"
task :edge do
  ENV['SHARED_PATH']    = '../../shared' unless ENV['SHARED_PATH']
  ENV['GIT_FORK']     ||= 'rails'
  ENV['RAILS_PATH']   ||= File.join(ENV['SHARED_PATH'], 'rails')

  clone_path    = "git@github.com:#{ENV['GIT_FORK']}/rails.git"
  checkout_path = "#{ENV['RAILS_PATH']}/git"
  export_path   = "#{ENV['RAILS_PATH']}/rev_#{ENV['REVISION']}"
  symlink_path  = 'vendor/rails'

  unless File.exists?(ENV['RAILS_PATH'])
    mkdir_p ENV['RAILS_PATH']
  end

  # do we need to checkout the file?
  unless File.exists?(checkout_path)
    Dir.chdir ENV['RAILS_PATH'] do
      puts 'setting up rails trunk'
      system "git clone --depth 1 #{clone_path} git"
    end
  end

  # do we need to export the revision?
  unless File.exists?(export_path)
    puts "setting up rails rev #{ENV['REVISION']}"
    Dir.chdir checkout_path do
      system "git checkout master"
      system "git pull"
      system "git checkout #{ENV['REVISION']}"
    end
    get_framework_for export_path do |framework|
      cp_r "#{checkout_path}/#{framework}/lib", "#{export_path}/#{framework}"
    end
  end

  puts 'linking rails'
  rm_rf   symlink_path
  mkdir_p symlink_path

  get_framework_for symlink_path do |framework|
    ln_s File.expand_path("#{export_path}/#{framework}/lib"), "#{symlink_path}/#{framework}/lib"
  end

  touch "vendor/rails_#{ENV['REVISION']}"
end

def get_framework_for(*paths)
  %w( railties actionpack activerecord actionmailer activesupport activeresource ).each do |framework|
    paths.each { |path| mkdir_p "#{path}/#{framework}" }
    yield framework
  end
end