Instantly share code, notes, and snippets.

@darix /bundler-dumpdeps Secret
Last active Jan 30, 2018

Embed
What would you like to do?
#!/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

This comment has been minimized.

Owner

darix commented Nov 29, 2017

tested with discourse and redmine. even handles redmines Gemfile.local construct

@darix

This comment has been minimized.

Owner

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