diff options
Diffstat (limited to 'lib/rubygems/basic_specification.rb')
-rw-r--r-- | lib/rubygems/basic_specification.rb | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/lib/rubygems/basic_specification.rb b/lib/rubygems/basic_specification.rb index 24bb4bc014..5afa7ee14c 100644 --- a/lib/rubygems/basic_specification.rb +++ b/lib/rubygems/basic_specification.rb @@ -38,11 +38,12 @@ class Gem::BasicSpecification # Return true if this spec can require +file+. def contains_requirable_file? file - root = full_gem_path + build_extensions + suffixes = Gem.suffixes - require_paths.any? do |lib| - base = "#{root}/#{lib}/#{file}" + full_require_paths.any? do |dir| + base = "#{dir}/#{file}" suffixes.any? { |suf| File.file? "#{base}#{suf}" } end end @@ -52,6 +53,27 @@ class Gem::BasicSpecification File.dirname(loaded_from) == self.class.default_specifications_dir end + ## + # The directory the named +extension+ was installed into after being built. + # + # Usage: + # + # spec.extensions.each do |ext| + # puts spec.extension_install_dir ext + # end + + def extension_install_dir + ruby_api_version = + if 'no' == RbConfig::CONFIG['ENABLE_SHARED'] then + "#{Gem.ruby_api_version}-static" + else + Gem.ruby_api_version + end + + File.join base_dir, 'extensions', Gem::Platform.local.to_s, + ruby_api_version, full_name + end + def find_full_gem_path # :nodoc: # TODO: also, shouldn't it default to full_name if it hasn't been written? path = File.expand_path File.join(gems_dir, full_name) @@ -84,6 +106,28 @@ class Gem::BasicSpecification end ## + # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is + # activated. + + def full_require_paths + full_paths = @require_paths.map do |path| + File.join full_gem_path, path + end + + full_paths << extension_install_dir unless @extensions.empty? + + full_paths + end + + ## + # Returns the full path to this spec's gem directory. + # eg: /usr/local/lib/ruby/1.8/gems/mygem-1.0 + + def gem_dir + @gem_dir ||= File.expand_path File.join(gems_dir, full_name) + end + + ## # Returns the full path to the gems directory containing this spec's # gem directory. eg: /usr/local/lib/ruby/1.8/gems @@ -119,10 +163,30 @@ class Gem::BasicSpecification end ## - # Require paths of the gem + # Paths in the gem to add to <code>$LOAD_PATH</code> when this gem is + # activated. + # + # See also #require_paths= + # + # If you have an extension you do not need to add <code>"ext"</code> to the + # require path, the extension build process will copy the extension files + # into "lib" for you. + # + # The default value is <code>"lib"</code> + # + # Usage: + # + # # If all library files are in the root directory... + # spec.require_path = '.' def require_paths - raise NotImplementedError + return @require_paths if @extensions.empty? + + relative_extension_install_dir = + File.join '..', '..', '..', 'extensions', Gem::Platform.local.to_s, + Gem.ruby_api_version, full_name + + @require_paths + [relative_extension_install_dir] end ## |