diff --git a/bundler/spec/support/hax.rb b/bundler/spec/support/hax.rb index c7fe3637cc5e..d46592b4bacc 100644 --- a/bundler/spec/support/hax.rb +++ b/bundler/spec/support/hax.rb @@ -50,4 +50,11 @@ class << self end end end + + class Specification < BasicSpecification + if defined?(DEFAULT_GEMS_LIST) + remove_const :DEFAULT_GEMS_LIST + DEFAULT_GEMS_LIST = %w[irb json foo bar].freeze + end + end end diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index 0477b4703538..41d57bfb0ee5 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -321,14 +321,15 @@ def install dir_mode = options[:dir_mode] FileUtils.mkdir_p gem_dir, :mode => dir_mode && 0o755 + extract_files + + build_extensions + write_build_info_file + if @options[:install_as_default] extract_bin write_default_spec else - extract_files - - build_extensions - write_build_info_file run_post_build_hooks end @@ -760,6 +761,12 @@ def verify_spec end end + def verify_default_gems + return unless options[:install_as_default] + return if Gem::Specification::DEFAULT_GEMS_LIST.include?(spec.name) + raise Gem::InstallError, "#{spec} is not a default gem." + end + ## # Return the text for an application file. @@ -925,6 +932,10 @@ def pre_install_checks ensure_loadable_spec + verify_spec + + verify_default_gems + if options[:install_as_default] Gem.ensure_default_gem_subdirectories gem_home else diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 91d4408a16f4..f5b52f7259e8 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -110,6 +110,32 @@ class Gem::Specification < Gem::BasicSpecification VALID_NAME_PATTERN = /\A[a-zA-Z0-9\.\-\_]+\z/ # :nodoc: + DEFAULT_GEMS_LIST = %w[ + bigdecimal + bundler + cmath + csv + date + dbm + etc + fcntl + fiddle + fileutils + gdbm + io-console + ipaddr + json + openssl + psych + rdoc + scanf + sdbm + stringio + strscan + webrick + zlib + ].freeze # :nodoc: + # :startdoc: ## diff --git a/test/rubygems/helper.rb b/test/rubygems/helper.rb index 705ed71f0c82..9c8a4fb0bc93 100644 --- a/test/rubygems/helper.rb +++ b/test/rubygems/helper.rb @@ -63,6 +63,11 @@ def self.specific_extra_args_hash=(value) end end +class Gem::Specification < Gem::BasicSpecification + remove_const :DEFAULT_GEMS_LIST + DEFAULT_GEMS_LIST = %w[systemgem default bundler a b c z].freeze +end + ## # RubyGemTestCase provides a variety of methods for testing rubygems and # gem-related behavior in a sandbox. Through RubyGemTestCase you can install