rvm 0.0.69 → 0.0.70

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/config/db CHANGED
@@ -2,6 +2,7 @@ niceness=0
2
2
  ruby_repo_url=http://svn.ruby-lang.org/repos/ruby
3
3
  rubinius_repo_url=git://github.com/evanphx/rubinius.git
4
4
  shyouhei_repo_url=git://github.com/shyouhei/ruby.git
5
+ macruby_version=nightly
5
6
  macruby_repo_url=git://git.macruby.org/macruby/MacRuby.git
6
7
  macruby_nightly_url=http://macruby.icoretech.org/latest
7
8
  jruby_repo_url=git://kenai.com/jruby~main
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 69
4
+ :patch: 70
@@ -0,0 +1,395 @@
1
+ # vim: ts=2:sw=2:sts=2:et:fdm=marker
2
+ # Author: Ara T. Howard
3
+ # Gem: open4
4
+ require 'fcntl'
5
+ require 'timeout'
6
+ require 'thread'
7
+
8
+ module Open4
9
+ #--{{{
10
+ VERSION = '0.9.6'
11
+ def self.version() VERSION end
12
+
13
+ class Error < ::StandardError; end
14
+
15
+ def popen4(*cmd, &b)
16
+ #--{{{
17
+ pw, pr, pe, ps = IO.pipe, IO.pipe, IO.pipe, IO.pipe
18
+
19
+ verbose = $VERBOSE
20
+ begin
21
+ $VERBOSE = nil
22
+ ps.last.fcntl(Fcntl::F_SETFD, Fcntl::FD_CLOEXEC)
23
+
24
+ cid = fork {
25
+ pw.last.close
26
+ STDIN.reopen pw.first
27
+ pw.first.close
28
+
29
+ pr.first.close
30
+ STDOUT.reopen pr.last
31
+ pr.last.close
32
+
33
+ pe.first.close
34
+ STDERR.reopen pe.last
35
+ pe.last.close
36
+
37
+ STDOUT.sync = STDERR.sync = true
38
+
39
+ begin
40
+ exec(*cmd)
41
+ raise 'forty-two'
42
+ rescue Exception => e
43
+ Marshal.dump(e, ps.last)
44
+ ps.last.flush
45
+ end
46
+ ps.last.close unless (ps.last.closed?)
47
+ exit!
48
+ }
49
+ ensure
50
+ $VERBOSE = verbose
51
+ end
52
+
53
+ [pw.first, pr.last, pe.last, ps.last].each{|fd| fd.close}
54
+
55
+ begin
56
+ e = Marshal.load ps.first
57
+ raise(Exception === e ? e : "unknown failure!")
58
+ rescue EOFError # If we get an EOF error, then the exec was successful
59
+ 42
60
+ ensure
61
+ ps.first.close
62
+ end
63
+
64
+ pw.last.sync = true
65
+
66
+ pi = [pw.last, pr.first, pe.first]
67
+
68
+ if b
69
+ begin
70
+ b[cid, *pi]
71
+ Process.waitpid2(cid).last
72
+ ensure
73
+ pi.each{|fd| fd.close unless fd.closed?}
74
+ end
75
+ else
76
+ [cid, pw.last, pr.first, pe.first]
77
+ end
78
+ #--}}}
79
+ end
80
+ alias open4 popen4
81
+ module_function :popen4
82
+ module_function :open4
83
+
84
+ class SpawnError < Error
85
+ #--{{{
86
+ attr 'cmd'
87
+ attr 'status'
88
+ attr 'signals'
89
+ def exitstatus
90
+ @status.exitstatus
91
+ end
92
+ def initialize cmd, status
93
+ @cmd, @status = cmd, status
94
+ @signals = {}
95
+ if status.signaled?
96
+ @signals['termsig'] = status.termsig
97
+ @signals['stopsig'] = status.stopsig
98
+ end
99
+ sigs = @signals.map{|k,v| "#{ k }:#{ v.inspect }"}.join(' ')
100
+ super "cmd <#{ cmd }> failed with status <#{ exitstatus.inspect }> signals <#{ sigs }>"
101
+ end
102
+ #--}}}
103
+ end
104
+
105
+ class ThreadEnsemble
106
+ #--{{{
107
+ attr 'threads'
108
+
109
+ def initialize cid
110
+ @cid, @threads, @argv, @done, @running = cid, [], [], Queue.new, false
111
+ @killed = false
112
+ end
113
+
114
+ def add_thread *a, &b
115
+ @running ? raise : (@argv << [a, b])
116
+ end
117
+
118
+ #
119
+ # take down process more nicely
120
+ #
121
+ def killall
122
+ c = Thread.critical
123
+ return nil if @killed
124
+ Thread.critical = true
125
+ (@threads - [Thread.current]).each{|t| t.kill rescue nil}
126
+ @killed = true
127
+ ensure
128
+ Thread.critical = c
129
+ end
130
+
131
+ def run
132
+ @running = true
133
+
134
+ begin
135
+ @argv.each do |a, b|
136
+ @threads << Thread.new(*a) do |*a|
137
+ begin
138
+ b[*a]
139
+ ensure
140
+ killall rescue nil if $!
141
+ @done.push Thread.current
142
+ end
143
+ end
144
+ end
145
+ rescue
146
+ killall
147
+ raise
148
+ ensure
149
+ all_done
150
+ end
151
+
152
+ @threads.map{|t| t.value}
153
+ end
154
+
155
+ def all_done
156
+ @threads.size.times{ @done.pop }
157
+ end
158
+ #--}}}
159
+ end
160
+
161
+ def to timeout = nil
162
+ #--{{{
163
+ Timeout.timeout(timeout){ yield }
164
+ #--}}}
165
+ end
166
+ module_function :to
167
+
168
+ def new_thread *a, &b
169
+ #--{{{
170
+ cur = Thread.current
171
+ Thread.new(*a) do |*a|
172
+ begin
173
+ b[*a]
174
+ rescue Exception => e
175
+ cur.raise e
176
+ end
177
+ end
178
+ #--}}}
179
+ end
180
+ module_function :new_thread
181
+
182
+ def getopts opts = {}
183
+ #--{{{
184
+ lambda do |*args|
185
+ keys, default, ignored = args
186
+ catch('opt') do
187
+ [keys].flatten.each do |key|
188
+ [key, key.to_s, key.to_s.intern].each do |key|
189
+ throw 'opt', opts[key] if opts.has_key?(key)
190
+ end
191
+ end
192
+ default
193
+ end
194
+ end
195
+ #--}}}
196
+ end
197
+ module_function :getopts
198
+
199
+ def relay src, dst = nil, t = nil
200
+ #--{{{
201
+ unless src.nil?
202
+ if src.respond_to? :gets
203
+ while buf = to(t){ src.gets }
204
+ dst << buf if dst
205
+ end
206
+
207
+ elsif src.respond_to? :each
208
+ q = Queue.new
209
+ th = nil
210
+
211
+ timer_set = lambda do |t|
212
+ th = new_thread{ to(t){ q.pop } }
213
+ end
214
+
215
+ timer_cancel = lambda do |t|
216
+ th.kill if th rescue nil
217
+ end
218
+
219
+ timer_set[t]
220
+ begin
221
+ src.each do |buf|
222
+ timer_cancel[t]
223
+ dst << buf if dst
224
+ timer_set[t]
225
+ end
226
+ ensure
227
+ timer_cancel[t]
228
+ end
229
+
230
+ elsif src.respond_to? :read
231
+ buf = to(t){ src.read }
232
+ dst << buf if dst
233
+
234
+ else
235
+ buf = to(t){ src.to_s }
236
+ dst << buf if dst
237
+ end
238
+ end
239
+ #--}}}
240
+ end
241
+ module_function :relay
242
+
243
+ def spawn arg, *argv
244
+ #--{{{
245
+ argv.unshift(arg)
246
+ opts = ((argv.size > 1 and Hash === argv.last) ? argv.pop : {})
247
+ argv.flatten!
248
+ cmd = argv.join(' ')
249
+
250
+
251
+ getopt = getopts opts
252
+
253
+ ignore_exit_failure = getopt[ 'ignore_exit_failure', getopt['quiet', false] ]
254
+ ignore_exec_failure = getopt[ 'ignore_exec_failure', !getopt['raise', true] ]
255
+ exitstatus = getopt[ %w( exitstatus exit_status status ) ]
256
+ stdin = getopt[ %w( stdin in i 0 ) << 0 ]
257
+ stdout = getopt[ %w( stdout out o 1 ) << 1 ]
258
+ stderr = getopt[ %w( stderr err e 2 ) << 2 ]
259
+ pid = getopt[ 'pid' ]
260
+ timeout = getopt[ %w( timeout spawn_timeout ) ]
261
+ stdin_timeout = getopt[ %w( stdin_timeout ) ]
262
+ stdout_timeout = getopt[ %w( stdout_timeout io_timeout ) ]
263
+ stderr_timeout = getopt[ %w( stderr_timeout ) ]
264
+ status = getopt[ %w( status ) ]
265
+ cwd = getopt[ %w( cwd dir ) ]
266
+
267
+ exitstatus =
268
+ case exitstatus
269
+ when TrueClass, FalseClass
270
+ ignore_exit_failure = true if exitstatus
271
+ [0]
272
+ else
273
+ [*(exitstatus || 0)].map{|i| Integer i}
274
+ end
275
+
276
+ stdin ||= '' if stdin_timeout
277
+ stdout ||= '' if stdout_timeout
278
+ stderr ||= '' if stderr_timeout
279
+
280
+ started = false
281
+
282
+ status =
283
+ begin
284
+ chdir(cwd) do
285
+ Timeout::timeout(timeout) do
286
+ popen4(*argv) do |c, i, o, e|
287
+ started = true
288
+
289
+ %w( replace pid= << push update ).each do |msg|
290
+ break(pid.send(msg, c)) if pid.respond_to? msg
291
+ end
292
+
293
+ te = ThreadEnsemble.new c
294
+
295
+ te.add_thread(i, stdin) do |i, stdin|
296
+ relay stdin, i, stdin_timeout
297
+ i.close rescue nil
298
+ end
299
+
300
+ te.add_thread(o, stdout) do |o, stdout|
301
+ relay o, stdout, stdout_timeout
302
+ end
303
+
304
+ te.add_thread(e, stderr) do |o, stderr|
305
+ relay e, stderr, stderr_timeout
306
+ end
307
+
308
+ te.run
309
+ end
310
+ end
311
+ end
312
+ rescue
313
+ raise unless(not started and ignore_exec_failure)
314
+ end
315
+
316
+ raise SpawnError.new(cmd, status) unless
317
+ (ignore_exit_failure or (status.nil? and ignore_exec_failure) or exitstatus.include?(status.exitstatus))
318
+
319
+ status
320
+ #--}}}
321
+ end
322
+ module_function :spawn
323
+
324
+ def chdir cwd, &block
325
+ return(block.call Dir.pwd) unless cwd
326
+ Dir.chdir cwd, &block
327
+ end
328
+ module_function :chdir
329
+
330
+ def background arg, *argv
331
+ #--{{{
332
+ require 'thread'
333
+ q = Queue.new
334
+ opts = { 'pid' => q, :pid => q }
335
+ case argv.last
336
+ when Hash
337
+ argv.last.update opts
338
+ else
339
+ argv.push opts
340
+ end
341
+ thread = Thread.new(arg, argv){|arg, argv| spawn arg, *argv}
342
+ sc = class << thread; self; end
343
+ sc.module_eval {
344
+ define_method(:pid){ @pid ||= q.pop }
345
+ define_method(:spawn_status){ @spawn_status ||= value }
346
+ define_method(:exitstatus){ @exitstatus ||= spawn_status.exitstatus }
347
+ }
348
+ thread
349
+ #--}}}
350
+ end
351
+ alias bg background
352
+ module_function :background
353
+ module_function :bg
354
+
355
+ def maim pid, opts = {}
356
+ #--{{{
357
+ getopt = getopts opts
358
+ sigs = getopt[ 'signals', %w(SIGTERM SIGQUIT SIGKILL) ]
359
+ suspend = getopt[ 'suspend', 4 ]
360
+ pid = Integer pid
361
+ existed = false
362
+ sigs.each do |sig|
363
+ begin
364
+ Process.kill sig, pid
365
+ existed = true
366
+ rescue Errno::ESRCH
367
+ return(existed ? nil : true)
368
+ end
369
+ return true unless alive? pid
370
+ sleep suspend
371
+ return true unless alive? pid
372
+ end
373
+ return(not alive?(pid))
374
+ #--}}}
375
+ end
376
+ module_function :maim
377
+
378
+ def alive pid
379
+ #--{{{
380
+ pid = Integer pid
381
+ begin
382
+ Process.kill 0, pid
383
+ true
384
+ rescue Errno::ESRCH
385
+ false
386
+ end
387
+ #--}}}
388
+ end
389
+ alias alive? alive
390
+ module_function :alive
391
+ module_function :'alive?'
392
+ #--}}}
393
+ end
394
+
395
+ def open4(*cmd, &b) cmd.size == 0 ? Open4 : Open4::popen4(*cmd, &b) end
@@ -0,0 +1,14 @@
1
+ module RVM
2
+ module InstanceMethods
3
+ def rvm(command, options = {})
4
+ result = RVM::Shell.new(command)
5
+ [result.output, result.errors]
6
+ end
7
+ end
8
+
9
+ def self.included(receiver)
10
+ receiver.send(:include, InstanceMethods)
11
+ end
12
+ end
13
+
14
+ include RVM
@@ -0,0 +1,14 @@
1
+ module RVM
2
+ class Shell
3
+ attr_reader :errors, :output
4
+
5
+ def initialize(command)
6
+ @command = (command =~ /^rvm /) ? command : "rvm #{command}"
7
+ Open4::popen4("/bin/bash -l -c '#{@command.tr("'","\\'")}'") do |pid, stdin, stdout, stderr|
8
+ stdin.close
9
+ @output = stdout.readlines.join
10
+ @errors = stderr.readlines.join
11
+ end
12
+ end
13
+ end
14
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rvm}
8
- s.version = "0.0.69"
8
+ s.version = "0.0.70"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wayne E. Seguin"]
12
- s.date = %q{2009-10-30}
12
+ s.date = %q{2009-10-31}
13
13
  s.default_executable = %q{rvm-install}
14
14
  s.description = %q{Manages Ruby interpreter installations and switching between them.}
15
15
  s.email = %q{wayneeseguin@gmail.com}
@@ -25,6 +25,9 @@ Gem::Specification.new do |s|
25
25
  "install",
26
26
  "lib/VERSION.yml",
27
27
  "lib/rvm.rb",
28
+ "lib/rvm/open4.rb",
29
+ "lib/rvm/rvm.rb",
30
+ "lib/rvm/shell.rb",
28
31
  "lib/rvm/version.rb",
29
32
  "rvm.gemspec",
30
33
  "scripts/aliases",
@@ -25,7 +25,6 @@ function __rvm_install_source {
25
25
  if [[ $? -gt 0 ]] ; then result=$? ; return $result ; fi
26
26
  else
27
27
  if [[ ! -z "$(echo $rvm_url | awk '/^git/')" ]] ; then
28
-
29
28
  if [[ -d "$rvm_ruby_src_path/.git" ]] ; then
30
29
  cd $rvm_ruby_src_path
31
30
  if [[ -z "$rvm_ruby_revision" ]] ; then
@@ -126,16 +125,63 @@ function __rvm_install_ruby {
126
125
 
127
126
  case "$rvm_ruby_interpreter" in
128
127
  macruby)
129
- if [[ "$(uname)" = "Darwin" ]] ; then
130
- rvm_url="$(__rvm_db "macruby_nightly_url")"
131
- __rvm_log "info" "Retrieving latest macruby" # $rvm_archives_path/macruby_nightly.pkg
132
- __rvm_fetch $rvm_url
133
- mv $rvm_archives_path/latest $rvm_archives_path/macruby_nightly.pkg
134
- __rvm_run "macruby/extract" "xar -x -f $rvm_archives_path/macruby_nightly.pkg -C $rvm_ruby_home" "Extracting macruby nightly package."
128
+ if [[ "Darwin" = "$(uname)" ]] ; then
129
+ if [[ "nightly" = "$rvm_ruby_version" ]] ; then
130
+ macruby_path="/usr/local/bin"
131
+ # TODO: Separated nightly from head.
132
+ rvm_url="$(__rvm_db "macruby_nightly_url")"
133
+ __rvm_log "info" "Retrieving the latest nightly macruby build..."
134
+ __rvm_fetch $rvm_url
135
+ mv "$rvm_archives_path/latest" "$rvm_archives_path/macruby_nightly.pkg"
136
+ __rvm_run "macruby/extract" "sudo installer -pkg '$rvm_path/archives/macruby_nightly.pkg' -target '/'"
137
+ mkdir -p "$rvm_ruby_home/bin"
138
+ elif [[ "head" = "$rvm_ruby_version" ]] ; then
139
+ # TODO: configure & make variables should be set here.
140
+ rvm_url="$(__rvm_db "${rvm_ruby_interpreter}_repo_url")"
141
+ if [[ -z "$rvm_url" ]] ; then
142
+ __rvm_log "fail" "rvm does not know the rvm repo url for 'ree_${rvm_ruby_version}'"
143
+ result=1
144
+ else
145
+ rvm_ruby_repo_url=$rvm_url
146
+ __rvm_install_source $*
147
+ fi
148
+ else
149
+ macruby_path="/usr/local/bin"
150
+ # TODO: Separated nightly from head.
151
+ rvm_url="$(__rvm_db "macruby_nightly_url")"
152
+ __rvm_log "info" "Retrieving latest macruby" # $rvm_archives_path/macruby_nightly.pkg
153
+ __rvm_fetch $rvm_url
154
+ mv $rvm_archives_path/latest $rvm_archives_path/macruby_nightly.pkg
155
+ __rvm_run "macruby/extract" "sudo installer -pkg '$rvm_path/archives/$rvm_ruby_package_file.zip' -target '/'"
156
+ mkdir -p "$rvm_ruby_home/bin"
157
+ fi
158
+
159
+ binaries="erb gem irb rake rdoc ri ruby testrb" # Trick to work in more shells :)
160
+ for binary_name in $(echo $binaries); do
161
+ # if [[ $binary_name != "gem" ]] ; then prefix="-S" ; fi
162
+ ruby_wrapper=$(cat <<RubyWrapper
163
+ #!/bin/bash
164
+
165
+ GEM_HOME="$rvm_ruby_gem_home" ; export GEM_HOME
166
+ GEM_PATH="$rvm_ruby_gem_home" ; export GEM_PATH
167
+ MY_RUBY_HOME="$rvm_ruby_home" ; export MY_RUBY_HOME
168
+ PATH="$rvm_ruby_home/bin:$rvm_ruby_gem_home/bin:\$PATH" ; export PATH
169
+
170
+ exec $macruby_path/mac$binary_name $prefix "\$@"
171
+ RubyWrapper
172
+ )
173
+ files="$rvm_ruby_home/bin/$binary_name $rvm_path/bin/$binary_name-$rvm_ruby_package_name"
174
+ for file_name in $(echo $files) ; do
175
+ rm -f $file_name
176
+ echo "$ruby_wrapper" > $file_name
177
+ if [[ -f $file_name ]] ; then chmod +x $file_name ; fi
178
+ done
179
+ unset file_name ruby_wrapper binary_name files prefix
180
+ done
181
+ __rvm_irbrc
135
182
  else
136
183
  __rvm_log "fail" "MacRuby can only be installed on a Darwin OS."
137
184
  fi
138
- __rvm_irbrc
139
185
  ;;
140
186
 
141
187
  ree)
@@ -15,11 +15,20 @@ function __rvm_select {
15
15
  macruby)
16
16
  if [[ "Darwin" = "$(uname)" ]] ; then
17
17
  rvm_ruby_repo_url="${rvm_ruby_repo_url:-"$(__rvm_db "macruby_repo_url")"}"
18
- rvm_ruby_version="${rvm_ruby_version:-head}"
19
18
  rvm_ruby_package_name=${rvm_ruby_interpreter}-${rvm_ruby_version}
20
- #rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "macruby_version")"}"
21
- #rvm_ruby_package_name=${rvm_ruby_interpreter}_nightly-${rvm_ruby_version}
22
- #rvm_url="http://dl.getdropbox.com/u/163257/$rvm_ruby_package_name.pkg" # 'nightly' builds
19
+ rvm_ruby_string="${rvm_ruby_interpreter}-${rvm_ruby_version}"
20
+ if [[ "nightly" = "$rvm_ruby_version" ]] ; then
21
+ rvm_url="http://macruby.icoretech.org/latest"
22
+ elif [[ "head" = "$rvm_ruby_version" ]] ; then
23
+ rvm_ruby_repo_url=${rvm_ruby_repo_url:-"$(__rvm_db "macruby_repo_url")"}
24
+ rvm_url="$rvm_ruby_repo_url"
25
+ else
26
+ rvm_ruby_version="${rvm_ruby_version:-"$(__rvm_db "macruby_version")"}"
27
+ rvm_ruby_package_name="${rvm_ruby_interpreter}_nightly-${rvm_ruby_version}"
28
+ rvm_ruby_package_file="MacRuby%200.5%20beta%201.zip"
29
+ rvm_url="http://www.macruby.org/files/MacRuby%200.5%20beta%201.zip"
30
+ fi
31
+
23
32
  unset rvm_ruby_patch_level
24
33
  else
25
34
  __rvm_log "fail" "MacRuby can only be installed on a Darwin OS."
@@ -264,6 +273,10 @@ __rvm_ruby_string() {
264
273
  elif [[ "system" = "$string" ]] ; then
265
274
  rvm_ruby_interpreter="system"
266
275
  break
276
+ elif [[ "nightly" = "$string" ]] ; then
277
+ rvm_ruby_version="nightly"
278
+ rvm_nightly_flag=1
279
+ break
267
280
  elif match "$string" "^preview" ; then
268
281
  rvm_ruby_patch_level="$string"
269
282
  elif match "$string" "^[a-z][a-z]" ; then
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rvm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.69
4
+ version: 0.0.70
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wayne E. Seguin
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-30 00:00:00 -04:00
12
+ date: 2009-10-31 00:00:00 -04:00
13
13
  default_executable: rvm-install
14
14
  dependencies: []
15
15
 
@@ -29,6 +29,9 @@ files:
29
29
  - install
30
30
  - lib/VERSION.yml
31
31
  - lib/rvm.rb
32
+ - lib/rvm/open4.rb
33
+ - lib/rvm/rvm.rb
34
+ - lib/rvm/shell.rb
32
35
  - lib/rvm/version.rb
33
36
  - rvm.gemspec
34
37
  - scripts/aliases