Permalink
Browse files

Add Specification#missing_extensions?

This will allow us to have better behavior when extensions have not been
built for the current platform.

Part of #796
  • Loading branch information...
1 parent 45d1741 commit 6062fbc60c05f8ff68f6fd95473850e5335d271c @drbrain drbrain committed Jan 28, 2014
@@ -1950,6 +1950,19 @@ def method_missing(sym, *a, &b) # :nodoc:
end
end
+ ##
+ # Is this specification missing its extensions? When this returns true you
+ # probably want to build_extensions
+
+ def missing_extensions?
+ return false if default_gem?
+ return false if extensions.empty?
+ return false if installed_by_version < Gem::Version.new('2.2.0.preview.2')
+ return false if File.exist? gem_build_complete_path
+
+ true
+ end
+
##
# Normalize the list of files so that:
# * All file lists have redundancies removed.
@@ -120,6 +120,13 @@ def full_require_paths
super
end
+ def missing_extensions?
+ return false if default_gem?
+ return false if extensions.empty?
+
+ to_spec.missing_extensions?
+ end
+
##
# Name of the gem
@@ -2878,6 +2878,52 @@ def test_metadata_specs
assert_equal @m1.to_ruby, valid_ruby_spec
end
+ def test_missing_extensions_eh
+ ext_spec
+
+ assert @ext.missing_extensions?
+
+ 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 clean"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+
+ @ext.build_extensions
+
+ refute @ext.missing_extensions?
+ end
+
+ def test_missing_extensions_eh_default_gem
+ spec = new_default_spec 'default', 1
+ spec.extensions << 'extconf.rb'
+
+ refute spec.missing_extensions?
+ end
+
+ def test_missing_extensions_eh_legacy
+ ext_spec
+
+ @ext.installed_by_version = v '2.2.0.preview.2'
+
+ assert @ext.missing_extensions?
+
+ @ext.installed_by_version = v '2.2.0.preview.1'
+
+ refute @ext.missing_extensions?
+ end
+
+ def test_missing_extensions_eh_none
+ refute @a1.missing_extensions?
+ end
+
def test_find_by_name
util_make_gems
assert(Gem::Specification.find_by_name("a"))
@@ -85,6 +85,46 @@ def test_full_require_paths
assert_equal expected, stub.full_require_paths
end
+ def test_missing_extensions_eh
+ stub = 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 clean"
+ f.puts "default:\n\techo built"
+ f.puts "install:\n\techo installed"
+ end
+ RUBY
+ end
+ end
+
+ assert stub.missing_extensions?
+
+ stub.build_extensions
+
+ refute stub.missing_extensions?
+ end
+
+ def test_missing_extensions_eh_default_gem
+ spec = new_default_spec 'default', 1
+ spec.extensions << 'extconf.rb'
+
+ open spec.loaded_from, 'w' do |io|
+ io.write spec.to_ruby_for_cache
+ end
+
+ default_spec = Gem::StubSpecification.new spec.loaded_from
+
+ refute default_spec.missing_extensions?
+ end
+
+ def test_missing_extensions_eh_none
+ refute @foo.missing_extensions?
+ end
+
def test_to_spec
assert @foo.to_spec.is_a?(Gem::Specification)
assert_equal "foo", @foo.to_spec.name

0 comments on commit 6062fbc

Please sign in to comment.