core-source 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ === 0.1.0 2010-09-22
2
+
3
+ Initial fork
4
+
@@ -0,0 +1,157 @@
1
+
2
+ SHELL = /bin/sh
3
+
4
+ #### Start of system configuration section. ####
5
+
6
+ srcdir = "/Users/ahaig/.rvm/gems/ruby-1.9.2-p0/bin"
7
+ topdir = /Users/ahaig/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1
8
+ hdrdir = /Users/ahaig/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1
9
+ arch_hdrdir = /Users/ahaig/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/$(arch)
10
+ VPATH = $(srcdir):$(arch_hdrdir)/ruby:$(hdrdir)/ruby
11
+ prefix = $(DESTDIR)/Users/ahaig/.rvm/rubies/ruby-1.9.2-p0
12
+ rubylibprefix = $(libdir)/$(RUBY_BASE_NAME)
13
+ exec_prefix = $(prefix)
14
+ vendorhdrdir = $(rubyhdrdir)/vendor_ruby
15
+ sitehdrdir = $(rubyhdrdir)/site_ruby
16
+ rubyhdrdir = $(includedir)/$(RUBY_BASE_NAME)-$(ruby_version)
17
+ vendordir = $(rubylibprefix)/vendor_ruby
18
+ sitedir = $(rubylibprefix)/site_ruby
19
+ ridir = $(datarootdir)/$(RI_BASE_NAME)
20
+ mandir = $(datarootdir)/man
21
+ localedir = $(datarootdir)/locale
22
+ libdir = $(exec_prefix)/lib
23
+ psdir = $(docdir)
24
+ pdfdir = $(docdir)
25
+ dvidir = $(docdir)
26
+ htmldir = $(docdir)
27
+ infodir = $(datarootdir)/info
28
+ docdir = $(datarootdir)/doc/$(PACKAGE)
29
+ oldincludedir = $(DESTDIR)/usr/include
30
+ includedir = $(prefix)/include
31
+ localstatedir = $(prefix)/var
32
+ sharedstatedir = $(prefix)/com
33
+ sysconfdir = $(prefix)/etc
34
+ datadir = $(datarootdir)
35
+ datarootdir = $(prefix)/share
36
+ libexecdir = $(exec_prefix)/libexec
37
+ sbindir = $(exec_prefix)/sbin
38
+ bindir = $(exec_prefix)/bin
39
+ rubylibdir = $(rubylibprefix)/$(ruby_version)
40
+ archdir = $(rubylibdir)/$(arch)
41
+ sitelibdir = $(sitedir)/$(ruby_version)
42
+ sitearchdir = $(sitelibdir)/$(sitearch)
43
+ vendorlibdir = $(vendordir)/$(ruby_version)
44
+ vendorarchdir = $(vendorlibdir)/$(sitearch)
45
+
46
+ CC = /usr/bin/clang
47
+ CXX = g++
48
+ LIBRUBY = $(LIBRUBY_SO)
49
+ LIBRUBY_A = lib$(RUBY_SO_NAME)-static.a
50
+ LIBRUBYARG_SHARED = -l$(RUBY_SO_NAME)
51
+ LIBRUBYARG_STATIC = -l$(RUBY_SO_NAME)-static
52
+ OUTFLAG = -o
53
+ COUTFLAG = -o
54
+
55
+ RUBY_EXTCONF_H =
56
+ cflags = $(optflags) $(debugflags) $(warnflags)
57
+ optflags = -O0
58
+ debugflags = -ggdb
59
+ warnflags = -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-missing-field-initializers -Wshorten-64-to-32 -Wno-long-long
60
+ CFLAGS = -fno-common -march=x86-64 -ggdb3 -fno-eliminate-unused-debug-symbols -fno-common -fsigned-char -pipe -fno-common
61
+ INCFLAGS = -I. -I$(arch_hdrdir) -I$(hdrdir)/ruby/backward -I$(hdrdir) -I$(srcdir)
62
+ DEFS =
63
+ CPPFLAGS = -DHAVE_VM_CORE_H -DHAVE_ISEQ_H -DHAVE_EVAL_INTERN_H -DHAVE_VERSION_H -I/Users/ahaig/.rvm/rubies/ruby-1.9.2-p0/include/ruby-1.9.1/ruby-1.9.2-p0
64
+ CXXFLAGS = $(CFLAGS) -march=x86-64 -ggdb3 -fno-eliminate-unused-debug-symbols -fno-common -fsigned-char -pipe
65
+ ldflags = -L. -L/usr/local/lib
66
+ dldflags = -Wl,-undefined,dynamic_lookup -Wl,-multiply_defined,suppress -Wl,-flat_namespace
67
+ ARCH_FLAG =
68
+ DLDFLAGS = $(ldflags) $(dldflags)
69
+ LDSHARED = $(CC) -dynamic -bundle
70
+ LDSHAREDXX = $(CXX) -dynamic -bundle
71
+ AR = ar
72
+ EXEEXT =
73
+
74
+ RUBY_BASE_NAME = ruby
75
+ RUBY_INSTALL_NAME = ruby
76
+ RUBY_SO_NAME = ruby.1.9.1
77
+ arch = x86_64-darwin10.4.0
78
+ sitearch = $(arch)
79
+ ruby_version = 1.9.1
80
+ ruby = /Users/ahaig/.rvm/rubies/ruby-1.9.2-p0/bin/ruby
81
+ RUBY = $(ruby)
82
+ RM = rm -f
83
+ RM_RF = $(RUBY) -run -e rm -- -rf
84
+ RMDIRS = $(RUBY) -run -e rmdir -- -p
85
+ MAKEDIRS = mkdir -p
86
+ INSTALL = /usr/bin/install -c
87
+ INSTALL_PROG = $(INSTALL) -m 0755
88
+ INSTALL_DATA = $(INSTALL) -m 644
89
+ COPY = cp
90
+
91
+ #### End of system configuration section. ####
92
+
93
+ preload =
94
+
95
+ libpath = . $(libdir)
96
+ LIBPATH = -L. -L$(libdir)
97
+ DEFFILE =
98
+
99
+ CLEANFILES = mkmf.log
100
+ DISTCLEANFILES =
101
+ DISTCLEANDIRS =
102
+
103
+ extout =
104
+ extout_prefix =
105
+ target_prefix =
106
+ LOCAL_LIBS =
107
+ LIBS = $(LIBRUBYARG_SHARED) -lpthread -ldl -lobjc
108
+ SRCS =
109
+ OBJS =
110
+ TARGET =
111
+ DLLIB =
112
+ EXTSTATIC =
113
+ STATIC_LIB =
114
+
115
+ BINDIR = $(bindir)
116
+ RUBYCOMMONDIR = $(sitedir)$(target_prefix)
117
+ RUBYLIBDIR = $(sitelibdir)$(target_prefix)
118
+ RUBYARCHDIR = $(sitearchdir)$(target_prefix)
119
+ HDRDIR = $(rubyhdrdir)/ruby$(target_prefix)
120
+ ARCHHDRDIR = $(rubyhdrdir)/$(arch)/ruby$(target_prefix)
121
+
122
+ TARGET_SO = $(DLLIB)
123
+ CLEANLIBS = $(TARGET).bundle
124
+ CLEANOBJS = *.o *.bak
125
+
126
+ all: Makefile
127
+ static: $(STATIC_LIB)
128
+ .PHONY: all install static install-so install-rb
129
+ .PHONY: clean clean-so clean-rb
130
+
131
+ clean-rb-default::
132
+ clean-rb::
133
+ clean-so::
134
+ clean: clean-so clean-rb-default clean-rb
135
+ @-$(RM) $(CLEANLIBS) $(CLEANOBJS) $(CLEANFILES)
136
+
137
+ distclean-rb-default::
138
+ distclean-rb::
139
+ distclean-so::
140
+ distclean: clean distclean-so distclean-rb-default distclean-rb
141
+ @-$(RM) Makefile $(RUBY_EXTCONF_H) conftest.* mkmf.log
142
+ @-$(RM) core ruby$(EXEEXT) *~ $(DISTCLEANFILES)
143
+ @-$(RMDIRS) $(DISTCLEANDIRS)
144
+
145
+ realclean: distclean
146
+ install: install-so install-rb
147
+
148
+ install-so: Makefile
149
+ install-rb: pre-install-rb install-rb-default
150
+ install-rb-default: pre-install-rb-default
151
+ pre-install-rb: Makefile
152
+ pre-install-rb-default: Makefile
153
+
154
+ site-install: site-install-so site-install-rb
155
+ site-install-so: install-so
156
+ site-install-rb: install-rb
157
+
@@ -0,0 +1,11 @@
1
+ CHANGELOG.rdoc
2
+ Makefile
3
+ Manifest.txt
4
+ README.rdoc
5
+ Rakefile
6
+ VERSION.rdoc
7
+ core-source.gemspec
8
+ lib/VERSION.rdoc
9
+ lib/contrib/progressbar.rb
10
+ lib/contrib/uri_ext.rb
11
+ lib/core-source.rb
@@ -0,0 +1,64 @@
1
+ == Sender
2
+
3
+ http://rubygems.org/gems/weakhash
4
+
5
+ == DESCRIPTION:
6
+
7
+ Fork of ruby_core_source modified to support CFLAGS and permit use of
8
+ whichever build system (mkmf, rpmkmf, or other modules) while utilizing
9
+ core source.
10
+
11
+ This fork was created because the existing ruby_core_source takes over
12
+ the build definition, preventing definition of CFLAGS and other settings
13
+ that mkmf requires be defined by an enclosing block.
14
+
15
+ == INSTALL:
16
+
17
+ * sudo gem install rp_ruby_core_source
18
+
19
+ == EXAMPLE:
20
+
21
+ require 'mkmfmf' # mkmfmf is a drop-in replacement for mkmf; see http://rubygems.org/gems/mkmfmf
22
+ require 'core-source'
23
+
24
+ target = "gdb_helper"
25
+
26
+ required_core_headers = [ "vm_core.h",
27
+ "iseq.h",
28
+ "eval_intern.h",
29
+ "version.h",
30
+ "node.h" ]
31
+
32
+ default_cflags = "-march=x86-64 -gfull -fcatch-undefined-behavior -fno-common -fsigned-char -pipe"
33
+
34
+ # Create our makefile from sources
35
+ if ensure_core_headers( required_core_headers )
36
+ with_cflags( default_cflags ) do
37
+ create_makefile( target )
38
+ end
39
+ end
40
+
41
+ == LICENSE:
42
+
43
+ (The MIT License)
44
+
45
+ Copyright (c) 2010 Asher
46
+
47
+ Permission is hereby granted, free of charge, to any person obtaining
48
+ a copy of this software and associated documentation files (the
49
+ 'Software'), to deal in the Software without restriction, including
50
+ without limitation the rights to use, copy, modify, merge, publish,
51
+ distribute, sublicense, and/or sell copies of the Software, and to
52
+ permit persons to whom the Software is furnished to do so, subject to
53
+ the following conditions:
54
+
55
+ The above copyright notice and this permission notice shall be
56
+ included in all copies or substantial portions of the Software.
57
+
58
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
59
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
60
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
61
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
62
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
63
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
64
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,64 @@
1
+ ###############################################################################
2
+ # #
3
+ # Gem Specification #
4
+ # #
5
+ ###############################################################################
6
+
7
+ gem_name = 'core-source'
8
+ has_c_source = false
9
+
10
+ developer_name = 'Asher'
11
+ email = 'asher@ridiculouspower.com'
12
+ rubyforge_name = 'asher'
13
+
14
+ $VERBOSE = false
15
+
16
+ ################################################################################
17
+
18
+ require 'hoe'
19
+ require 'rake/extensiontask'
20
+
21
+ require 'pp'
22
+
23
+ Hoe.spec gem_name do
24
+ developer( developer_name, email )
25
+ self.rubyforge_name = rubyforge_name
26
+ self.version = File.open( 'VERSION.rdoc' ).readline
27
+ self.readme_file = 'README.rdoc'
28
+ self.history_file = 'CHANGELOG.rdoc'
29
+ self.extra_rdoc_files = FileList['*.rdoc']
30
+ if has_c_source
31
+ self.spec_extras = { :extensions => 'ext/' + gem_name + '/extconf.rb' }
32
+ self.extra_dev_deps << ['rake-compiler', '>= 0']
33
+ end
34
+ Rake::ExtensionTask.new( gem_name, spec ) do |ext|
35
+ ext.lib_dir = File.join( 'lib', gem_name )
36
+ end
37
+ end
38
+
39
+ if has_c_source
40
+ # clear default task and set default to :compile
41
+ Rake::Task[ :default ].clear
42
+ task :default => :compile
43
+ end
44
+
45
+ task :make do
46
+ Rake::Task[:compile].invoke
47
+ end
48
+
49
+ task :cultivate do
50
+ system "touch Manifest.txt; rake check_manifest | grep -v \"(in \" | patch"
51
+ system "rake debug_gem | grep -v \"(in \" > " + gem_name + ".gemspec"
52
+ end
53
+
54
+ # allow spec task to be turned off from command line
55
+ if has_c_source and
56
+ not ( ENV[ "no_spec" ] or
57
+ ENV[ "no_spec" ] == "true" or
58
+ ENV[ "no_spec" ] == "yes" or
59
+ ENV[ "no_spec" ] == "on" or
60
+ ENV[ "spec" ] == "false" or
61
+ ENV[ "spec" ] == "no" or
62
+ ENV[ "spec" ] == "off" )
63
+ Rake::Task[ :spec ].prerequisites << :compile
64
+ end
@@ -0,0 +1 @@
1
+ 0.1
@@ -0,0 +1,42 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{core-source}
5
+ s.version = "0.1"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Asher"]
9
+ s.date = %q{2010-08-24}
10
+ s.description = %q{Fork of ruby_core_source modified to support CFLAGS and permit use of
11
+ whichever build system (mkmf, rpmkmf, or other modules) while utilizing
12
+ core source.
13
+
14
+ This fork was created because the existing ruby_core_source takes over
15
+ the build definition, preventing definition of CFLAGS and other settings
16
+ that mkmf requires be defined by an enclosing block.}
17
+ s.email = ["asher@ridiculouspower.com"]
18
+ s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "README.rdoc", "VERSION.rdoc"]
19
+ s.files = ["CHANGELOG.rdoc", "Makefile", "Manifest.txt", "README.rdoc", "Rakefile", "VERSION.rdoc", "core-source.gemspec", "lib/VERSION.rdoc", "lib/contrib/progressbar.rb", "lib/contrib/uri_ext.rb", "lib/core-source.rb"]
20
+ s.homepage = %q{http://rubygems.org/gems/weakhash}
21
+ s.rdoc_options = ["--main", "README.rdoc"]
22
+ s.require_paths = ["lib"]
23
+ s.rubyforge_project = %q{asher}
24
+ s.rubygems_version = %q{1.3.7}
25
+ s.summary = %q{Fork of ruby_core_source modified to support CFLAGS and permit use of whichever build system (mkmf, rpmkmf, or other modules) while utilizing core source}
26
+
27
+ if s.respond_to? :specification_version then
28
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
29
+ s.specification_version = 3
30
+
31
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
32
+ s.add_development_dependency(%q<rubyforge>, [">= 2.0.4"])
33
+ s.add_development_dependency(%q<hoe>, [">= 2.6.1"])
34
+ else
35
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
36
+ s.add_dependency(%q<hoe>, [">= 2.6.1"])
37
+ end
38
+ else
39
+ s.add_dependency(%q<rubyforge>, [">= 2.0.4"])
40
+ s.add_dependency(%q<hoe>, [">= 2.6.1"])
41
+ end
42
+ end
@@ -0,0 +1 @@
1
+ 0.1
@@ -0,0 +1,239 @@
1
+ # Contrib code taken from ruby_core_source
2
+
3
+ # = progressbar.rb
4
+ #
5
+ # == Copyright (C) 2001 Satoru Takabayashi
6
+ #
7
+ # Ruby License
8
+ #
9
+ # This module is free software. You may use, modify, and/or redistribute this
10
+ # software under the same terms as Ruby.
11
+ #
12
+ # This program is distributed in the hope that it will be useful, but WITHOUT
13
+ # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
+ # FOR A PARTICULAR PURPOSE.
15
+ #
16
+ # == Author(s)
17
+ #
18
+ # * Satoru Takabayashi
19
+
20
+ # Author:: Satoru Takabayashi
21
+ # Copyright:: Copyright (c) 2001 Satoru Takabayashi
22
+ # License:: Ruby License
23
+
24
+ # = Console Progress Bar
25
+ #
26
+ # Console::ProgressBar is a terminal-based progress bar library.
27
+ #
28
+ # == Usage
29
+ #
30
+ # pbar = ConsoleProgressBar.new( "Demo", 100 )
31
+ # 100.times { pbar.inc }
32
+ # pbar.finish
33
+ #
34
+
35
+ module Console; end
36
+
37
+ class Console::ProgressBar
38
+
39
+ def initialize(title, total, out = STDERR)
40
+ @title = title
41
+ @total = total
42
+ @out = out
43
+ @bar_length = 80
44
+ @bar_mark = "o"
45
+ @total_overflow = true
46
+ @current = 0
47
+ @previous = 0
48
+ @is_finished = false
49
+ @start_time = Time.now
50
+ @format = "%-14s %3d%% %s %s"
51
+ @format_arguments = [:title, :percentage, :bar, :stat]
52
+ show_progress
53
+ end
54
+
55
+ private
56
+ def convert_bytes (bytes)
57
+ if bytes < 1024
58
+ sprintf("%6dB", bytes)
59
+ elsif bytes < 1024 * 1000 # 1000kb
60
+ sprintf("%5.1fKB", bytes.to_f / 1024)
61
+ elsif bytes < 1024 * 1024 * 1000 # 1000mb
62
+ sprintf("%5.1fMB", bytes.to_f / 1024 / 1024)
63
+ else
64
+ sprintf("%5.1fGB", bytes.to_f / 1024 / 1024 / 1024)
65
+ end
66
+ end
67
+
68
+ def transfer_rate
69
+ bytes_per_second = @current.to_f / (Time.now - @start_time)
70
+ sprintf("%s/s", convert_bytes(bytes_per_second))
71
+ end
72
+
73
+ def bytes
74
+ convert_bytes(@current)
75
+ end
76
+
77
+ def format_time (t)
78
+ t = t.to_i
79
+ sec = t % 60
80
+ min = (t / 60) % 60
81
+ hour = t / 3600
82
+ sprintf("%02d:%02d:%02d", hour, min, sec);
83
+ end
84
+
85
+ # ETA stands for Estimated Time of Arrival.
86
+ def eta
87
+ if @current == 0
88
+ "ETA: --:--:--"
89
+ else
90
+ elapsed = Time.now - @start_time
91
+ eta = elapsed * @total / @current - elapsed;
92
+ sprintf("ETA: %s", format_time(eta))
93
+ end
94
+ end
95
+
96
+ def elapsed
97
+ elapsed = Time.now - @start_time
98
+ sprintf("Time: %s", format_time(elapsed))
99
+ end
100
+
101
+ def stat
102
+ if @is_finished then elapsed else eta end
103
+ end
104
+
105
+ def stat_for_file_transfer
106
+ if @is_finished then
107
+ sprintf("%s %s %s", bytes, transfer_rate, elapsed)
108
+ else
109
+ sprintf("%s %s %s", bytes, transfer_rate, eta)
110
+ end
111
+ end
112
+
113
+ def eol
114
+ if @is_finished then "\n" else "\r" end
115
+ end
116
+
117
+ def bar
118
+ len = percentage * @bar_length / 100
119
+ sprintf("|%s%s|", @bar_mark * len, " " * (@bar_length - len))
120
+ end
121
+
122
+ def percentage
123
+ if @total.zero?
124
+ 100
125
+ else
126
+ @current * 100 / @total
127
+ end
128
+ end
129
+
130
+ def title
131
+ @title[0,13] + ":"
132
+ end
133
+
134
+ def get_width
135
+ # FIXME: I don't know how portable it is.
136
+ default_width = 80
137
+ begin
138
+ tiocgwinsz = 0x5413
139
+ data = [0, 0, 0, 0].pack("SSSS")
140
+ if @out.ioctl(tiocgwinsz, data) >= 0 then
141
+ rows, cols, xpixels, ypixels = data.unpack("SSSS")
142
+ if cols >= 0 then cols else default_width end
143
+ else
144
+ default_width
145
+ end
146
+ rescue Exception
147
+ default_width
148
+ end
149
+ end
150
+
151
+ def show
152
+ arguments = @format_arguments.map {|method| send(method) }
153
+ line = sprintf(@format, *arguments)
154
+
155
+ width = get_width
156
+ if line.length == width - 1
157
+ @out.print(line + eol)
158
+ elsif line.length >= width
159
+ @bar_length = [@bar_length - (line.length - width + 1), 0].max
160
+ if @bar_length == 0 then @out.print(line + eol) else show end
161
+ else #line.length < width - 1
162
+ @bar_length += width - line.length + 1
163
+ show
164
+ end
165
+ end
166
+
167
+ def show_progress
168
+ if @total.zero?
169
+ cur_percentage = 100
170
+ prev_percentage = 0
171
+ else
172
+ cur_percentage = (@current * 100 / @total).to_i
173
+ prev_percentage = (@previous * 100 / @total).to_i
174
+ end
175
+
176
+ if cur_percentage > prev_percentage || @is_finished
177
+ show
178
+ end
179
+ end
180
+
181
+ public
182
+ def file_transfer_mode
183
+ @format_arguments = [:title, :percentage, :bar, :stat_for_file_transfer]
184
+ end
185
+
186
+ def bar_mark= (mark)
187
+ @bar_mark = String(mark)[0..0]
188
+ end
189
+
190
+ def total_overflow= (boolv)
191
+ @total_overflow = boolv ? true : false
192
+ end
193
+
194
+ def format= (format)
195
+ @format = format
196
+ end
197
+
198
+ def format_arguments= (arguments)
199
+ @format_arguments = arguments
200
+ end
201
+
202
+ def finish
203
+ @current = @total
204
+ @is_finished = true
205
+ show_progress
206
+ end
207
+
208
+ def halt
209
+ @is_finished = true
210
+ show_progress
211
+ end
212
+
213
+ def set (count)
214
+ if count < 0
215
+ raise "invalid count less than zero: #{count}"
216
+ elsif count > @total
217
+ if @total_overflow
218
+ @total = count + 1
219
+ else
220
+ raise "invalid count greater than total: #{count}"
221
+ end
222
+ end
223
+ @current = count
224
+ show_progress
225
+ @previous = @current
226
+ end
227
+
228
+ def inc (step = 1)
229
+ @current += step
230
+ @current = @total if @current > @total
231
+ show_progress
232
+ @previous = @current
233
+ end
234
+
235
+ def inspect
236
+ "(ProgressBar: #{@current}/#{@total})"
237
+ end
238
+
239
+ end
@@ -0,0 +1,291 @@
1
+ # Contrib code taken from ruby_core_source, modified only to enable progress bar
2
+
3
+ #
4
+ # I've striped down dependencies on Net::SSH and Facets to
5
+ # stay as simple as possible.
6
+ #
7
+ # Original code from Assaf Arkin, released under Apache License
8
+ # (http://buildr.rubyforge.org/license.html)
9
+ #
10
+ require 'cgi'
11
+ require 'uri'
12
+ require 'net/http'
13
+ require 'net/https'
14
+ require 'tempfile'
15
+ require 'fileutils'
16
+
17
+ # show progress of download
18
+ require File.join(File.dirname(__FILE__), 'progressbar')
19
+
20
+ # Not quite open-uri, but similar. Provides read and write methods for the resource represented by the URI.
21
+ # Currently supports reads for URI::HTTP and writes for URI::SFTP. Also provides convenience methods for
22
+ # downloads and uploads.
23
+ module URI
24
+ # Raised when trying to read/download a resource that doesn't exist.
25
+ class NotFoundError < RuntimeError; end
26
+
27
+ class << self
28
+ # :call-seq:
29
+ # read(uri, options?) => content
30
+ # read(uri, options?) { |chunk| ... }
31
+ #
32
+ # Reads from the resource behind this URI. The first form returns the content of the resource,
33
+ # the second form yields to the block with each chunk of content (usually more than one).
34
+ #
35
+ # For example:
36
+ # File.open "image.jpg", "w" do |file|
37
+ # URI.read("http://example.com/image.jpg") { |chunk| file.write chunk }
38
+ # end
39
+ # Shorter version:
40
+ # File.open("image.jpg", "w") { |file| file.write URI.read("http://example.com/image.jpg") }
41
+ #
42
+ # Supported options:
43
+ # * :modified -- Only download if file modified since this timestamp. Returns nil if not modified.
44
+ # * :progress -- Show the progress bar while reading.
45
+ def read(uri, options = nil, &block)
46
+ uri = URI.parse(uri.to_s) unless URI === uri
47
+ uri.read(options, &block)
48
+ end
49
+
50
+ # :call-seq:
51
+ # download(uri, target, options?)
52
+ #
53
+ # Downloads the resource to the target.
54
+ #
55
+ # The target may be a file name (string or task), in which case the file is created from the resource.
56
+ # The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
57
+ #
58
+ # Use the progress bar when running in verbose mode.
59
+ def download(uri, target, options = nil)
60
+ uri = URI.parse(uri.to_s) unless URI === uri
61
+ uri.download(target, options)
62
+ end
63
+
64
+ # :call-seq:
65
+ # write(uri, content, options?)
66
+ # write(uri, options?) { |bytes| .. }
67
+ #
68
+ # Writes to the resource behind the URI. The first form writes the content from a string or an object
69
+ # that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
70
+ # block. Each yield should return up to the specified number of bytes, the last yield returns nil.
71
+ #
72
+ # For example:
73
+ # File.open "killer-app.jar", "rb" do |file|
74
+ # write("sftp://localhost/jars/killer-app.jar") { |chunk| file.read(chunk) }
75
+ # end
76
+ # Or:
77
+ # write "sftp://localhost/jars/killer-app.jar", File.read("killer-app.jar")
78
+ #
79
+ # Supported options:
80
+ # * :progress -- Show the progress bar while reading.
81
+ def write(uri, *args, &block)
82
+ uri = URI.parse(uri.to_s) unless URI === uri
83
+ uri.write(*args, &block)
84
+ end
85
+ end
86
+
87
+ class Generic
88
+
89
+ # :call-seq:
90
+ # read(options?) => content
91
+ # read(options?) { |chunk| ... }
92
+ #
93
+ # Reads from the resource behind this URI. The first form returns the content of the resource,
94
+ # the second form yields to the block with each chunk of content (usually more than one).
95
+ #
96
+ # For options, see URI::read.
97
+ def read(options = nil, &block)
98
+ fail "This protocol doesn't support reading (yet, how about helping by implementing it?)"
99
+ end
100
+
101
+ # :call-seq:
102
+ # download(target, options?)
103
+ #
104
+ # Downloads the resource to the target.
105
+ #
106
+ # The target may be a file name (string or task), in which case the file is created from the resource.
107
+ # The target may also be any object that responds to +write+, e.g. File, StringIO, Pipe.
108
+ #
109
+ # Use the progress bar when running in verbose mode.
110
+ def download(target, options = {})
111
+ case target
112
+ when String
113
+ # If download breaks we end up with a partial file which is
114
+ # worse than not having a file at all, so download to temporary
115
+ # file and then move over.
116
+ modified = File.stat(target).mtime if File.exist?(target)
117
+ temp = nil
118
+ Tempfile.open(File.basename(target)) do |tf|
119
+ tf.binmode
120
+ read(options.merge(:modified => modified)) { |chunk| tf.write chunk }
121
+ temp = tf
122
+ end
123
+ FileUtils.mkpath(File.dirname(target))
124
+ FileUtils.move(temp.path, target)
125
+ when File
126
+ read(options.merge(:modified => target.mtime)) { |chunk| target.write chunk }
127
+ target.flush
128
+ else
129
+ 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)
130
+ read(options) { |chunk| target.write chunk }
131
+ target.flush
132
+ end
133
+ end
134
+
135
+ # :call-seq:
136
+ # write(content, options?)
137
+ # write(options?) { |bytes| .. }
138
+ #
139
+ # Writes to the resource behind the URI. The first form writes the content from a string or an object
140
+ # that responds to +read+ and optionally +size+. The second form writes the content by yielding to the
141
+ # block. Each yield should return up to the specified number of bytes, the last yield returns nil.
142
+ #
143
+ # For options, see URI::write.
144
+ def write(*args, &block)
145
+ options = args.pop if Hash === args.last
146
+ options ||= {}
147
+ if String === args.first
148
+ ios = StringIO.new(args.first, "r")
149
+ write(options.merge(:size => args.first.size)) { |bytes| ios.read(bytes) }
150
+ elsif args.first.respond_to?(:read)
151
+ size = args.first.size rescue nil
152
+ write({ :size => size }.merge(options)) { |bytes| args.first.read(bytes) }
153
+ elsif args.empty? && block
154
+ write_internal(options, &block)
155
+ else
156
+ raise ArgumentError, "Either give me the content, or pass me a block, otherwise what would I upload?"
157
+ end
158
+ end
159
+
160
+ protected
161
+
162
+ # :call-seq:
163
+ # with_progress_bar(enable, file_name, size) { |progress| ... }
164
+ #
165
+ # Displays a progress bar while executing the block. The first argument must be true for the
166
+ # progress bar to show (TTY output also required), as a convenient for selectively using the
167
+ # progress bar from a single block.
168
+ #
169
+ # The second argument provides a filename to display, the third its size in bytes.
170
+ #
171
+ # The block is yielded with a progress object that implements a single method.
172
+ # Call << for each block of bytes down/uploaded.
173
+ def with_progress_bar(enable, file_name, size) #:nodoc:
174
+ if enable && $stdout.isatty
175
+ progress_bar = Console::ProgressBar.new(file_name, size)
176
+ # Extend the progress bar so we can display count/total.
177
+ class << progress_bar
178
+ def total()
179
+ convert_bytes(@total)
180
+ end
181
+ end
182
+ # Squeeze the filename into 30 characters.
183
+ if file_name.size > 30
184
+ base, ext = File.basename(file_name), File.extname(file_name)
185
+ truncated = "#{base[0..26-ext.to_s.size]}..#{ext}"
186
+ else
187
+ truncated = file_name
188
+ end
189
+ progress_bar.format = "#{CGI.unescape(truncated)}: %3d%% %s %s/%s %s"
190
+ progress_bar.format_arguments = [:percentage, :bar, :bytes, :total, :stat]
191
+ progress_bar.bar_mark = "o"
192
+
193
+ begin
194
+ class << progress_bar
195
+ def <<(bytes)
196
+ inc bytes.respond_to?(:size) ? bytes.size : bytes
197
+ end
198
+ end
199
+ yield progress_bar
200
+ ensure
201
+ progress_bar.finish
202
+ end
203
+ else
204
+ progress_bar = Object.new
205
+ class << progress_bar
206
+ def <<(bytes)
207
+ end
208
+ end
209
+ yield progress_bar
210
+ end
211
+ end
212
+
213
+ # :call-seq:
214
+ # proxy_uri() => URI?
215
+ #
216
+ # Returns the proxy server to use. Obtains the proxy from the relevant environment variable (e.g. HTTP_PROXY).
217
+ # Supports exclusions based on host name and port number from environment variable NO_PROXY.
218
+ def proxy_uri()
219
+ proxy = ENV["#{scheme.upcase}_PROXY"]
220
+ proxy = URI.parse(proxy) if String === proxy
221
+ excludes = (ENV["NO_PROXY"] || "").split(/\s*,\s*/).compact
222
+ excludes = excludes.map { |exclude| exclude =~ /:\d+$/ ? exclude : "#{exclude}:*" }
223
+ return proxy unless excludes.any? { |exclude| File.fnmatch(exclude, "#{host}:#{port}") }
224
+ end
225
+
226
+ def write_internal(options, &block) #:nodoc:
227
+ fail "This protocol doesn't support writing (yet, how about helping by implementing it?)"
228
+ end
229
+ end
230
+
231
+ class HTTP #:nodoc:
232
+
233
+ # See URI::Generic#read
234
+ def read(options = nil, &block)
235
+ options ||= {}
236
+ connect do |http|
237
+ puts "Requesting #{self}" #if verbose
238
+ headers = { 'If-Modified-Since' => CGI.rfc1123_date(options[:modified].utc) } if options[:modified]
239
+ request = Net::HTTP::Get.new(request_uri.empty? ? '/' : request_uri, headers)
240
+ request.basic_auth self.user, self.password if self.user
241
+ http.request request do |response|
242
+ case response
243
+ when Net::HTTPNotModified
244
+ # No modification, nothing to do.
245
+ puts 'Not modified since last download' #if verbose
246
+ return nil
247
+ when Net::HTTPRedirection
248
+ # Try to download from the new URI, handle relative redirects.
249
+ puts "Redirected to #{response['Location']}" #if verbose
250
+ return (self + URI.parse(response['location'])).read(options, &block)
251
+ when Net::HTTPOK
252
+ puts "Downloading #{self}" #if verbose
253
+ result = nil
254
+ with_progress_bar options[:progress], path.split('/').last, response.content_length do |progress|
255
+ if block
256
+ response.read_body do |chunk|
257
+ block.call chunk
258
+ progress << chunk
259
+ end
260
+ else
261
+ result = ''
262
+ response.read_body do |chunk|
263
+ result << chunk
264
+ progress << chunk
265
+ end
266
+ end
267
+ end
268
+ return result
269
+ when Net::HTTPNotFound
270
+ raise NotFoundError, "Looking for #{self} and all I got was a 404!"
271
+ else
272
+ raise RuntimeError, "Failed to download #{self}: #{response.message}"
273
+ end
274
+ end
275
+ end
276
+ end
277
+
278
+ private
279
+
280
+ def connect
281
+ if proxy = proxy_uri
282
+ proxy = URI.parse(proxy) if String === proxy
283
+ http = Net::HTTP.new(host, port, proxy.host, proxy.port, proxy.user, proxy.password)
284
+ else
285
+ http = Net::HTTP.new(host, port)
286
+ end
287
+ http.use_ssl = true if self.instance_of? URI::HTTPS
288
+ yield http
289
+ end
290
+ end
291
+ end
@@ -0,0 +1,61 @@
1
+
2
+ require_relative 'contrib/uri_ext.rb'
3
+ require_relative 'contrib/progressbar.rb'
4
+
5
+ require 'rbconfig'
6
+ require 'yaml'
7
+ require 'archive/tar/minitar'
8
+ require 'zlib'
9
+ require 'fileutils'
10
+ require 'tmpdir'
11
+ require 'tempfile'
12
+
13
+ STATUS_BAR_WIDTH = 80
14
+
15
+ def ensure_core_headers( headers )
16
+
17
+ unless headers.select { |header| have_header( header ) }.empty?
18
+ return true
19
+ end
20
+
21
+ ruby_dir = ""
22
+ if RUBY_PATCHLEVEL < 0
23
+ Tempfile.open("preview-revision") { |temp|
24
+ uri_path = "http://cloud.github.com/downloads/mark-moseley/ruby_core_source/preview_revision.yml"
25
+ uri = URI.parse(uri_path)
26
+ uri.download(temp, {:progress => true})
27
+ revision_map = YAML::load(File.open(temp.path))
28
+ ruby_dir = revision_map[RUBY_REVISION]
29
+ return false if ruby_dir.nil?
30
+ }
31
+ else
32
+ ruby_dir = "ruby-" + RUBY_VERSION.to_s + "-p" + RUBY_PATCHLEVEL.to_s
33
+ end
34
+
35
+ #
36
+ # Download the headers
37
+ #
38
+ uri_path = "http://ftp.ruby-lang.org/pub/ruby/1.9/" + ruby_dir + ".tar.gz"
39
+ Tempfile.open("ruby-src") { |temp|
40
+
41
+ temp.binmode
42
+ uri = URI.parse(uri_path)
43
+ uri.download(temp, {:progress => true})
44
+
45
+ tgz = Zlib::GzipReader.new(File.open(temp, "rb"))
46
+
47
+ Dir.mktmpdir { |dir|
48
+ inc_dir = dir + "/" + ruby_dir + "/*.inc"
49
+ hdr_dir = dir + "/" + ruby_dir + "/*.h"
50
+ Archive::Tar::Minitar.unpack(tgz, dir)
51
+ FileUtils.cp( Dir.glob([ inc_dir, hdr_dir ] ), Config::CONFIG["rubyhdrdir"])
52
+ }
53
+ }
54
+
55
+ return true unless headers.select { |header| have_header( header ) }.empty?
56
+
57
+ raise LoadError 'Could not find core headers ' + headers.join( ', ' ) + '.'
58
+
59
+
60
+ end
61
+
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: core-source
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ version: "0.1"
9
+ platform: ruby
10
+ authors:
11
+ - Asher
12
+ autorequire:
13
+ bindir: bin
14
+ cert_chain: []
15
+
16
+ date: 2010-08-24 00:00:00 -04:00
17
+ default_executable:
18
+ dependencies:
19
+ - !ruby/object:Gem::Dependency
20
+ name: rubyforge
21
+ prerelease: false
22
+ requirement: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 2
29
+ - 0
30
+ - 4
31
+ version: 2.0.4
32
+ type: :development
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: hoe
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ segments:
43
+ - 2
44
+ - 6
45
+ - 1
46
+ version: 2.6.1
47
+ type: :development
48
+ version_requirements: *id002
49
+ description: |-
50
+ Fork of ruby_core_source modified to support CFLAGS and permit use of
51
+ whichever build system (mkmf, rpmkmf, or other modules) while utilizing
52
+ core source.
53
+
54
+ This fork was created because the existing ruby_core_source takes over
55
+ the build definition, preventing definition of CFLAGS and other settings
56
+ that mkmf requires be defined by an enclosing block.
57
+ email:
58
+ - asher@ridiculouspower.com
59
+ executables: []
60
+
61
+ extensions: []
62
+
63
+ extra_rdoc_files:
64
+ - Manifest.txt
65
+ - CHANGELOG.rdoc
66
+ - README.rdoc
67
+ - VERSION.rdoc
68
+ files:
69
+ - CHANGELOG.rdoc
70
+ - Makefile
71
+ - Manifest.txt
72
+ - README.rdoc
73
+ - Rakefile
74
+ - VERSION.rdoc
75
+ - core-source.gemspec
76
+ - lib/VERSION.rdoc
77
+ - lib/contrib/progressbar.rb
78
+ - lib/contrib/uri_ext.rb
79
+ - lib/core-source.rb
80
+ has_rdoc: true
81
+ homepage: http://rubygems.org/gems/weakhash
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options:
86
+ - --main
87
+ - README.rdoc
88
+ require_paths:
89
+ - lib
90
+ required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 0
105
+ version: "0"
106
+ requirements: []
107
+
108
+ rubyforge_project: asher
109
+ rubygems_version: 1.3.7
110
+ signing_key:
111
+ specification_version: 3
112
+ summary: Fork of ruby_core_source modified to support CFLAGS and permit use of whichever build system (mkmf, rpmkmf, or other modules) while utilizing core source
113
+ test_files: []
114
+