Skip to content

Instantly share code, notes, and snippets.

@chetan
Created December 18, 2012 00:00
Show Gist options
  • Save chetan/4323573 to your computer and use it in GitHub Desktop.
Save chetan/4323573 to your computer and use it in GitHub Desktop.
List gems which use a C extension
#!/usr/bin/env ruby
# list all gems in your Gemfile which have a C extension
require 'bundler'
gemfile = []
File.new("Gemfile").readlines.each do |line|
next if line =~ /^\s*#/
if line =~ /gem\s+['"](.*?)['"]/ then
gemfile << $1
end
end
b = Bundler.setup(:default)
gems = b.requested_specs.to_a
direct = []
indirect = []
gems.each do |g|
if File.directory? File.join(g.full_gem_path, "ext") then
if gemfile.include?(g.name) then
next if g.name == "facter" # doesn't actually use an ext
direct << g.name
else
indirect << g.name
end
end
end
puts "gems requiring an ext:"
puts "----------------------"
direct.each{ |g| puts g }
puts
puts "gems requiring an ext (not in gemfile):"
puts "---------------------------------------"
indirect.each{ |g| puts g }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment