2018-06-15 19:02:44 +02:00
|
|
|
<%
|
|
|
|
|
|
|
|
begin
|
|
|
|
require 'rbconfigpackagingsupport'
|
|
|
|
rescue LoadError => ex
|
|
|
|
end
|
|
|
|
def self.patch_mod_full_name(path, mod_full_name)
|
|
|
|
path.gsub(/\/-/, "/#{mod_full_name}")
|
|
|
|
end
|
2021-01-26 15:22:17 +01:00
|
|
|
|
2018-06-15 19:02:44 +02:00
|
|
|
def self.patch_libdir(path)
|
|
|
|
# path ? path.gsub(/\/usr\/lib(64)?/, '%{_libdir}') : path
|
|
|
|
path
|
|
|
|
end
|
|
|
|
|
2023-11-13 21:56:58 +01:00
|
|
|
def self.rpm_jemalloc_prefix
|
|
|
|
jemalloc_prefix = nil
|
|
|
|
|
|
|
|
package_name = RbConfig::CONFIG['RUBY_SO_NAME']
|
|
|
|
|
|
|
|
IO.popen("rpm -q --provides #{package_name}") {|rpm_io|
|
|
|
|
rpm_provides = rpm_io.read
|
|
|
|
mo = /(?<jemalloc_prefix>with(out)?-jemalloc)/.match(rpm_provides)
|
|
|
|
|
|
|
|
if mo
|
|
|
|
jemalloc_prefix = mo[:jemalloc_prefix]
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
jemalloc_prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.jemalloc_requires
|
|
|
|
jemalloc_prefix = rpm_jemalloc_prefix
|
|
|
|
|
|
|
|
if jemalloc_prefix
|
|
|
|
return "Requires: #{RbConfig::CONFIG['RUBY_SO_NAME']}-#{jemalloc_prefix} >= #{RbConfig::CONFIG['RUBY_PROGRAM_VERSION']}"
|
|
|
|
end
|
|
|
|
#
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
|
2018-06-15 19:02:44 +02:00
|
|
|
def self.get_extension_doc_dir(gem_spec)
|
|
|
|
return nil unless Gem.ruby_engine == 'ruby' && Gem::Requirement.new("~> 2.1.0").satisfied_by?(Gem.ruby_version)
|
|
|
|
if gem_spec.respond_to?(:extensions_dir)
|
|
|
|
rp = gem_spec.extensions_dir.rpartition(gem_spec.base_dir)
|
2021-01-26 15:22:17 +01:00
|
|
|
return File.join(rp[1], 'doc', rp[2])
|
2018-06-15 19:02:44 +02:00
|
|
|
end
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.get_mod_weight(spec)
|
|
|
|
versions=spec.version.to_s.split('.')
|
|
|
|
begin v1=Integer(versions[0]) rescue v1=1 end
|
|
|
|
begin v2=Integer(versions[1]) rescue v2=0 end
|
2021-01-26 15:22:17 +01:00
|
|
|
begin v3=Integer(versions[2]) rescue v3=0 end
|
2018-06-15 19:02:44 +02:00
|
|
|
weight=v1*10000+v2*100+v3
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.map_executable(config, executable)
|
|
|
|
if not(config[:binary_map].nil? or
|
|
|
|
config[:binary_map][executable].nil?)
|
|
|
|
executable=config[:binary_map][executable]
|
|
|
|
end
|
|
|
|
executable
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.filecontent_or_value(path)
|
|
|
|
(path and File.exists?(path)) ? File.read(path) : path
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.parse_custom_pkgs(env_value)
|
|
|
|
custom_pkgs = {}
|
|
|
|
if env_value
|
|
|
|
list = env_value.split(/\s+/)
|
|
|
|
list.each do |element|
|
|
|
|
pkg_name,filelist_path, preamble, description = element.split(/\|/, 4)
|
|
|
|
filelist = filecontent_or_value(filelist_path)
|
|
|
|
preamble = filecontent_or_value(preamble)
|
|
|
|
description = filecontent_or_value(description)
|
|
|
|
custom_pkgs[pkg_name] = {
|
|
|
|
"filelist" => filelist,
|
|
|
|
"preamble" => preamble,
|
|
|
|
"description" => description,
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
custom_pkgs
|
|
|
|
end
|
2021-01-26 15:22:17 +01:00
|
|
|
|
2023-05-12 23:25:06 +02:00
|
|
|
def self.fix_up_rubygem_requires_with_rb_api(rb_api, preamble_text)
|
|
|
|
STDERR.puts(preamble_text)
|
|
|
|
preamble_text.lines.map do |line|
|
|
|
|
if mo = /^(?<pre_text>\s*\S+\s*:\s+rubygem\()(?<pkg_info>[^\)]+)(?<post_text>\).*)?$/.match(line)
|
|
|
|
if not(mo[:pkg_info] =~ /^ruby:\d\.\d\.\d/)
|
|
|
|
line = "#{mo[:pre_text]}#{rb_api}:#{mo[:pkg_info]}#{mo[:post_text]}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
line
|
|
|
|
end.join("\n")
|
|
|
|
end
|
|
|
|
|
|
|
|
rb_api = "#{RUBY_ENGINE}:#{RbConfig::CONFIG['ruby_version']}"
|
|
|
|
|
|
|
|
rb_pkg_abi = "#{rb_api}:#{spec.name}"
|
2021-01-26 15:22:17 +01:00
|
|
|
|
2018-06-15 19:02:44 +02:00
|
|
|
rb_suffix = RbConfig::CONFIG['ruby_install_name'].gsub(/^ruby/, '')
|
|
|
|
rb_pkgname = RbConfig::CONFIG['ruby_install_name'].gsub(/^ruby\./, '')
|
|
|
|
if rb_suffix =~ /\A\d+\.\d+\z/
|
|
|
|
rb_suffix = '.ruby' + rb_suffix
|
|
|
|
end
|
|
|
|
pkg_basename = rb_pkgname + '-rubygem-' + spec.name
|
|
|
|
|
|
|
|
mod_full_name = "#{spec.name}-#{spec.version}"
|
2021-01-26 15:22:17 +01:00
|
|
|
mod_weight = get_mod_weight(spec)
|
2018-06-15 19:02:44 +02:00
|
|
|
|
|
|
|
gem_platform = Gem::Platform.new(RbConfig::CONFIG["arch"]).to_s
|
|
|
|
rb_bindir = RbConfig::CONFIG['bindir']
|
|
|
|
rb_sysconfdir = RbConfig::CONFIG['sysconfdir']
|
|
|
|
docdir = '/usr/share/doc/packages'
|
|
|
|
gem_spec = Gem::Specification.new
|
|
|
|
gem_base_dir = patch_libdir(gem_spec.base_dir)
|
|
|
|
gem_cache_dir = patch_libdir(gem_spec.cache_dir)
|
2021-01-26 15:22:17 +01:00
|
|
|
gem_build_info_dir = patch_libdir(gem_spec.build_info_dir)
|
2018-06-15 19:02:44 +02:00
|
|
|
gem_gems_dir = patch_libdir(gem_spec.gems_dir)
|
|
|
|
gem_spec_dir = patch_libdir(gem_spec.spec_dir)
|
|
|
|
gem_bin_dir = patch_libdir(patch_mod_full_name(gem_spec.bin_dir , mod_full_name ))
|
|
|
|
gem_doc_dir = patch_libdir(patch_mod_full_name(gem_spec.doc_dir, mod_full_name ))
|
|
|
|
gem_gem_dir = patch_libdir(patch_mod_full_name(gem_spec.gem_dir, mod_full_name ))
|
|
|
|
gem_ri_dir = patch_libdir(patch_mod_full_name(gem_spec.ri_dir, mod_full_name ))
|
|
|
|
#ruby2.1
|
|
|
|
gem_extensions_dir = gem_spec.respond_to?(:extensions_dir) ? patch_libdir(gem_spec.extensions_dir) : nil
|
|
|
|
gem_extension_dir = gem_spec.respond_to?(:extension_dir) ? patch_libdir(patch_mod_full_name(gem_spec.extension_dir, mod_full_name)) : nil
|
|
|
|
gem_extension_doc = patch_libdir(get_extension_doc_dir(gem_spec))
|
|
|
|
#/ruby2.1
|
2021-01-26 15:22:17 +01:00
|
|
|
gem_plugins_dir = Gem.respond_to?(:plugindir) ? Gem.plugindir : nil
|
|
|
|
has_plugins = gem_plugins_dir && not( spec.files.select {|filename| filename =~ /rubygems_plugin#{Gem.suffix_regexp}\z/ }.empty? )
|
|
|
|
if config[:disable_docs].nil?
|
|
|
|
config[:disable_docs] ||= true
|
|
|
|
end
|
|
|
|
if config[:include_testsuite].nil?
|
|
|
|
config[:include_testsuite] ||= false
|
|
|
|
end
|
2018-06-15 19:02:44 +02:00
|
|
|
%>
|
|
|
|
%package -n <%= pkg_basename %><%= config[:version_suffix] %>
|
|
|
|
# MANUAL
|
|
|
|
<% if config[:main] && config[:main][:preamble] -%>
|
2023-05-12 23:25:06 +02:00
|
|
|
<%= fix_up_rubygem_requires_with_rb_api(rb_api, config[:main][:preamble]) %>
|
2018-06-15 19:02:44 +02:00
|
|
|
<% end -%>
|
|
|
|
# /MANUAL
|
2023-11-13 21:56:58 +01:00
|
|
|
<% unless spec.extensions.empty? -%>
|
|
|
|
<%= jemalloc_requires %>
|
|
|
|
<% end -%>
|
2018-06-15 19:02:44 +02:00
|
|
|
Summary: <%= config[:summary] or spec.summary %>
|
|
|
|
Group: Development/Languages/Ruby
|
|
|
|
<% unless spec.executables.empty? -%>
|
|
|
|
PreReq: update-alternatives
|
|
|
|
<% end -%>
|
2021-01-26 15:22:17 +01:00
|
|
|
<% if has_plugins -%>
|
|
|
|
Conflicts: rubygem(<%= rb_pkg_abi %>)
|
|
|
|
<% end -%>
|
2018-06-15 19:02:44 +02:00
|
|
|
Enhances: <%= rb_pkgname %>
|
|
|
|
|
|
|
|
%description -n <%= pkg_basename %><%= config[:version_suffix] %>
|
|
|
|
<%= config[:description] or spec.description -%>
|
|
|
|
|
2021-01-26 15:22:17 +01:00
|
|
|
<% if spec.has_rdoc? && !(config[:disable_docs]) -%>
|
2018-06-15 19:02:44 +02:00
|
|
|
%package -n <%= pkg_basename %>-doc<%= config[:version_suffix] %>
|
|
|
|
Summary: RDoc documentation for <%= spec.name %>
|
|
|
|
Group: Development/Languages/Ruby
|
|
|
|
Requires: <%= pkg_basename %><%= config[:version_suffix] %> = <%= spec.version %>
|
|
|
|
|
|
|
|
%description -n <%= pkg_basename %>-doc<%= config[:version_suffix] %>
|
|
|
|
Documentation generated at gem installation time.
|
|
|
|
Usually in RDoc and RI formats.
|
|
|
|
|
|
|
|
<% end -%>
|
|
|
|
<% test_frameworks = Hash.new
|
|
|
|
docdirfiles = []
|
|
|
|
format.file_entries.each do |entry|
|
|
|
|
# new rubygems version has it different
|
|
|
|
if entry.kind_of?(Array)
|
|
|
|
path=entry[0]['path']
|
|
|
|
else
|
|
|
|
path=entry
|
|
|
|
end
|
|
|
|
path.gsub!(%r{^\./}, '')
|
|
|
|
%w(test spec).each { |framework|
|
|
|
|
test_frameworks[framework] = 1 if path.index(framework + "/") == 0
|
|
|
|
}
|
|
|
|
%w(changes
|
|
|
|
copying
|
|
|
|
history
|
|
|
|
legal
|
|
|
|
licence
|
|
|
|
license
|
|
|
|
license-mit
|
|
|
|
mit-license
|
|
|
|
changelog
|
|
|
|
news
|
|
|
|
release_notes
|
|
|
|
readme
|
|
|
|
).each { |file|
|
|
|
|
bpath = path.downcase.gsub(%r{\.rdoc$}, '').gsub(%r{\.txt$}, '').gsub(%r{\.md$}, '').gsub(%r{\.markdown$}, '')
|
|
|
|
#$stderr.puts "PATH #{path} #{bpath} #{file}"
|
|
|
|
docdirfiles << path if bpath == file
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test_frameworks = test_frameworks.keys.sort
|
|
|
|
-%>
|
|
|
|
<% unless test_frameworks.empty? -%>
|
|
|
|
%package -n <%= pkg_basename %>-testsuite<%= config[:version_suffix] %>
|
|
|
|
Summary: Test suite for <%= spec.name %>
|
|
|
|
Group: Development/Languages/Ruby
|
|
|
|
Requires: <%= pkg_basename %><%= config[:version_suffix] %> = <%= spec.version %>
|
|
|
|
|
|
|
|
%description -n <%= pkg_basename %>-testsuite<%= config[:version_suffix] %>
|
|
|
|
Test::Unit or RSpec files, useful for developers.
|
|
|
|
|
|
|
|
<% end -%>
|
|
|
|
|
|
|
|
<% unless spec.executables.empty? -%>
|
|
|
|
%post -n <%= pkg_basename %><%= config[:version_suffix] %>
|
|
|
|
<% spec.executables.each do |executable| -%>
|
|
|
|
/usr/sbin/update-alternatives --install \
|
|
|
|
<%= rb_bindir %>/<%= map_executable(config, executable) %> <%= map_executable(config, executable) %> <%= rb_bindir %>/<%= "#{executable}#{rb_suffix}-#{spec.version}" %> <%= mod_weight %>
|
|
|
|
/usr/sbin/update-alternatives --install \
|
|
|
|
<%= rb_bindir %>/<%= "#{executable}-#{spec.version}" %> <%= "#{executable}-#{spec.version}" %> <%= rb_bindir %>/<%= "#{executable}#{rb_suffix}-#{spec.version}" %> <%= mod_weight %>
|
|
|
|
/usr/sbin/update-alternatives --install \
|
|
|
|
<%= rb_bindir %>/<%= "#{executable}#{rb_suffix}" %> <%= "#{executable}#{rb_suffix}" %> <%= rb_bindir %>/<%= "#{executable}#{rb_suffix}-#{spec.version}" %> <%= mod_weight %>
|
|
|
|
<% end -%>
|
|
|
|
|
|
|
|
%preun -n <%= pkg_basename %><%= config[:version_suffix] %>
|
|
|
|
if [ "$1" = 0 ] ; then
|
|
|
|
<% spec.executables.each do |executable| -%>
|
|
|
|
/usr/sbin/update-alternatives --remove <%= map_executable(config, executable) %> <%= rb_bindir %>/<%= "#{executable}#{rb_suffix}-#{spec.version}" %>
|
|
|
|
/usr/sbin/update-alternatives --remove <%= "#{executable}-#{spec.version}" %> <%= rb_bindir %>/<%= "#{executable}#{rb_suffix}-#{spec.version}" %>
|
|
|
|
/usr/sbin/update-alternatives --remove <%= "#{executable}#{rb_suffix}" %> <%= rb_bindir %>/<%= "#{executable}#{rb_suffix}-#{spec.version}" %>
|
|
|
|
<% end -%>
|
|
|
|
fi
|
|
|
|
<% end -%>
|
|
|
|
|
|
|
|
%files -n <%= pkg_basename %><%= config[:version_suffix] %>
|
|
|
|
%defattr(-,root,root,-)
|
|
|
|
# MANUAL
|
|
|
|
<% if config[:main] && config[:main][:filelist] -%>
|
|
|
|
<%= config[:main][:filelist] -%>
|
|
|
|
<% end -%>
|
|
|
|
# /MANUAL
|
|
|
|
<% unless docdirfiles.empty? -%>
|
|
|
|
<%= docdir %>/<%= pkg_basename %><%= config[:version_suffix] %>
|
|
|
|
<% end -%>
|
|
|
|
<% spec.executables.each do |executable| -%>
|
|
|
|
<%= rb_bindir %>/<%= "#{executable}#{rb_suffix}-#{spec.version}" %>
|
|
|
|
<%= rb_bindir %>/<%= "#{executable}#{rb_suffix}" %>
|
|
|
|
<%= rb_bindir %>/<%= "#{executable}-#{spec.version}" %>
|
|
|
|
<%= rb_bindir %>/<%= map_executable(config, executable) %>
|
|
|
|
%ghost <%= rb_sysconfdir %>/alternatives/<%= map_executable(config, executable) %>
|
|
|
|
%ghost <%= rb_sysconfdir %>/alternatives/<%= "#{executable}#{rb_suffix}" %>
|
|
|
|
%ghost <%= rb_sysconfdir %>/alternatives/<%= "#{executable}-#{spec.version}" %>
|
|
|
|
<% end -%>
|
|
|
|
# cache file
|
|
|
|
<%= gem_cache_dir %>/<%= mod_full_name %>.gem
|
|
|
|
<%= gem_gem_dir %>
|
2021-01-26 15:22:17 +01:00
|
|
|
<% if has_plugins -%>
|
|
|
|
<%= gem_plugins_dir %>
|
|
|
|
<% end -%>
|
|
|
|
<%= gem_build_info_dir %>
|
2018-06-15 19:02:44 +02:00
|
|
|
<% unless spec.extensions.empty? or gem_extension_dir.nil? -%>
|
|
|
|
<%= gem_extension_dir %>
|
|
|
|
<% end -%>
|
|
|
|
<% test_frameworks.each do |framework| -%>
|
|
|
|
%exclude <%= File.join gem_gem_dir, framework %>
|
|
|
|
<% end -%>
|
|
|
|
<%= gem_spec_dir %>/<%= mod_full_name -%>.gemspec
|
|
|
|
|
2021-01-26 15:22:17 +01:00
|
|
|
<% if spec.has_rdoc? && !(config[:disable_docs]) -%>
|
2018-06-15 19:02:44 +02:00
|
|
|
%files -n <%= pkg_basename %>-doc<%= config[:version_suffix] %>
|
|
|
|
%defattr(-,root,root,-)
|
|
|
|
%doc <%= gem_doc_dir %>
|
|
|
|
<% unless spec.extensions.empty? or gem_extension_doc.nil? -%>
|
|
|
|
%doc <%= gem_extension_doc %>
|
|
|
|
<% end -%>
|
|
|
|
<% end -%>
|
|
|
|
|
2021-01-26 15:22:17 +01:00
|
|
|
<% if config[:include_testsuite] and !test_frameworks.empty? -%>
|
2018-06-15 19:02:44 +02:00
|
|
|
%files -n <%= pkg_basename %>-testsuite<%= config[:version_suffix] %>
|
|
|
|
%defattr(-,root,root,-)
|
|
|
|
<% test_frameworks.each do |framework| -%>
|
|
|
|
<%= File.join gem_gem_dir, framework %>
|
|
|
|
<% end -%>
|
|
|
|
<% end -%>
|
|
|
|
<%
|
|
|
|
if config[:custom_pkgs_ruby_versioned]
|
|
|
|
config[:custom_pkgs_ruby_versioned].each do |custom_pkg_name, data|
|
2021-01-26 15:22:17 +01:00
|
|
|
-%>
|
2018-06-15 19:02:44 +02:00
|
|
|
%package -n <%= pkg_basename %>-<%= custom_pkg_name %><%= config[:version_suffix] %>
|
|
|
|
<% if data[:preamble] and data[:preamble] != '' -%>
|
|
|
|
<%= data[:preamble] %>
|
|
|
|
<% else %>
|
|
|
|
Summary: <%= custom_pkg_name %> sub package for <%= spec.name %>
|
|
|
|
Group: Development/Languages/Ruby
|
|
|
|
<% end %>
|
|
|
|
Requires: <%= pkg_basename %><%= config[:version_suffix] %> = <%= spec.version %>
|
|
|
|
%description -n <%= pkg_basename %>-<%= custom_pkg_name %><%= config[:version_suffix] %>
|
|
|
|
<% if data[:description] and data[:description] != '' -%>
|
|
|
|
<%= data[:description] %>
|
|
|
|
<% else %>
|
|
|
|
<%= spec.description -%>
|
|
|
|
|
|
|
|
This package holds the <%= custom_pkg_name %> sub package for <%= spec.name -%>
|
|
|
|
<% end %>
|
|
|
|
%files -n <%= pkg_basename %>-<%= custom_pkg_name %><%= config[:version_suffix] %>
|
|
|
|
%defattr(-,root,root,-)
|
|
|
|
<%= data['filelist'] -%>
|
|
|
|
<%
|
|
|
|
end
|
|
|
|
end
|
|
|
|
-%>
|