Skip to content
This repository
Browse code

gem_prelude is now owned by ruby

  • Loading branch information...
commit b2be0da0b7d7c9e46aa5010fe5a4479add7fbe7c 1 parent f7d4eee
Eric Hodel drbrain authored

Showing 3 changed files with 1 addition and 306 deletions. Show diff stats Hide diff stats

  1. +1 1  Manifest.txt
  2. +0 1  Rakefile
  3. +0 304 util/gem_prelude.rb
2  Manifest.txt
@@ -191,5 +191,5 @@ test/rubygems/test_gem_validator.rb
191 191 test/rubygems/test_gem_version.rb
192 192 test/rubygems/test_gem_version_option.rb
193 193 test/rubygems/test_kernel.rb
  194 +test/rubygems/test_require.rb
194 195 util/CL2notes
195   -util/gem_prelude.rb
1  Rakefile
@@ -127,7 +127,6 @@ def diff_with dir
127 127 sh "diff #{diff_options} lib/rubygems #{dir}/lib/rubygems; true"
128 128 sh "diff #{diff_options} lib/rbconfig #{dir}/lib/rbconfig; true"
129 129 sh "diff #{diff_options} test #{dir}/test/rubygems; true"
130   - sh "diff #{diff_options} util/gem_prelude.rb #{dir}/gem_prelude.rb; true"
131 130 end
132 131
133 132 rubinius_dir = ENV['RUBINIUS_PATH'] || '../git.rubini.us/code'
304 util/gem_prelude.rb
... ... @@ -1,304 +0,0 @@
1   -# depends on: array.rb dir.rb env.rb file.rb hash.rb module.rb regexp.rb
2   -# vim: filetype=ruby
3   -
4   -# NOTICE: Ruby is during initialization here.
5   -# * Encoding.default_external does not reflects -E.
6   -# * Should not expect Encoding.default_internal.
7   -# * Locale encoding is available.
8   -
9   -if defined?(Gem) then
10   -
11   - # :stopdoc:
12   -
13   - module Kernel
14   -
15   - def gem(gem_name, *requirements)
16   - Gem.push_gem_version_on_load_path(gem_name, *requirements)
17   - end
18   - private :gem
19   - end
20   -
21   - module Gem
22   -
23   - ConfigMap = {
24   - :EXEEXT => RbConfig::CONFIG["EXEEXT"],
25   - :RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
26   - :arch => RbConfig::CONFIG["arch"],
27   - :bindir => RbConfig::CONFIG["bindir"],
28   - :libdir => RbConfig::CONFIG["libdir"],
29   - :ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
30   - :ruby_version => RbConfig::CONFIG["ruby_version"],
31   - :rubylibprefix => RbConfig::CONFIG["rubylibprefix"],
32   - :sitedir => RbConfig::CONFIG["sitedir"],
33   - :sitelibdir => RbConfig::CONFIG["sitelibdir"],
34   - }
35   -
36   - def self.dir
37   - @gem_home ||= nil
38   - set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
39   - @gem_home
40   - end
41   -
42   - def self.path
43   - @gem_path ||= nil
44   - unless @gem_path
45   - paths = [ENV['GEM_PATH'] || default_path]
46   - paths << APPLE_GEM_HOME if defined? APPLE_GEM_HOME
47   - set_paths(paths.compact.join(File::PATH_SEPARATOR))
48   - end
49   - @gem_path
50   - end
51   -
52   - def self.post_install(&hook)
53   - @post_install_hooks << hook
54   - end
55   -
56   - def self.post_uninstall(&hook)
57   - @post_uninstall_hooks << hook
58   - end
59   -
60   - def self.pre_install(&hook)
61   - @pre_install_hooks << hook
62   - end
63   -
64   - def self.pre_uninstall(&hook)
65   - @pre_uninstall_hooks << hook
66   - end
67   -
68   - def self.set_home(home)
69   - home = home.dup.force_encoding(Encoding.find('filesystem'))
70   - home.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
71   - @gem_home = home
72   - end
73   -
74   - def self.set_paths(gpaths)
75   - if gpaths
76   - @gem_path = gpaths.split(File::PATH_SEPARATOR)
77   -
78   - if File::ALT_SEPARATOR then
79   - @gem_path.map! do |path|
80   - path.gsub File::ALT_SEPARATOR, File::SEPARATOR
81   - end
82   - end
83   -
84   - @gem_path << Gem.dir
85   - else
86   - # TODO: should this be Gem.default_path instead?
87   - @gem_path = [Gem.dir]
88   - end
89   -
90   - @gem_path.uniq!
91   - @gem_path.map!{|x|x.force_encoding(Encoding.find('filesystem'))}
92   - end
93   -
94   - def self.user_home
95   - @user_home ||= File.expand_path("~").force_encoding(Encoding.find('filesystem'))
96   - rescue
97   - if File::ALT_SEPARATOR then
98   - "C:/"
99   - else
100   - "/"
101   - end
102   - end
103   -
104   - # begin rubygems/defaults
105   - # NOTE: this require will be replaced with in-place eval before compilation.
106   - require 'lib/rubygems/defaults.rb'
107   - # end rubygems/defaults
108   -
109   -
110   - ##
111   - # Methods before this line will be removed when QuickLoader is replaced
112   - # with the real RubyGems
113   -
114   - GEM_PRELUDE_METHODS = Gem.methods(false)
115   -
116   - begin
117   - verbose, debug = $VERBOSE, $DEBUG
118   - $VERBOSE = $DEBUG = nil
119   -
120   - begin
121   - require 'rubygems/defaults/operating_system'
122   - rescue ::LoadError
123   - end
124   -
125   - if defined?(RUBY_ENGINE) then
126   - begin
127   - require "rubygems/defaults/#{RUBY_ENGINE}"
128   - rescue ::LoadError
129   - end
130   - end
131   - ensure
132   - $VERBOSE, $DEBUG = verbose, debug
133   - end
134   -
135   - module QuickLoader
136   -
137   - @loaded_full_rubygems_library = false
138   -
139   - def self.load_full_rubygems_library
140   - return if @loaded_full_rubygems_library
141   -
142   - @loaded_full_rubygems_library = true
143   -
144   - class << Gem
145   - Gem::GEM_PRELUDE_METHODS.each do |method_name|
146   - undef_method method_name
147   - end
148   - undef_method :const_missing
149   - undef_method :method_missing
150   - end
151   -
152   - Kernel.module_eval do
153   - undef_method :gem if method_defined? :gem
154   - end
155   -
156   - $".delete path_to_full_rubygems_library
157   - $".each do |path|
158   - if /#{Regexp.escape File::SEPARATOR}rubygems\.rb\z/ =~ path
159   - raise LoadError, "another rubygems is already loaded from #{path}"
160   - end
161   - end
162   - require 'rubygems'
163   - end
164   -
165   - def self.fake_rubygems_as_loaded
166   - path = path_to_full_rubygems_library
167   - $" << path unless $".include?(path)
168   - end
169   -
170   - def self.path_to_full_rubygems_library
171   - installed_path = File.join(Gem::ConfigMap[:rubylibprefix], Gem::ConfigMap[:ruby_version])
172   - if $:.include?(installed_path)
173   - return File.join(installed_path, 'rubygems.rb')
174   - else # e.g., on test-all
175   - $:.each do |dir|
176   - if File.exist?( path = File.join(dir, 'rubygems.rb') )
177   - return path
178   - end
179   - end
180   - raise LoadError, 'rubygems.rb'
181   - end
182   - end
183   -
184   - GemPaths = {}
185   - GemVersions = {}
186   -
187   - def push_gem_version_on_load_path(gem_name, *requirements)
188   - if requirements.empty?
189   - unless GemPaths.has_key?(gem_name) then
190   - raise Gem::LoadError, "Could not find RubyGem #{gem_name} (>= 0)\n"
191   - end
192   -
193   - # highest version gems already active
194   - return false
195   - else
196   - if requirements.length > 1 then
197   - QuickLoader.load_full_rubygems_library
198   - return gem(gem_name, *requirements)
199   - end
200   -
201   - requirement, version = requirements[0].split
202   - requirement.strip!
203   -
204   - if loaded_version = GemVersions[gem_name] then
205   - case requirement
206   - when ">", ">=" then
207   - return false if
208   - (loaded_version <=> Gem.integers_for(version)) >= 0
209   - when "~>" then
210   - required_version = Gem.integers_for version
211   -
212   - return false if loaded_version.first == required_version.first
213   - end
214   - end
215   -
216   - QuickLoader.load_full_rubygems_library
217   - gem gem_name, *requirements
218   - end
219   - end
220   -
221   - def integers_for(gem_version)
222   - numbers = gem_version.split(".").collect {|n| n.to_i}
223   - numbers.pop while numbers.last == 0
224   - numbers << 0 if numbers.empty?
225   - numbers
226   - end
227   -
228   - def push_all_highest_version_gems_on_load_path
229   - Gem.path.each do |path|
230   - gems_directory = File.join(path, "gems")
231   -
232   - if File.exist?(gems_directory) then
233   - Dir.entries(gems_directory).each do |gem_directory_name|
234   - next if gem_directory_name == "." || gem_directory_name == ".."
235   -
236   - next unless gem_name = gem_directory_name[/(.*)-(.*)/, 1]
237   - new_version = integers_for($2)
238   - current_version = GemVersions[gem_name]
239   -
240   - if !current_version or (current_version <=> new_version) < 0 then
241   - GemVersions[gem_name] = new_version
242   - GemPaths[gem_name] = File.join(gems_directory, gem_directory_name)
243   - end
244   - end
245   - end
246   - end
247   -
248   - require_paths = []
249   -
250   - GemPaths.each_value do |path|
251   - if File.exist?(file = File.join(path, ".require_paths")) then
252   - paths = File.read(file).split.map do |require_path|
253   - File.join path, require_path
254   - end
255   -
256   - require_paths.concat paths
257   - else
258   - require_paths << file if File.exist?(file = File.join(path, "bin"))
259   - require_paths << file if File.exist?(file = File.join(path, "lib"))
260   - end
261   - end
262   -
263   - # "tag" the first require_path inserted into the $LOAD_PATH to enable
264   - # indexing correctly with rubygems proper when it inserts an explicitly
265   - # gem version
266   - unless require_paths.empty? then
267   - require_paths.first.instance_variable_set(:@gem_prelude_index, true)
268   - end
269   - # gem directories must come after -I and ENV['RUBYLIB']
270   - $:[$:.index{|e|e.instance_variable_defined?(:@gem_prelude_index)}||-1,0] = require_paths
271   - end
272   -
273   - def const_missing(constant)
274   - QuickLoader.load_full_rubygems_library
275   -
276   - if Gem.const_defined?(constant) then
277   - Gem.const_get constant
278   - else
279   - super
280   - end
281   - end
282   -
283   - def method_missing(method, *args, &block)
284   - QuickLoader.load_full_rubygems_library
285   - super unless Gem.respond_to?(method)
286   - Gem.send(method, *args, &block)
287   - end
288   - end
289   -
290   - extend QuickLoader
291   -
292   - end
293   -
294   - begin
295   - Gem.push_all_highest_version_gems_on_load_path
296   - Gem::QuickLoader.fake_rubygems_as_loaded
297   - rescue Exception => e
298   - puts "Error loading gem paths on load path in gem_prelude"
299   - puts e
300   - puts e.backtrace.join("\n")
301   - end
302   -
303   -end
304   -

0 comments on commit b2be0da

Please sign in to comment.
Something went wrong with that request. Please try again.