9 ENV["LC_ALL"] = ENV["LANG"] = "C"
10 SVNURL
= URI
.parse("http://svn.ruby-lang.org/repos/ruby/")
11 RUBY_VERSION_PATTERN
= /^\#define\s+RUBY_VERSION\s+"([\d.]+)"/
13 ENV["VPATH"] ||= "include/ruby"
14 YACC
= ENV["YACC"] ||= "bison"
15 ENV["BASERUBY"] ||= "ruby"
16 ENV["RUBY"] ||= "ruby"
18 ENV["MINIRUBY"] ||= "ruby"
20 path
= ENV["PATH"].split(File
::PATH_SEPARATOR)
21 %w
[YACC BASERUBY RUBY MV MINIRUBY
].each
do |var
|
23 unless path
.any
? {|dir
|
24 file
= File
.join(dir
, cmd
)
25 File
.file
?(file
) and File
.executable
?(file
)
27 abort
"#{File.basename $0}: #{var} command not found - #{cmd}"
31 unless destdir
= ARGV.shift
32 abort
"usage: #{File.basename $0} new-directory-to-save [version ...]"
34 FileUtils
.mkpath(destdir
)
35 destdir
= File
.expand_path(destdir
)
36 revisions
= ARGV.empty
? ? ["trunk"] : ARGV
37 tmp
= Dir
.mktmpdir("ruby-snapshot")
45 def package(rev
, destdir
)
48 when /\Atrunk\z/, /\Abranches\//, /\Atags\
//
51 url
= SVNURL
+ "branches/"
52 url
= url
+ `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m
, 1]
53 when /\A\(.*\..*\..*\)-/
55 url
= SVNURL
+ "tags/v#{rev.sub(/-p?/, '_').tr('.', '_')}"
57 url
= SVNURL
+ "branches/ruby_#{rev.tr('.', '_')}"
59 warn
"#{$0}: unknown version - #{rev}"
62 revision
= `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
65 url
= SVNURL
+ "trunk"
66 version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN
, 1]
68 warn
"#{$0}: #{rev} not found"
71 revision
= `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
73 puts
"Exporting #{rev}@#{revision}"
74 IO
.popen("svn export #{url} ruby") do |pipe
|
75 pipe
.each
{|line
| /^A/ =~ line
or print line
}
81 open("ruby/revision.h", "wb") {|f
| f
.puts
"#define RUBY_REVISION #{revision}"}
82 version ||= (versionhdr
= IO
.read("ruby/version.h"))[RUBY_VERSION_PATTERN
, 1]
85 versionhdr
||= IO
.read("ruby/version.h")
86 patchlevel
= versionhdr
[/^\#define\s+RUBY_PATCHLEVEL\s+(\d+)/, 1]
87 tag
= (patchlevel
? "p#{patchlevel}" : "r#{revision}")
91 v
= "ruby-#{version}-#{tag}"
94 print
"creating configure..."
95 unless system("autoconf")
100 FileUtils
.rm_rf("autom4te.cache")
101 print
"creating prerequisites..."
102 if File
.file
?("common.mk") && /^prereq/ =~ commonmk
= IO
.read("common.mk")
103 IO
.popen("make -f - prereq srcdir=. IFCHANGE=tool/ifchange", "w") do |f
|
104 f
.puts(IO
.read("Makefile.in")[/^lex\.c.*?^$/m
])
105 f
.puts(commonmk
.gsub(/\{[^{}]*\}/, ""))
108 system("#{YACC} -o parse.c parse.y")
117 return [["bzip tarball", ".tar.bz2", %w
"tar cjf"],
118 ["gzip tarball", ".tar.gz", %w
"tar czf"],
119 ["zip archive", ".zip", %w
"zip -qr"]
120 ].collect
do |mesg
, ext
, cmd
|
121 file
= "#{destdir}/#{v}#{ext}"
122 print
"creating #{mesg}... #{file}"
123 if system(*(cmd
+ [file
, v
]))
132 FileUtils
.rm_rf(v
) if v
135 revisions
.collect
{|rev
| package(rev
, destdir
)}.flatten
.each
do |name
|
136 str
= open(name
, "rb") {|f
| f
.read
}
137 md5
= Digest
::MD5.hexdigest str
138 sha
= Digest
::SHA256.hexdigest str
139 puts
"MD5(#{name})= #{md5}"
140 puts
"SHA256(#{name})= #{sha}"
141 puts
"SIZE(name)= #{str.size}"