Permalink
Browse files

Warn about extension building once per gem

Part of #796
  • Loading branch information...
1 parent 6062fbc commit da3be982fa50f097073260c9c0c38fbf9e4228b9 @drbrain drbrain committed Jan 29, 2014
@@ -15,6 +15,11 @@ class Gem::BasicSpecification
attr_writer :extension_dir # :nodoc:
##
+ # Is this specification ignored for activation purposes?
+
+ attr_writer :ignored # :nodoc:
+
+ ##
# The path this gemspec was loaded from. This attribute is not persisted.
attr_reader :loaded_from
@@ -53,7 +58,15 @@ def base_dir
# Return true if this spec can require +file+.
def contains_requirable_file? file
- build_extensions
+ if instance_variable_defined? :@ignored then
+ return false
+ elsif missing_extensions? then
+ @ignored = true
+
+ warn "Ignoring #{full_name} because its extensions are not built. " +
+ "Try: gem pristine #{full_name}"
+ return false
+ end
suffixes = Gem.suffixes
@@ -155,6 +155,8 @@ def require_paths
def to_spec
@spec ||= Gem::Specification.load(loaded_from)
+ @spec.ignored = instance_variable_defined? :@ignored
+ @spec
end
##
@@ -831,6 +831,23 @@ def test_self_try_activate_missing_dep
assert_match %r%Could not find 'b' %, e.message
end
+ def test_self_try_activate_missing_extensions
+ util_spec 'ext', '1' do |s|
+ s.extensions = %w[ext/extconf.rb]
+ s.mark_version
+ s.installed_by_version = v('2.2')
+ end
+
+ _, err = capture_io do
+ refute Gem.try_activate 'nonexistent'
+ end
+
+ expected = "Ignoring ext-1 because its extensions are not built. " +
+ "Try: gem pristine ext-1\n"
+
+ assert_equal expected, err
+ end
+
def test_self_use_paths
util_ensure_gem_dirs
@@ -1332,22 +1332,14 @@ def test_contains_requirable_file_eh
def test_contains_requirable_file_eh_extension
ext_spec
- extconf_rb = File.join @ext.gem_dir, @ext.extensions.first
- FileUtils.mkdir_p File.dirname extconf_rb
-
- open extconf_rb, 'w' do |f|
- f.write <<-'RUBY'
- open 'Makefile', 'w' do |f|
- f.puts "clean:\n\techo cleaned"
- f.puts "default:\n\techo built"
- f.puts "install:\n\techo installed"
- end
- RUBY
+ _, err = capture_io do
+ refute @ext.contains_requirable_file? 'nonexistent'
end
- refute @ext.contains_requirable_file? 'nonexistent'
+ expected = "Ignoring ext-1 because its extensions are not built. " +
+ "Try: gem pristine ext-1\n"
- assert_path_exists @ext.extension_dir
+ assert_equal expected, err
end
def test_date
@@ -55,22 +55,14 @@ def test_contains_requirable_file_eh
def test_contains_requirable_file_eh_extension
stub_with_extension do |stub|
- extconf_rb = File.join stub.gem_dir, stub.extensions.first
- FileUtils.mkdir_p File.dirname extconf_rb
-
- open extconf_rb, 'w' do |f|
- f.write <<-'RUBY'
- open 'Makefile', 'w' do |f|
- f.puts "clean:\n\techo cleaned"
- f.puts "default:\n\techo built"
- f.puts "install:\n\techo installed"
- end
- RUBY
+ _, err = capture_io do
+ refute stub.contains_requirable_file? 'nonexistent'
end
- refute stub.contains_requirable_file? 'nonexistent'
+ expected = "Ignoring stub_e-2 because its extensions are not built. " +
+ "Try: gem pristine stub_e-2\n"
- assert_path_exists stub.extension_dir
+ assert_equal expected, err
end
end
@@ -128,6 +120,17 @@ def test_missing_extensions_eh_none
def test_to_spec
assert @foo.to_spec.is_a?(Gem::Specification)
assert_equal "foo", @foo.to_spec.name
+ refute @foo.to_spec.instance_variable_get :@ignored
+ end
+
+ def test_to_spec_missing_extensions
+ stub = stub_with_extension
+
+ capture_io do
+ stub.contains_requirable_file? 'nonexistent'
+ end
+
+ assert stub.to_spec.instance_variable_get :@ignored
end
def stub_with_extension

0 comments on commit da3be98

Please sign in to comment.