Skip to content

Instantly share code, notes, and snippets.

@darix
Last active January 30, 2018 10:26
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darix/64caae88be214c3022d6a4ed22a91eb3 to your computer and use it in GitHub Desktop.
Save darix/64caae88be214c3022d6a4ed22a91eb3 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# vim: set sw=2 sts=2 et tw=80 :
require 'bundler'
def expand_pessimistic(version)
splitted = version.to_s.split('.')
sub_version = splitted.slice(0,(splitted.length-1)).join('.')
":#{sub_version} >= #{version}"
end
def rpmify(op, version)
case op
when '~>'
return expand_pessimistic(version)
when '>='
if version != Gem::Version.new(0)
return " #{op} #{version}"
end
when '!='
return " > #{version}"
when '='
return " #{op} #{version}"
else
STDERR.puts "Unknown operator '#{op}' called with version '#{version}'"
exit 1
end
end
#
# TODO: have a commaldine option to specify those.
# e.g. in mastodon you also want to skip the no_docker and heroku group
#
bad_groups = [:test, :development]
bd=Bundler::Dsl.evaluate('Gemfile', 'Gemfile.lock', {})
bd.dependencies.each do |dep|
next if (dep.groups - bad_groups).empty?
dep.requirement.requirements.each do |req|
req_str = rpmify(*req)
puts "BuildRequires: %{rubygem #{dep.name}#{req_str}}"
end
end
@darix
Copy link
Author

darix commented Nov 29, 2017

works without a gemfile.lock as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment