* transcode.c (trans_open_i): check the result of rb_transcoding_open.
[ruby-svn.git] / tool / make-snapshot
blob997582b636cf6878b43af5d6d15bd19664bc5739
1 #!/usr/bin/ruby
2 require 'uri'
3 require 'digest/md5'
4 require 'digest/sha2'
5 require 'fileutils'
6 require 'tmpdir'
7 STDOUT.sync = true
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"
17 ENV["MV"] ||= "mv"
18 ENV["MINIRUBY"] ||= "ruby"
20 path = ENV["PATH"].split(File::PATH_SEPARATOR)
21 %w[YACC BASERUBY RUBY MV MINIRUBY].each do |var|
22 cmd = ENV[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}"
28 end
29 end
31 unless destdir = ARGV.shift
32 abort "usage: #{File.basename $0} new-directory-to-save [version ...]"
33 end
34 FileUtils.mkpath(destdir)
35 destdir = File.expand_path(destdir)
36 revisions = ARGV.empty? ? ["trunk"] : ARGV
37 tmp = Dir.mktmpdir("ruby-snapshot")
38 FileUtils.mkpath(tmp)
39 at_exit {
40 Dir.chdir "/"
41 FileUtils.rm_rf(tmp)
43 Dir.chdir tmp
45 def package(rev, destdir)
46 patchlevel = false
47 case rev
48 when /\Atrunk\z/, /\Abranches\//, /\Atags\//
49 url = SVNURL + rev
50 when /\Astable\z/
51 url = SVNURL + "branches/"
52 url = url + `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m, 1]
53 when /\A\(.*\..*\..*\)-/
54 patchlevel = true
55 url = SVNURL + "tags/v#{rev.sub(/-p?/, '_').tr('.', '_')}"
56 when /\./
57 url = SVNURL + "branches/ruby_#{rev.tr('.', '_')}"
58 else
59 warn "#{$0}: unknown version - #{rev}"
60 return
61 end
62 revision = `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
63 version = nil
64 unless revision
65 url = SVNURL + "trunk"
66 version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN, 1]
67 unless rev == version
68 warn "#{$0}: #{rev} not found"
69 return
70 end
71 revision = `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
72 end
73 puts "Exporting #{rev}@#{revision}"
74 IO.popen("svn export #{url} ruby") do |pipe|
75 pipe.each {|line| /^A/ =~ line or print line}
76 end
77 unless $?.success?
78 warn("Export failed")
79 return
80 end
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]
83 version or return
84 if patchlevel
85 versionhdr ||= IO.read("ruby/version.h")
86 patchlevel = versionhdr[/^\#define\s+RUBY_PATCHLEVEL\s+(\d+)/, 1]
87 tag = (patchlevel ? "p#{patchlevel}" : "r#{revision}")
88 else
89 tag = "r#{revision}"
90 end
91 v = "ruby-#{version}-#{tag}"
92 File.rename "ruby", v
93 Dir.chdir(v) do
94 print "creating configure..."
95 unless system("autoconf")
96 puts " failed"
97 return
98 end
99 puts " done"
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(/\{[^{}]*\}/, ""))
107 else
108 system("#{YACC} -o parse.c parse.y")
110 unless $?.success?
111 puts " failed"
112 return
114 puts " done"
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]))
124 puts " done"
125 file
126 else
127 puts " failed"
130 end.compact
131 ensure
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}"
142 puts