debugger-ruby_core_source 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/Rakefile +16 -16
- data/lib/debugger/ruby_core_source.rb +56 -1
- data/lib/debugger/ruby_core_source/version.rb +1 -1
- metadata +2 -7
- data/LICENSE +0 -23
- data/lib/contrib/progressbar.rb +0 -237
- data/lib/contrib/uri_ext.rb +0 -289
- data/lib/ruby_core_source.rb +0 -62
data/CHANGELOG.md
CHANGED
data/Rakefile
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
require 'tempfile'
|
2
1
|
require 'tmpdir'
|
3
|
-
require 'uri'
|
4
|
-
require 'contrib/uri_ext'
|
2
|
+
require 'open-uri'
|
5
3
|
require 'archive/tar/minitar'
|
6
4
|
require 'zlib'
|
7
5
|
require 'fileutils'
|
6
|
+
require 'rubygems/package_task'
|
8
7
|
|
9
8
|
desc 'Add ruby headers under lib for a given VERSION'
|
10
9
|
task :add_source do
|
@@ -13,20 +12,21 @@ task :add_source do
|
|
13
12
|
uri_path = "http://ftp.ruby-lang.org/pub/ruby/1.9/#{ruby_dir}.tar.gz"
|
14
13
|
dest_dir = File.dirname(__FILE__) + "/lib/debugger/ruby_core_source/#{ruby_dir}"
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
puts "Downloading #{uri_path}..."
|
16
|
+
temp = open(uri_path)
|
17
|
+
puts "Unpacking #{uri_path}..."
|
18
|
+
tgz = Zlib::GzipReader.new(File.open(temp, "rb"))
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Archive::Tar::Minitar.unpack(tgz, dir)
|
28
|
-
FileUtils.cp(Dir.glob([ inc_dir, hdr_dir ]), dest_dir)
|
29
|
-
end
|
20
|
+
FileUtils.mkdir_p(dest_dir)
|
21
|
+
Dir.mktmpdir do |dir|
|
22
|
+
inc_dir = dir + "/" + ruby_dir + "/*.inc"
|
23
|
+
hdr_dir = dir + "/" + ruby_dir + "/*.h"
|
24
|
+
Archive::Tar::Minitar.unpack(tgz, dir)
|
25
|
+
FileUtils.cp(Dir.glob([ inc_dir, hdr_dir ]), dest_dir)
|
30
26
|
end
|
27
|
+
end
|
31
28
|
|
29
|
+
base_spec = eval(File.read('debugger-ruby_core_source.gemspec'), binding, 'debugger-ruby_core_source.gemspec')
|
30
|
+
Gem::PackageTask.new(base_spec) do |pkg|
|
31
|
+
pkg.need_tar = true
|
32
32
|
end
|
@@ -1,7 +1,62 @@
|
|
1
|
-
require 'ruby_core_source'
|
2
1
|
require 'debugger/ruby_core_source/version'
|
2
|
+
require 'rbconfig'
|
3
3
|
|
4
4
|
module Debugger
|
5
5
|
module RubyCoreSource
|
6
|
+
REVISION_MAP = {
|
7
|
+
24186 => 'ruby-1.9.2-preview1',
|
8
|
+
27362 => 'ruby-1.9.2-preview3',
|
9
|
+
28524 => 'ruby-1.9.2-rc1',
|
10
|
+
28618 => 'ruby-1.9.2-rc2',
|
11
|
+
32789 => 'ruby-1.9.3-preview1',
|
12
|
+
33323 => 'ruby-1.9.3-rc1'
|
13
|
+
}
|
14
|
+
|
15
|
+
def self.create_makefile_with_core(hdrs, name)
|
16
|
+
# First, see if the gem already has the needed headers
|
17
|
+
if hdrs.call
|
18
|
+
create_makefile(name)
|
19
|
+
return true
|
20
|
+
end
|
21
|
+
|
22
|
+
ruby_dir = if RUBY_PATCHLEVEL < 0
|
23
|
+
REVISION_MAP[RUBY_REVISION] or
|
24
|
+
no_source_abort("ruby-#{RUBY_VERSION} (revision #{RUBY_REVISION})")
|
25
|
+
else
|
26
|
+
"ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
27
|
+
end
|
28
|
+
|
29
|
+
# Check if core headers were already downloaded; if so, use them
|
30
|
+
if RbConfig::CONFIG["rubyhdrdir"]
|
31
|
+
dest_dir = RbConfig::CONFIG["rubyhdrdir"] + "/" + ruby_dir
|
32
|
+
with_cppflags("-I" + dest_dir) {
|
33
|
+
if hdrs.call
|
34
|
+
create_makefile(name)
|
35
|
+
return true
|
36
|
+
end
|
37
|
+
}
|
38
|
+
end
|
39
|
+
|
40
|
+
# Look for sources that ship with gem
|
41
|
+
dest_dir = File.dirname(__FILE__) + "/debugger/ruby_core_source/#{ruby_dir}"
|
42
|
+
no_source_abort(ruby_dir) unless File.directory?(dest_dir)
|
43
|
+
|
44
|
+
with_cppflags("-I" + dest_dir) {
|
45
|
+
if hdrs.call
|
46
|
+
create_makefile(name)
|
47
|
+
return true
|
48
|
+
end
|
49
|
+
}
|
50
|
+
return false
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.no_source_abort(ruby_version)
|
54
|
+
abort <<-STR
|
55
|
+
Makefile creation failed
|
56
|
+
**************************************************************************
|
57
|
+
No source for #{ruby_version} provided with debugger-ruby_core_source gem.
|
58
|
+
**************************************************************************
|
59
|
+
STR
|
60
|
+
end
|
6
61
|
end
|
7
62
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debugger-ruby_core_source
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2012-04-
|
13
|
+
date: 2012-04-06 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: archive-tar-minitar
|
@@ -53,15 +53,12 @@ extra_rdoc_files:
|
|
53
53
|
files:
|
54
54
|
- CHANGELOG.md
|
55
55
|
- LEGAL
|
56
|
-
- LICENSE
|
57
56
|
- LICENSE.txt
|
58
57
|
- OLD_README
|
59
58
|
- README.md
|
60
59
|
- RUBY_LICENSE
|
61
60
|
- Rakefile
|
62
61
|
- debugger-ruby_core_source.gemspec
|
63
|
-
- lib/contrib/progressbar.rb
|
64
|
-
- lib/contrib/uri_ext.rb
|
65
62
|
- lib/debugger/ruby_core_source.rb
|
66
63
|
- lib/debugger/ruby_core_source/ruby-1.9.2-p290/debug.h
|
67
64
|
- lib/debugger/ruby_core_source/ruby-1.9.2-p290/dln.h
|
@@ -204,7 +201,6 @@ files:
|
|
204
201
|
- lib/debugger/ruby_core_source/ruby-1.9.3-p125/vm_opts.h
|
205
202
|
- lib/debugger/ruby_core_source/ruby-1.9.3-p125/vmtc.inc
|
206
203
|
- lib/debugger/ruby_core_source/version.rb
|
207
|
-
- lib/ruby_core_source.rb
|
208
204
|
homepage: http://github.com/cldwalker/debugger-ruby_core_source
|
209
205
|
licenses: []
|
210
206
|
post_install_message:
|
@@ -230,4 +226,3 @@ signing_key:
|
|
230
226
|
specification_version: 3
|
231
227
|
summary: Provide Ruby core source files
|
232
228
|
test_files: []
|
233
|
-
has_rdoc:
|
data/LICENSE
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
Copyright (C) 2011 Mark Moseley <mark@fast-software.com>
|
2
|
-
All rights reserved.
|
3
|
-
*
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
5
|
-
modification, are permitted provided that the following conditions
|
6
|
-
are met:
|
7
|
-
1. Redistributions of source code must retain the above copyright
|
8
|
-
notice, this list of conditions and the following disclaimer.
|
9
|
-
2. Redistributions in binary form must reproduce the above copyright
|
10
|
-
notice, this list of conditions and the following disclaimer in the
|
11
|
-
documentation and/or other materials provided with the distribution.
|
12
|
-
*
|
13
|
-
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
14
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
15
|
-
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
16
|
-
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
17
|
-
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
18
|
-
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
19
|
-
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
20
|
-
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
21
|
-
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
22
|
-
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
23
|
-
SUCH DAMAGE.
|
data/lib/contrib/progressbar.rb
DELETED
@@ -1,237 +0,0 @@
|
|
1
|
-
# = progressbar.rb
|
2
|
-
#
|
3
|
-
# == Copyright (C) 2001 Satoru Takabayashi
|
4
|
-
#
|
5
|
-
# Ruby License
|
6
|
-
#
|
7
|
-
# This module is free software. You may use, modify, and/or redistribute this
|
8
|
-
# software under the same terms as Ruby.
|
9
|
-
#
|
10
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
11
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
12
|
-
# FOR A PARTICULAR PURPOSE.
|
13
|
-
#
|
14
|
-
# == Author(s)
|
15
|
-
#
|
16
|
-
# * Satoru Takabayashi
|
17
|
-
|
18
|
-
# Author:: Satoru Takabayashi
|
19
|
-
# Copyright:: Copyright (c) 2001 Satoru Takabayashi
|
20
|
-
# License:: Ruby License
|
21
|
-
|
22
|
-
# = Console Progress Bar
|
23
|
-
#
|
24
|
-
# Console::ProgressBar is a terminal-based progress bar library.
|
25
|
-
#
|
26
|
-
# == Usage
|
27
|
-
#
|
28
|
-
# pbar = ConsoleProgressBar.new( "Demo", 100 )
|
29
|
-
# 100.times { pbar.inc }
|
30
|
-
# pbar.finish
|
31
|
-
#
|
32
|
-
|
33
|
-
module Console; end
|
34
|
-
|
35
|
-
class Console::ProgressBar
|
36
|
-
|
37
|
-
def initialize(title, total, out = STDERR)
|
38
|
-
@title = title
|
39
|
-
@total = total
|
40
|
-
@out = out
|
41
|
-
@bar_length = 80
|
42
|
-
@bar_mark = "o"
|
43
|
-
@total_overflow = true
|
44
|
-
@current = 0
|
45
|
-
@previous = 0
|
46
|
-
@is_finished = false
|
47
|
-
@start_time = Time.now
|
48
|
-
@format = "%-14s %3d%% %s %s"
|
49
|
-
@format_arguments = [:title, :percentage, :bar, :stat]
|
50
|
-
show_progress
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
def convert_bytes (bytes)
|
55
|
-
if bytes < 1024
|
56
|
-
sprintf("%6dB", bytes)
|
57
|
-
elsif bytes < 1024 * 1000 # 1000kb
|
58
|
-
sprintf("%5.1fKB", bytes.to_f / 1024)
|
59
|
-
elsif bytes < 1024 * 1024 * 1000 # 1000mb
|
60
|
-
sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
|
61
|
-
else
|
62
|
-
sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def transfer_rate
|
67
|
-
bytes_per_second = @current.to_f / (Time.now - @start_time)
|
68
|
-
sprintf("%s/s", convert_bytes(bytes_per_second))
|
69
|
-
end
|
70
|
-
|
71
|
-
def bytes
|
72
|
-
convert_bytes(@current)
|
73
|
-
end
|
74
|
-
|
75
|
-
def format_time (t)
|
76
|
-
t = t.to_i
|
77
|
-
sec = t % 60
|
78
|
-
min = (t / 60) % 60
|
79
|
-
hour = t / 3600
|
80
|
-
sprintf("%02d:%02d:%02d", hour, min, sec);
|
81
|
-
end
|
82
|
-
|
83
|
-
# ETA stands for Estimated Time of Arrival.
|
84
|
-
def eta
|
85
|
-
if @current == 0
|
86
|
-
"ETA: --:--:--"
|
87
|
-
else
|
88
|
-
elapsed = Time.now - @start_time
|
89
|
-
eta = elapsed * @total / @current - elapsed;
|
90
|
-
sprintf("ETA: %s", format_time(eta))
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def elapsed
|
95
|
-
elapsed = Time.now - @start_time
|
96
|
-
sprintf("Time: %s", format_time(elapsed))
|
97
|
-
end
|
98
|
-
|
99
|
-
def stat
|
100
|
-
if @is_finished then elapsed else eta end
|
101
|
-
end
|
102
|
-
|
103
|
-
def stat_for_file_transfer
|
104
|
-
if @is_finished then
|
105
|
-
sprintf("%s %s %s", bytes, transfer_rate, elapsed)
|
106
|
-
else
|
107
|
-
sprintf("%s %s %s", bytes, transfer_rate, eta)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
def eol
|
112
|
-
if @is_finished then "\n" else "\r" end
|
113
|
-
end
|
114
|
-
|
115
|
-
def bar
|
116
|
-
len = percentage * @bar_length / 100
|
117
|
-
sprintf("|%s%s|", @bar_mark * len, " " * (@bar_length - len))
|
118
|
-
end
|
119
|
-
|
120
|
-
def percentage
|
121
|
-
if @total.zero?
|
122
|
-
100
|
123
|
-
else
|
124
|
-
@current * 100 / @total
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def title
|
129
|
-
@title[0,13] + ":"
|
130
|
-
end
|
131
|
-
|
132
|
-
def get_width
|
133
|
-
# FIXME: I don't know how portable it is.
|
134
|
-
default_width = 80
|
135
|
-
begin
|
136
|
-
tiocgwinsz = 0x5413
|
137
|
-
data = [0, 0, 0, 0].pack("SSSS")
|
138
|
-
if @out.ioctl(tiocgwinsz, data) >= 0 then
|
139
|
-
rows, cols, xpixels, ypixels = data.unpack("SSSS")
|
140
|
-
if cols >= 0 then cols else default_width end
|
141
|
-
else
|
142
|
-
default_width
|
143
|
-
end
|
144
|
-
rescue Exception
|
145
|
-
default_width
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
def show
|
150
|
-
arguments = @format_arguments.map {|method| send(method) }
|
151
|
-
line = sprintf(@format, *arguments)
|
152
|
-
|
153
|
-
width = get_width
|
154
|
-
if line.length == width - 1
|
155
|
-
@out.print(line + eol)
|
156
|
-
elsif line.length >= width
|
157
|
-
@bar_length = [@bar_length - (line.length - width + 1), 0].max
|
158
|
-
if @bar_length == 0 then @out.print(line + eol) else show end
|
159
|
-
else #line.length < width - 1
|
160
|
-
@bar_length += width - line.length + 1
|
161
|
-
show
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
def show_progress
|
166
|
-
if @total.zero?
|
167
|
-
cur_percentage = 100
|
168
|
-
prev_percentage = 0
|
169
|
-
else
|
170
|
-
cur_percentage = (@current * 100 / @total).to_i
|
171
|
-
prev_percentage = (@previous * 100 / @total).to_i
|
172
|
-
end
|
173
|
-
|
174
|
-
if cur_percentage > prev_percentage || @is_finished
|
175
|
-
show
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
public
|
180
|
-
def file_transfer_mode
|
181
|
-
@format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
|
182
|
-
end
|
183
|
-
|
184
|
-
def bar_mark= (mark)
|
185
|
-
@bar_mark = String(mark)[0..0]
|
186
|
-
end
|
187
|
-
|
188
|
-
def total_overflow= (boolv)
|
189
|
-
@total_overflow = boolv ? true : false
|
190
|
-
end
|
191
|
-
|
192
|
-
def format= (format)
|
193
|
-
@format = format
|
194
|
-
end
|
195
|
-
|
196
|
-
def format_arguments= (arguments)
|
197
|
-
@format_arguments = arguments
|
198
|
-
end
|
199
|
-
|
200
|
-
def finish
|
201
|
-
@current = @total
|
202
|
-
@is_finished = true
|
203
|
-
show_progress
|
204
|
-
end
|
205
|
-
|
206
|
-
def halt
|
207
|
-
@is_finished = true
|
208
|
-
show_progress
|
209
|
-
end
|
210
|
-
|
211
|
-
def set (count)
|
212
|
-
if count < 0
|
213
|
-
raise "invalid count less than zero: #{count}"
|
214
|
-
elsif count > @total
|
215
|
-
if @total_overflow
|
216
|
-
@total = count + 1
|
217
|
-
else
|
218
|
-
raise "invalid count greater than total: #{count}"
|
219
|
-
end
|
220
|
-
end
|
221
|
-
@current = count
|
222
|
-
show_progress
|
223
|
-
@previous = @current
|
224
|
-
end
|
225
|
-
|
226
|
-
def inc (step = 1)
|
227
|
-
@current += step
|
228
|
-
@current = @total if @current > @total
|
229
|
-
show_progress
|
230
|
-
@previous = @current
|
231
|
-
end
|
232
|
-
|
233
|
-
def inspect
|
234
|
-
"(ProgressBar: #{@current}/#{@total})"
|
235
|
-
end
|
236
|
-
|
237
|
-
end
|
data/lib/contrib/uri_ext.rb
DELETED
@@ -1,289 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# I've striped down dependencies on Net::SSH and Facets to
|
3
|
-
# stay as simple as possible.
|
4
|
-
#
|
5
|
-
# Original code from Assaf Arkin, released under Apache License
|
6
|
-
# (http://buildr.rubyforge.org/license.html)
|
7
|
-
#
|
8
|
-
require 'cgi'
|
9
|
-
require 'uri'
|
10
|
-
require 'net/http'
|
11
|
-
require 'net/https'
|
12
|
-
require 'tempfile'
|
13
|
-
require 'fileutils'
|
14
|
-
|
15
|
-
# show progress of download
|
16
|
-
require File.join(File.dirname(__FILE__), 'progressbar')
|
17
|
-
|
18
|
-
# Not quite open-uri, but similar. Provides read and write methods for the resource represented by the URI.
|
19
|
-
# Currently supports reads for URI::HTTP and writes for URI::SFTP. Also provides convenience methods for
|
20
|
-
# downloads and uploads.
|
21
|
-
module URI
|
22
|
-
# Raised when trying to read/download a resource that doesn't exist.
|
23
|
-
class NotFoundError < RuntimeError; end
|
24
|
-
|
25
|
-
class << self
|
26
|
-
# :call-seq:
|
27
|
-
# read(uri, options?) => content
|
28
|
-
# read(uri, options?) { |chunk| ... }
|
29
|
-
#
|
30
|
-
# Reads from the resource behind this URI. The first form returns the content of the resource,
|
31
|
-
# the second form yields to the block with each chunk of content (usually more than one).
|
32
|
-
#
|
33
|
-
# For example:
|
34
|
-
# File.open "image.jpg", "w" do |file|
|
35
|
-
# URI.read("http://example.com/image.jpg") { |chunk| file.write chunk }
|
36
|
-
# end
|
37
|
-
# Shorter version:
|
38
|
-
# File.open("image.jpg", "w") { |file| file.write URI.read("http://example.com/image.jpg") }
|
39
|
-
#
|
40
|
-
# Supported options:
|
41
|
-
# * :modified -- Only download if file modified since this timestamp. Returns nil if not modified.
|
42
|
-
# * :progress -- Show the progress bar while reading.
|
43
|
-
def read(uri, options = nil, &block)
|
44
|
-
uri = URI.parse(uri.to_s) unless URI === uri
|
45
|
-
uri.read(options, &block)
|
46
|
-
end
|
47
|
-
|
48
|
-
# :call-seq:
|
49
|
-
# download(uri, target, options?)
|
50
|
-
#
|
51
|
-
# Downloads the resource to the target.
|
52
|
-
#
|
53
|
-
# The target may be a file name (string or task), in which case the file is created from the resource.
|
54
|
-
# The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
|
55
|
-
#
|
56
|
-
# Use the progress bar when running in verbose mode.
|
57
|
-
def download(uri, target, options = nil)
|
58
|
-
uri = URI.parse(uri.to_s) unless URI === uri
|
59
|
-
uri.download(target, options)
|
60
|
-
end
|
61
|
-
|
62
|
-
# :call-seq:
|
63
|
-
# write(uri, content, options?)
|
64
|
-
# write(uri, options?) { |bytes| .. }
|
65
|
-
#
|
66
|
-
# Writes to the resource behind the URI. The first form writes the content from a string or an object
|
67
|
-
# that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
|
68
|
-
# block. Each yield should return up to the specified number of bytes, the last yield returns nil.
|
69
|
-
#
|
70
|
-
# For example:
|
71
|
-
# File.open "killer-app.jar", "rb" do |file|
|
72
|
-
# write("sftp://localhost/jars/killer-app.jar") { |chunk| file.read(chunk) }
|
73
|
-
# end
|
74
|
-
# Or:
|
75
|
-
# write "sftp://localhost/jars/killer-app.jar", File.read("killer-app.jar")
|
76
|
-
#
|
77
|
-
# Supported options:
|
78
|
-
# * :progress -- Show the progress bar while reading.
|
79
|
-
def write(uri, *args, &block)
|
80
|
-
uri = URI.parse(uri.to_s) unless URI === uri
|
81
|
-
uri.write(*args, &block)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
class Generic
|
86
|
-
|
87
|
-
# :call-seq:
|
88
|
-
# read(options?) => content
|
89
|
-
# read(options?) { |chunk| ... }
|
90
|
-
#
|
91
|
-
# Reads from the resource behind this URI. The first form returns the content of the resource,
|
92
|
-
# the second form yields to the block with each chunk of content (usually more than one).
|
93
|
-
#
|
94
|
-
# For options, see URI::read.
|
95
|
-
def read(options = nil, &block)
|
96
|
-
fail "This protocol doesn't support reading (yet, how about helping by implementing it?)"
|
97
|
-
end
|
98
|
-
|
99
|
-
# :call-seq:
|
100
|
-
# download(target, options?)
|
101
|
-
#
|
102
|
-
# Downloads the resource to the target.
|
103
|
-
#
|
104
|
-
# The target may be a file name (string or task), in which case the file is created from the resource.
|
105
|
-
# The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
|
106
|
-
#
|
107
|
-
# Use the progress bar when running in verbose mode.
|
108
|
-
def download(target, options = {})
|
109
|
-
case target
|
110
|
-
when String
|
111
|
-
# If download breaks we end up with a partial file which is
|
112
|
-
# worse than not having a file at all, so download to temporary
|
113
|
-
# file and then move over.
|
114
|
-
modified = File.stat(target).mtime if File.exist?(target)
|
115
|
-
temp = nil
|
116
|
-
Tempfile.open(File.basename(target)) do |tf|
|
117
|
-
tf.binmode
|
118
|
-
read(options.merge(:modified => modified)) { |chunk| tf.write chunk }
|
119
|
-
temp = tf
|
120
|
-
end
|
121
|
-
FileUtils.mkpath(File.dirname(target))
|
122
|
-
FileUtils.move(temp.path, target)
|
123
|
-
when File
|
124
|
-
read(options.merge(:modified => target.mtime)) { |chunk| target.write chunk }
|
125
|
-
target.flush
|
126
|
-
else
|
127
|
-
raise ArgumentError, "Expecting a target that is either a file name (string, task) or object that responds to write (file, pipe)." unless target.respond_to?(:write)
|
128
|
-
read(options) { |chunk| target.write chunk }
|
129
|
-
target.flush
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
# :call-seq:
|
134
|
-
# write(content, options?)
|
135
|
-
# write(options?) { |bytes| .. }
|
136
|
-
#
|
137
|
-
# Writes to the resource behind the URI. The first form writes the content from a string or an object
|
138
|
-
# that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
|
139
|
-
# block. Each yield should return up to the specified number of bytes, the last yield returns nil.
|
140
|
-
#
|
141
|
-
# For options, see URI::write.
|
142
|
-
def write(*args, &block)
|
143
|
-
options = args.pop if Hash === args.last
|
144
|
-
options ||= {}
|
145
|
-
if String === args.first
|
146
|
-
ios = StringIO.new(args.first, "r")
|
147
|
-
write(options.merge(:size => args.first.size)) { |bytes| ios.read(bytes) }
|
148
|
-
elsif args.first.respond_to?(:read)
|
149
|
-
size = args.first.size rescue nil
|
150
|
-
write({ :size => size }.merge(options)) { |bytes| args.first.read(bytes) }
|
151
|
-
elsif args.empty? && block
|
152
|
-
write_internal(options, &block)
|
153
|
-
else
|
154
|
-
raise ArgumentError, "Either give me the content, or pass me a block, otherwise what would I upload?"
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
protected
|
159
|
-
|
160
|
-
# :call-seq:
|
161
|
-
# with_progress_bar(enable, file_name, size) { |progress| ... }
|
162
|
-
#
|
163
|
-
# Displays a progress bar while executing the block. The first argument must be true for the
|
164
|
-
# progress bar to show (TTY output also required), as a convenient for selectively using the
|
165
|
-
# progress bar from a single block.
|
166
|
-
#
|
167
|
-
# The second argument provides a filename to display, the third its size in bytes.
|
168
|
-
#
|
169
|
-
# The block is yielded with a progress object that implements a single method.
|
170
|
-
# Call << for each block of bytes down/uploaded.
|
171
|
-
def with_progress_bar(enable, file_name, size) #:nodoc:
|
172
|
-
if enable && $stdout.isatty
|
173
|
-
progress_bar = Console::ProgressBar.new(file_name, size)
|
174
|
-
# Extend the progress bar so we can display count/total.
|
175
|
-
class << progress_bar
|
176
|
-
def total()
|
177
|
-
convert_bytes(@total)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
# Squeeze the filename into 30 characters.
|
181
|
-
if file_name.size > 30
|
182
|
-
base, ext = File.basename(file_name), File.extname(file_name)
|
183
|
-
truncated = "#{base[0..26-ext.to_s.size]}..#{ext}"
|
184
|
-
else
|
185
|
-
truncated = file_name
|
186
|
-
end
|
187
|
-
progress_bar.format = "#{CGI.unescape(truncated)}: %3d%% %s %s/%s %s"
|
188
|
-
progress_bar.format_arguments = [:percentage, :bar, :bytes, :total, :stat]
|
189
|
-
progress_bar.bar_mark = "o"
|
190
|
-
|
191
|
-
begin
|
192
|
-
class << progress_bar
|
193
|
-
def <<(bytes)
|
194
|
-
inc bytes.respond_to?(:size) ? bytes.size : bytes
|
195
|
-
end
|
196
|
-
end
|
197
|
-
yield progress_bar
|
198
|
-
ensure
|
199
|
-
progress_bar.finish
|
200
|
-
end
|
201
|
-
else
|
202
|
-
progress_bar = Object.new
|
203
|
-
class << progress_bar
|
204
|
-
def <<(bytes)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
yield progress_bar
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
# :call-seq:
|
212
|
-
# proxy_uri() => URI?
|
213
|
-
#
|
214
|
-
# Returns the proxy server to use. Obtains the proxy from the relevant environment variable (e.g. HTTP_PROXY).
|
215
|
-
# Supports exclusions based on host name and port number from environment variable NO_PROXY.
|
216
|
-
def proxy_uri()
|
217
|
-
proxy = ENV["#{scheme.upcase}_PROXY"]
|
218
|
-
proxy = URI.parse(proxy) if String === proxy
|
219
|
-
excludes = (ENV["NO_PROXY"] || "").split(/\s*,\s*/).compact
|
220
|
-
excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" }
|
221
|
-
return proxy unless excludes.any? { |exclude| File.fnmatch(exclude, "#{host}:#{port}") }
|
222
|
-
end
|
223
|
-
|
224
|
-
def write_internal(options, &block) #:nodoc:
|
225
|
-
fail "This protocol doesn't support writing (yet, how about helping by implementing it?)"
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
class HTTP #:nodoc:
|
230
|
-
|
231
|
-
# See URI::Generic#read
|
232
|
-
def read(options = nil, &block)
|
233
|
-
options ||= {}
|
234
|
-
connect do |http|
|
235
|
-
puts "Requesting #{self}" #if verbose
|
236
|
-
headers = { 'If-Modified-Since' => CGI.rfc1123_date(options[:modified].utc) } if options[:modified]
|
237
|
-
request = Net::HTTP::Get.new(request_uri.empty? ? '/' : request_uri, headers)
|
238
|
-
request.basic_auth self.user, self.password if self.user
|
239
|
-
http.request request do |response|
|
240
|
-
case response
|
241
|
-
when Net::HTTPNotModified
|
242
|
-
# No modification, nothing to do.
|
243
|
-
puts 'Not modified since last download' #if verbose
|
244
|
-
return nil
|
245
|
-
when Net::HTTPRedirection
|
246
|
-
# Try to download from the new URI, handle relative redirects.
|
247
|
-
puts "Redirected to #{response['Location']}" #if verbose
|
248
|
-
return (self + URI.parse(response['location'])).read(options, &block)
|
249
|
-
when Net::HTTPOK
|
250
|
-
puts "Downloading #{self}" #if verbose
|
251
|
-
result = nil
|
252
|
-
with_progress_bar options[:progress], path.split('/').last, response.content_length do |progress|
|
253
|
-
if block
|
254
|
-
response.read_body do |chunk|
|
255
|
-
block.call chunk
|
256
|
-
progress << chunk
|
257
|
-
end
|
258
|
-
else
|
259
|
-
result = ''
|
260
|
-
response.read_body do |chunk|
|
261
|
-
result << chunk
|
262
|
-
progress << chunk
|
263
|
-
end
|
264
|
-
end
|
265
|
-
end
|
266
|
-
return result
|
267
|
-
when Net::HTTPNotFound
|
268
|
-
raise NotFoundError, "Looking for #{self} and all I got was a 404!"
|
269
|
-
else
|
270
|
-
raise RuntimeError, "Failed to download #{self}: #{response.message}"
|
271
|
-
end
|
272
|
-
end
|
273
|
-
end
|
274
|
-
end
|
275
|
-
|
276
|
-
private
|
277
|
-
|
278
|
-
def connect
|
279
|
-
if proxy = proxy_uri
|
280
|
-
proxy = URI.parse(proxy) if String === proxy
|
281
|
-
http = Net::HTTP.new(host, port, proxy.host, proxy.port, proxy.user, proxy.password)
|
282
|
-
else
|
283
|
-
http = Net::HTTP.new(host, port)
|
284
|
-
end
|
285
|
-
http.use_ssl = true if self.instance_of? URI::HTTPS
|
286
|
-
yield http
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
data/lib/ruby_core_source.rb
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'rbconfig'
|
2
|
-
|
3
|
-
module Ruby_core_source
|
4
|
-
REVISION_MAP = {
|
5
|
-
24186 => 'ruby-1.9.2-preview1',
|
6
|
-
27362 => 'ruby-1.9.2-preview3',
|
7
|
-
28524 => 'ruby-1.9.2-rc1',
|
8
|
-
28618 => 'ruby-1.9.2-rc2',
|
9
|
-
32789 => 'ruby-1.9.3-preview1',
|
10
|
-
33323 => 'ruby-1.9.3-rc1'
|
11
|
-
}
|
12
|
-
|
13
|
-
def self.create_makefile_with_core(hdrs, name)
|
14
|
-
|
15
|
-
#
|
16
|
-
# First, see if the gem already has the needed headers
|
17
|
-
#
|
18
|
-
if hdrs.call
|
19
|
-
create_makefile(name)
|
20
|
-
return true
|
21
|
-
end
|
22
|
-
|
23
|
-
ruby_dir = if RUBY_PATCHLEVEL < 0
|
24
|
-
REVISION_MAP[RUBY_REVISION] or
|
25
|
-
no_source_abort("ruby-#{RUBY_VERSION} (revision #{RUBY_REVISION})")
|
26
|
-
else
|
27
|
-
"ruby-#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}"
|
28
|
-
end
|
29
|
-
|
30
|
-
#
|
31
|
-
# Check if core headers were already downloaded; if so, use them
|
32
|
-
#
|
33
|
-
dest_dir = RbConfig::CONFIG["rubyhdrdir"] + "/" + ruby_dir
|
34
|
-
with_cppflags("-I" + dest_dir) {
|
35
|
-
if hdrs.call
|
36
|
-
create_makefile(name)
|
37
|
-
return true
|
38
|
-
end
|
39
|
-
}
|
40
|
-
|
41
|
-
# Look for sources that ship with gem
|
42
|
-
dest_dir = File.dirname(__FILE__) + "/debugger/ruby_core_source/#{ruby_dir}"
|
43
|
-
no_source_abort(ruby_dir) unless File.directory?(dest_dir)
|
44
|
-
|
45
|
-
with_cppflags("-I" + dest_dir) {
|
46
|
-
if hdrs.call
|
47
|
-
create_makefile(name)
|
48
|
-
return true
|
49
|
-
end
|
50
|
-
}
|
51
|
-
return false
|
52
|
-
end
|
53
|
-
|
54
|
-
def self.no_source_abort(ruby_version)
|
55
|
-
abort <<-STR
|
56
|
-
Makefile creation failed
|
57
|
-
**************************************************************************
|
58
|
-
No source for #{ruby_version} provided with debugger-ruby_core_source gem.
|
59
|
-
**************************************************************************
|
60
|
-
STR
|
61
|
-
end
|
62
|
-
end
|