#!/usr/bin/env jruby
# -*- coding: utf-8 -*-
# This script is for use with JRuby, to copy the (patched) stdlib and external test files from
# various locations in MRI's layout to JRuby's layout. It should be used
# against the jruby-specific fork of MRI's repository at
# github.com/jruby/ruby.
#
# This script selects the branch to use against with the version number, i.e: jruby-ruby_1_8_7 or jruby-ruby_1_9_3.
#
# usage: sync_ruby
#
# Example:
#
# The JRuby ruby fork is in ../jruby-ruby, and jruby is in the current directory.
# We want to sync both 1.8.7 standard libraries.
#
# $ jruby tool/sync_ruby stdlib 1_8_7 ../jruby-ruby .
# ~/projects/jruby jruby tool/sync_ruby stdlib 1_8_7 ../jruby-ruby .
# Already on 'jruby-ruby_1_8_7'
# cp -r ../jruby-ruby/lib/English.rb ./lib/ruby/1.8
# cp -r ../jruby-ruby/lib/Env.rb ./lib/ruby/1.8
# ...
require 'fileutils'
class Sync
include FileUtils
def initialize(type, version, source, target)
@type = type
@named_version = version
@version = format_version(version)
@source = source
@target = target
checkout
end
def sync_tests
Dir.glob("#{@source}/test/*") do |file|
cp_r file, "#{@target}/test/mri", :verbose => true
end
end
def sync_stdlib
load File.dirname(__FILE__) + "/globals_#{@named_version}.rb"
for file in STDLIB_FILES
cp_r "#{@source}/lib/#{file}", "#{@target}/lib/ruby/#{@version}", :verbose => true
end
for file, target in EXT_FILES
if File.directory? "#{@source}/#{file}"
cp_r "#{@source}/#{file}", "#{@target}/lib/ruby/#{@version}/", :verbose => true
else
cp_r "#{@source}/#{file}", "#{@target}/lib/ruby/#{@version}/#{target}", :verbose => true
end
end
end
def sync_rubygems
if Dir.pwd != File.expand_path('../..', __FILE__) || @target != '.'
$stderr.puts "Rubygems is sync'd into the jruby where this script was launched."
$stderr.puts "To acknowledge this, run in the top level of that jruby tree and use a target of `.'."
raise ArgumentError, "Sync Rubygems target mismatch"
end
(Dir["#@target/lib/ruby/site_ruby/1.8/*ubygems"] + ["#@target/lib/ruby/site_ruby/1.8/rbconfig"]).each do |f|
rm_rf f
end
cd(@source) do
system "ruby setup.rb --no-format-executable --no-ri --no-rdoc"
end
gem_script = File.join(@target, "bin", "gem")
# Fix up shebang so it doesn't have abs path
lines = IO.readlines gem_script
lines[0] = "#!/usr/bin/env jruby\n"
File.open(gem_script, "wb") {|f| lines.each {|l| f