* transcode.c (econv_init): accept Encoding object as source_encoding
[ruby-svn.git] / tool / make-snapshot
blob65f5bd024dbe686d7c8b14d3c2149afbe95c1d29
1 #!/usr/bin/ruby -s
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 $patch_file &&= File.expand_path($patch_file)
21 path = ENV["PATH"].split(File::PATH_SEPARATOR)
22 %w[YACC BASERUBY RUBY MV MINIRUBY].each do |var|
23 cmd = ENV[var]
24 unless path.any? {|dir|
25 file = File.join(dir, cmd)
26 File.file?(file) and File.executable?(file)
28 abort "#{File.basename $0}: #{var} command not found - #{cmd}"
29 end
30 end
32 unless destdir = ARGV.shift
33 abort "usage: #{File.basename $0} new-directory-to-save [version ...]"
34 end
35 revisions = ARGV.empty? ? ["trunk"] : ARGV
36 unless tmp = $exported
37 FileUtils.mkpath(destdir)
38 destdir = File.expand_path(destdir)
39 tmp = Dir.mktmpdir("ruby-snapshot")
40 FileUtils.mkpath(tmp)
41 at_exit {
42 Dir.chdir "/"
43 FileUtils.rm_rf(tmp)
44 } unless $keep_temp
45 end
46 Dir.chdir tmp
48 def package(rev, destdir)
49 patchlevel = false
50 case rev
51 when /\Atrunk\z/, /\Abranches\//, /\Atags\//
52 url = SVNURL + rev
53 when /\Astable\z/
54 url = SVNURL + "branches/"
55 url = url + `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m, 1]
56 when /\A\(.*\..*\..*\)-/
57 patchlevel = true
58 url = SVNURL + "tags/v#{rev.sub(/-p?/, '_').tr('.', '_')}"
59 when /\./
60 url = SVNURL + "branches/ruby_#{rev.tr('.', '_')}"
61 else
62 warn "#{$0}: unknown version - #{rev}"
63 return
64 end
65 revision = `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
66 version = nil
67 unless revision
68 url = SVNURL + "trunk"
69 version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN, 1]
70 unless rev == version
71 warn "#{$0}: #{rev} not found"
72 return
73 end
74 revision = `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
75 end
76 unless $exported
77 puts "Exporting #{rev}@#{revision}"
78 IO.popen("svn export #{url} ruby") do |pipe|
79 pipe.each {|line| /^A/ =~ line or print line}
80 end
81 unless $?.success?
82 warn("Export failed")
83 return
84 end
85 end
87 if !File.directory?(v = "ruby")
88 v = Dir.glob("ruby-*").select(&File.method(:directory?))
89 v.size == 1 or abort "not exported"
90 v = v[0]
91 end
92 open("#{v}/revision.h", "wb") {|f| f.puts "#define RUBY_REVISION #{revision}"}
93 version ||= (versionhdr = IO.read("#{v}/version.h"))[RUBY_VERSION_PATTERN, 1]
94 version or return
95 if patchlevel
96 versionhdr ||= IO.read("#{v}/version.h")
97 patchlevel = versionhdr[/^\#define\s+RUBY_PATCHLEVEL\s+(\d+)/, 1]
98 tag = (patchlevel ? "p#{patchlevel}" : "r#{revision}")
99 else
100 tag = "r#{revision}"
102 v = "ruby-#{version}-#{tag}"
103 File.directory?(v) or File.rename "ruby", v
104 system("patch -d #{v} -p0 -i #{$patch_file}") if $patch_file
105 def (clean = []).add(n) push(n); n end
106 Dir.chdir(v) do
107 File.open(clean.add("cross.rb"), "w") {|f| f.puts "CROSS_COMPILING=true"}
108 unless File.exist?("configure")
109 print "creating configure..."
110 unless system("autoconf")
111 puts " failed"
112 return
114 puts " done"
116 clean.add("autom4te.cache")
117 print "creating prerequisites..."
118 if File.file?("common.mk") && /^prereq/ =~ commonmk = IO.read("common.mk")
119 puts
120 extout = clean.add('tmp')
121 File.open(clean.add("config.status"), "w") {|f|
122 f.puts "s,@configure_args@,|#_!!_#|,g"
123 f.puts "s,@EXTOUT@,|#_!!_#|#{extout},g"
124 f.puts "s,@bindir@,|#_!!_#|,g"
125 f.puts "s,@ruby_install_name@,|#_!!_#|,g"
126 f.puts "s,@ARCH_FLAG@,|#_!!_#|,g"
127 f.puts "s,@CFLAGS@,|#_!!_#|,g"
128 f.puts "s,@CPPFLAGS@,|#_!!_#|,g"
129 f.puts "s,@LDFLAGS@,|#_!!_#|,g"
130 f.puts "s,@DLDFLAGS@,|#_!!_#|,g"
131 f.puts "s,@LIBEXT@,|#_!!_#|a,g"
132 f.puts "s,@OBJEXT@,|#_!!_#|o,g"
133 f.puts "s,@LIBRUBY@,|#_!!_#|liburyb.a,g"
134 f.puts "s,@LIBRUBY_A@,|#_!!_#|liburyb.a,g"
136 FileUtils.mkpath(hdrdir = "#{extout}/include/ruby")
137 File.open("#{hdrdir}/config.h", "w") {}
138 miniruby = ENV['MINIRUBY'] + " -rcross"
139 IO.popen("make -f - prereq srcdir=. IFCHANGE=tool/ifchange 'MINIRUBY=#{miniruby}'", "w") do |f|
140 f.puts(IO.read("Makefile.in")[/^lex\.c.*?^$/m])
141 f.puts(commonmk.gsub(/\{[^{}]*\}/, ""))
143 clean.push("rbconfig.rb", ".rbconfig.time")
144 print "prerequisites"
145 else
146 system("#{YACC} -o parse.c parse.y")
148 FileUtils.rm_rf(clean)
149 unless $?.success?
150 puts " failed"
151 return
153 puts " done"
156 return [["bzip tarball", ".tar.bz2", %w"tar cjf"],
157 ["gzip tarball", ".tar.gz", %w"tar czf"],
158 ["zip archive", ".zip", %w"zip -qr"]
159 ].collect do |mesg, ext, cmd|
160 file = "#{destdir}/#{v}#{ext}"
161 print "creating #{mesg}... #{file}"
162 if system(*(cmd + [file, v]))
163 puts " done"
164 file
165 else
166 puts " failed"
169 end.compact
170 ensure
171 FileUtils.rm_rf(v) if v and !$exported and !$keep_temp
174 revisions.collect {|rev| package(rev, destdir)}.flatten.each do |name|
175 name or next
176 str = open(name, "rb") {|f| f.read}
177 md5 = Digest::MD5.hexdigest str
178 sha = Digest::SHA256.hexdigest str
179 puts "MD5(#{name})= #{md5}"
180 puts "SHA256(#{name})= #{sha}"
181 puts "SIZE(name)= #{str.size}"
182 puts