ZenTest 4.11.0 → 4.12.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/multiruby.rb DELETED
@@ -1,413 +0,0 @@
1
- require 'fileutils'
2
- require 'open-uri'
3
-
4
- ##
5
- # multiruby_setup is a script to help you manage multiruby.
6
- #
7
- # usage: multiruby_setup [-h|cmd|spec...]
8
- #
9
- # cmds:
10
- #
11
- # -h, --help, help = show this help.
12
- # build = build and install everything. used internally.
13
- # clean = clean scm build dirs and remove non-scm build dirs.
14
- # list = print installed versions.
15
- # rm:$version = remove a particular version.
16
- # rubygems:merge = symlink all rubygem dirs to one dir.
17
- # tags = list all tags from svn.
18
- # update = update svn builds.
19
- # update:rubygems = update rubygems and nuke install dirs.
20
- #
21
- # specs:
22
- #
23
- # the_usual = alias for latest versions from tar + rubygems
24
- # mri:svn:current = alias for mri:svn:releases and mri:svn:branches.
25
- # mri:svn:releases = alias for supported releases of mri ruby.
26
- # mri:svn:branches = alias for active branches of mri ruby.
27
- # mri:svn:branch:$branch = install a specific $branch of mri from svn.
28
- # mri:svn:tag:$tag = install a specific $tag of mri from svn.
29
- # mri:tar:$version = install a specific $version of mri from tarball.
30
- #
31
- # environment variables:
32
- #
33
- # GEM_URL = url for rubygems tarballs
34
- # MRI_SVN = url for MRI SVN
35
- # RUBY_URL = url for MRI tarballs
36
- # VERSIONS = what versions to install
37
- #
38
- # RUBYOPT is cleared on installs.
39
- #
40
- # NOTES:
41
- #
42
- # * you can add a symlink to your rubinius build into ~/.multiruby/install
43
- # * I need patches/maintainers for other implementations.
44
- #
45
- module Multiruby
46
- def self.env name, fallback; ENV[name] || fallback; end # :nodoc:
47
-
48
- TAGS = %w( 1_8_7 1_9_1 1_9_2)
49
- BRANCHES = %w(1_8 1_8_7 1_9 trunk)
50
-
51
- VERSIONS = env('VERSIONS', TAGS.join(":").gsub(/_/, '.')).split(/:/)
52
- MRI_SVN = env 'MRI_SVN', 'http://svn.ruby-lang.org/repos/ruby'
53
- RUBY_URL = env 'RUBY_URL', 'http://ftp.ruby-lang.org/pub/ruby'
54
- GEM_URL = env 'GEM_URL', 'http://files.rubyforge.vm.bytemark.co.uk/rubygems'
55
-
56
- HELP = []
57
-
58
- File.readlines(__FILE__).each do |line|
59
- next unless line =~ /^#( |$)/
60
- HELP << line.sub(/^# ?/, '')
61
- end
62
-
63
- def self.build_and_install
64
- ENV.delete 'RUBYOPT'
65
-
66
- root_dir = self.root_dir
67
- versions = []
68
-
69
- Dir.chdir root_dir do
70
- self.setup_dirs
71
-
72
- rubygems = Dir["versions/rubygems*.tgz"]
73
- abort "You should delete all but one rubygem tarball" if rubygems.size > 1
74
- rubygem_tarball = File.expand_path rubygems.last rescue nil
75
-
76
- Dir.chdir "build" do
77
- Dir["../versions/*"].sort.each do |tarball|
78
- next if tarball =~ /rubygems/
79
-
80
- build_dir = File.basename tarball, ".tar.gz"
81
- version = build_dir.sub(/^ruby-?/, '')
82
- inst_dir = "#{root_dir}/install/#{version}"
83
-
84
- unless test ?d, inst_dir then
85
- unless test ?d, build_dir then
86
- if test ?d, tarball then
87
- dir = File.basename tarball
88
- FileUtils.ln_sf "../versions/#{dir}", "../build/#{dir}"
89
- else
90
- puts "creating #{inst_dir}"
91
- Dir.mkdir inst_dir
92
- run "tar zxf #{tarball}"
93
- end
94
- end
95
- Dir.chdir build_dir do
96
- puts "building and installing #{version}"
97
- if test ?f, "configure.in" then
98
- gnu_utils_build inst_dir
99
- elsif test ?f, "Rakefile" then
100
- rake_build inst_dir
101
- else
102
- raise "dunno how to build"
103
- end
104
-
105
- if rubygem_tarball and version !~ /1[._-]9|mri_trunk|rubinius/ then
106
- rubygems = File.basename rubygem_tarball, ".tgz"
107
- run "tar zxf #{rubygem_tarball}" unless test ?d, rubygems
108
-
109
- Dir.chdir rubygems do
110
- run "../ruby ./setup.rb --no-rdoc --no-ri", "../log.rubygems"
111
- end
112
- end
113
- end
114
- end
115
- end
116
- end
117
-
118
- versions = Dir["install/*"].map { |path| File.basename path }
119
- end
120
-
121
- versions
122
- end
123
-
124
- def self.clean
125
- self.each_scm_build_dir do |style|
126
- case style
127
- when :svn then
128
- if File.exist? "Rakefile" then
129
- run "rake clean"
130
- elsif File.exist? "Makefile" then
131
- run "make clean"
132
- end
133
- else
134
- FileUtils.rm_rf Dir.pwd
135
- end
136
- end
137
- end
138
-
139
- def self.each_scm_build_dir
140
- Multiruby.in_build_dir do
141
- Dir["*"].each do |dir|
142
- next unless File.directory? dir
143
- Dir.chdir dir do
144
- if File.exist?(".svn") then
145
- yield :svn
146
- else
147
- yield :none
148
- end
149
- end
150
- end
151
- end
152
- end
153
-
154
- def self.matching_versions url, matching=nil
155
- file = URI.parse(url).read
156
-
157
- map = {
158
- "preview" => "beta",
159
- "rc" => "beta2",
160
- "p" => "release",
161
- "tar" => "aargh",
162
- "gz" => "aargh",
163
- }
164
-
165
- versions = file.scan(/href="(ruby.*tar.gz)"/).flatten.sort_by { |s|
166
- s.scan(/\d+|[a-z]+/).map { |a| Integer(a) rescue map[a] || a }
167
- }
168
-
169
- versions = versions.grep(/#{Regexp.escape(matching)}/) if matching
170
-
171
- versions
172
- end
173
-
174
- def self.fetch_tar v
175
- in_versions_dir do
176
- warn " Determining latest version for #{v}"
177
- ver = v[/\d+\.\d+/]
178
- base = matching_versions("#{RUBY_URL}/#{ver}/", v).last
179
- abort "Could not determine release for #{v}" unless base
180
- url = File.join RUBY_URL, ver, base
181
- unless File.file? base then
182
- warn " Fetching #{base} via HTTP... this might take a while."
183
- open(url) do |f|
184
- File.open base, 'w' do |out|
185
- out.write f.read
186
- end
187
- end
188
- end
189
- end
190
- end
191
-
192
- def self.gnu_utils_build inst_dir
193
- run "autoconf" unless test ?f, "configure"
194
- run "./configure --enable-shared --prefix #{inst_dir}", "log.configure" unless
195
- test ?f, "Makefile"
196
- run "(nice make -j4 main; nice make main)", "log.build"
197
- run "make install-nodoc", "log.install"
198
- end
199
-
200
- def self.help
201
- puts HELP.join
202
- end
203
-
204
- def self.in_build_dir
205
- in_root_dir "build" do
206
- yield
207
- end
208
- end
209
-
210
- def self.in_install_dir
211
- in_root_dir "install" do
212
- yield
213
- end
214
- end
215
-
216
- def self.in_root_dir subdir = ""
217
- Dir.chdir File.join(self.root_dir, subdir) do
218
- yield
219
- end
220
- end
221
-
222
- def self.in_tmp_dir
223
- in_root_dir "tmp" do
224
- yield
225
- end
226
- end
227
-
228
- def self.in_versions_dir
229
- in_root_dir "versions" do
230
- yield
231
- end
232
- end
233
-
234
- def self.list
235
- puts "Known versions:"
236
- in_install_dir do
237
- Dir["*"].sort.each do |d|
238
- puts " #{d}"
239
- end
240
- end
241
- end
242
-
243
- def self.merge_rubygems
244
- in_install_dir do
245
- gems = Dir["*/lib/ruby/gems"]
246
-
247
- unless test ?d, "../gems" then
248
- FileUtils.mv gems.first, ".."
249
- end
250
-
251
- gems.each do |d|
252
- FileUtils.rm_rf d
253
- FileUtils.ln_sf "../../../../gems", d
254
- end
255
- end
256
- end
257
-
258
- def self.mri_latest_tag v
259
- Multiruby.tags.grep(/#{v}/).last
260
- end
261
-
262
- def self.rake_build inst_dir
263
- run "rake", "log.build"
264
- FileUtils.ln_sf "../build/#{File.basename Dir.pwd}", inst_dir
265
- end
266
-
267
- def self.rm name
268
- Multiruby.in_root_dir do
269
- FileUtils.rm_rf Dir["*/#{name}"]
270
- f = "versions/ruby-#{name}.tar.gz"
271
- File.unlink f if test ?f, f
272
- end
273
- end
274
-
275
- def self.root_dir
276
- root_dir = File.expand_path(ENV['MULTIRUBY'] ||
277
- File.join(ENV['HOME'], ".multiruby"))
278
-
279
- unless test ?d, root_dir then
280
- puts "creating #{root_dir}"
281
- Dir.mkdir root_dir, 0700
282
- end
283
-
284
- root_dir
285
- end
286
-
287
- def self.run base_cmd, log = nil
288
- cmd = base_cmd
289
- cmd += " > #{log} 2>&1" if log
290
- puts "Running command: #{cmd}"
291
- raise "ERROR: Command failed with exit code #{$?}" unless system cmd
292
- end
293
-
294
- def self.setup_dirs download = true
295
- %w(build install versions tmp).each do |dir|
296
- unless test ?d, dir then
297
- puts "creating #{dir}"
298
- Dir.mkdir dir
299
- if dir == "versions" && download then
300
- warn " Downloading initial ruby tarballs to ~/.multiruby/versions:"
301
- VERSIONS.each do |v|
302
- self.fetch_tar v
303
- end
304
- warn " ...done"
305
- warn " Put other ruby tarballs in ~/.multiruby/versions to use them."
306
- end
307
- end
308
- end
309
- end
310
-
311
- def self.svn_co url, dir
312
- Multiruby.in_versions_dir do
313
- Multiruby.run "svn co #{url} #{dir}" unless File.directory? dir
314
- FileUtils.ln_sf "../versions/#{dir}", "../build/#{dir}"
315
- end
316
- end
317
-
318
- def self.tags
319
- tags = nil
320
- Multiruby.in_tmp_dir do
321
- cache = "svn.tag.cache"
322
- File.unlink cache if Time.now - File.mtime(cache) > 3600 rescue nil
323
-
324
- File.open cache, "w" do |f|
325
- f.write `svn ls #{MRI_SVN}/tags/`
326
- end unless File.exist? cache
327
-
328
- tags = File.read(cache).split(/\n/).grep(/^v/).reject {|s| s =~ /preview/}
329
- end
330
-
331
- tags = tags.sort_by { |t| t.scan(/\d+/).map { |s| s.to_i } }
332
- end
333
-
334
- def self.update
335
- # TODO:
336
- # update will look at the dir name and act accordingly rel_.* will
337
- # figure out latest tag on that name and svn sw to it trunk and
338
- # others will just svn update
339
-
340
- clean = []
341
-
342
- self.each_scm_build_dir do |style|
343
- dir = File.basename(Dir.pwd)
344
- warn dir
345
-
346
- case style
347
- when :svn then
348
- case dir
349
- when /mri_\d/ then
350
- system "svn cleanup" # just in case
351
- svn_up = `svn up`
352
- in_build_dir do
353
- if svn_up =~ /^[ADUCG] / then
354
- clean << dir
355
- else
356
- warn " no update"
357
- end
358
- FileUtils.ln_sf "../build/#{dir}", "../versions/#{dir}"
359
- end
360
- when /mri_rel_(.+)/ then
361
- ver = $1
362
- url = `svn info`[/^URL: (.*)/, 1]
363
- latest = self.mri_latest_tag(ver).chomp('/')
364
- new_url = File.join(File.dirname(url), latest)
365
- if new_url != url then
366
- run "svn sw #{new_url}"
367
- clean << dir
368
- else
369
- warn " no update"
370
- end
371
- else
372
- warn " update in this svn dir not supported yet: #{dir}"
373
- end
374
- else
375
- warn " update in non-svn dir not supported yet: #{dir}"
376
- end
377
- end
378
-
379
- in_install_dir do
380
- clean.each do |dir|
381
- warn "removing install/#{dir}"
382
- FileUtils.rm_rf dir
383
- end
384
- end
385
- end
386
-
387
- def self.update_rubygems
388
- warn " Determining latest version for rubygems"
389
- html = URI.parse(GEM_URL).read
390
-
391
- versions = html.scan(/href="rubygems-update-(\d+(?:\.\d+)+).gem/i).flatten
392
- latest = versions.sort_by { |v| v.scan(/\d+/).map { |s| s.to_i } }.last
393
-
394
- Multiruby.in_versions_dir do
395
- file = "rubygems-#{latest}.tgz"
396
- unless File.file? file then
397
- warn " Fetching rubygems-#{latest}.tgz via HTTP."
398
- File.unlink(*Dir["rubygems*"])
399
- File.open file, 'w' do |f|
400
- f.write URI.parse(GEM_URL+"/"+file).read
401
- end
402
- end
403
- end
404
-
405
- Multiruby.in_build_dir do
406
- FileUtils.rm_rf Dir["rubygems*"]
407
- end
408
-
409
- Multiruby.in_install_dir do
410
- FileUtils.rm_rf Dir["*"]
411
- end
412
- end
413
- end