From: Marcin Krol Date: Fri, 23 Feb 2018 09:12:24 +0000 (+0000) Subject: - backported rubyprov package from PLD rpm 5.x X-Git-Url: https://git.tld-linux.org/?a=commitdiff_plain;h=506d43e50fa9d65fb66418f89cb81349b9da98a1;p=packages%2Frpm.git - backported rubyprov package from PLD rpm 5.x --- diff --git a/gem_helper.rb b/gem_helper.rb new file mode 100755 index 0000000..11de3be --- /dev/null +++ b/gem_helper.rb @@ -0,0 +1,197 @@ +#!/usr/bin/env ruby +#-- +# Copyright 2010 Per Øyvind Karlsen +# This program is free software. It may be redistributed and/or modified under +# the terms of the LGPL version 2.1 (or later). +#++ + +require 'optparse' +require 'rubygems' + +# Write the .gemspec specification (in Ruby) +def writespec(spec) + file_name = spec.full_name.untaint + '.gemspec' + File.open(file_name, "w") do |file| + file.puts spec.to_ruby_for_cache + end + print "Wrote: %s\n" % file_name +end + +# make gemspec self-contained +if ARGV[0] == "spec-dump" + spec = eval(File.read(ARGV[1])) + writespec(spec) + exit(0) +end + +if ARGV[0] == "build" or ARGV[0] == "install" or ARGV[0] == "spec" + require 'yaml' + require 'zlib' + + filter = nil + opts = nil + keepcache = false + fixperms = false + gemdir = nil + dry_run = false + files = [] + argv = ARGV[1..-1] + # Push this into some environment variables as the modified classes doesn't + # seem to be able to access our global variables.. + ENV['GEM_MODE'] = ARGV[0] + if ARGV[0] == "build" + opts = OptionParser.new("#{$0} <--filter PATTERN>") + opts.on("-f", "--filter PATTERN", "Filter pattern to use for gem files") do |val| + filter = val + end + opts.on("-j", "--jobs JOBS", "Number of jobs to run simultaneously.") do |val| + ENV['jobs'] = "-j"+val + end + opts.on("--dry-run", "Only show the files the gem will include") do + ARGV.delete("--dry-run") + dry_run = true + end + elsif ARGV[0] == "install" + opts = OptionParser.new("#{$0} <--keep-cache>") + opts.on("--keep-cache", "Don't delete gem copy from cache") do + ARGV.delete("--keep-cache") + keepcache = true + end + opts.on("--fix-permissions", "Force standard permissions for files installed") do + ARGV.delete("--fix-permissions") + fixperms = true + end + opts.on("-i", "--install-dir GEMDIR", "Gem repository directory") do |val| + gemdir = val + end + end + while argv.length > 0 + begin + opts.parse!(argv) + rescue OptionParser::InvalidOption => e + e.recover(argv) + end + argv.delete_at(0) + end + + file_data = Zlib::GzipReader.open("metadata.gz") {|io| io.read} + header = YAML::load(file_data) + body = {} + # I don't know any better.. :/ + header.instance_variables.each do |iv| + body[iv.to_s.sub(/^@/,'')] = header.instance_variable_get(iv) + end + + spec = Gem::Specification.from_yaml(YAML.dump(header)) + + if ARGV[0] == "spec" + writespec(spec) + exit(0) + end + + if ARGV[0] == "install" + system("gem %s %s.gem" % [ARGV.join(' '), spec.full_name]) + if !keepcache + require 'fileutils' + FileUtils.rm_rf("%s/cache" % gemdir) + end + if fixperms + chmod = "chmod u+r,u+w,g-w,g+r,o+r -R %s" % gemdir + print "\nFixing permissions:\n\n%s\n" % chmod + system("%s" % chmod) + print "\n" + end + end + + if body['extensions'].size > 0 + require 'rubygems/ext' + module Gem::Ext + class Builder + def self.make(dest_path, results) + make_program = ENV['make'] + unless make_program then + make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make' + end + cmd = make_program + if ENV['GEM_MODE'] == "build" + cmd += " %s" % ENV['jobs'] + elsif ENV['GEM_MODE'] == "install" + cmd += " DESTDIR='%s' install" % ENV['DESTDIR'] + end + results << cmd + results << `#{cmd} #{redirector}` + + raise Gem::ExtensionBuildError, "make failed:\n\n#{results}" unless + $?.success? + end + end + end + + require 'rubygems/installer' + module Gem + class Installer + def initialize(spec, options={}) + @gem_dir = Dir.pwd + @spec = spec + end + end + class ConfigFile + def really_verbose + true + end + end + end + + unless dry_run + Gem::Installer.new(spec).build_extensions + else + for ext in body['extensions'] + files.push(ext[0..ext.rindex("/")-1]+".so") + end + end + + body['extensions'].clear() + end + if ARGV[0] == "build" + body['test_files'].clear() + + # We don't want ext/ in require_paths, it will only contain content for + # building extensions which needs to be installed in sitearchdir anyways.. + idx = 0 + for i in 0..body['require_paths'].size()-1 + if body['require_paths'][idx].match("^ext(/|$)") + body['require_paths'].delete_at(idx) + else + idx += 1 + end + end + + # We'll get rid of all the files we don't really need to install + idx = 0 + for i in 0..body['files'].size()-1 + if filter and body['files'][idx].match(filter) + match = true + else + match = false + for path in body['require_paths'] + if body['files'][idx].match("^%s/" % path) + match = true + end + end + end + if !match + body['files'].delete_at(idx) + else + idx += 1 + end + end + + spec = Gem::Specification.from_yaml(YAML.dump(header)) + unless dry_run + Gem::Builder.new(spec).build + else + files.concat(spec.files) + print "%s\n" % files.join("\n") + end + end +end diff --git a/rpm-rubyprov.patch b/rpm-rubyprov.patch new file mode 100644 index 0000000..15a867e --- /dev/null +++ b/rpm-rubyprov.patch @@ -0,0 +1,87 @@ +diff -urpa rpm-4.5.orig/configure.ac rpm-4.5/configure.ac +--- rpm-4.5.orig/configure.ac 2011-10-03 01:50:17.000000000 +0000 ++++ rpm-4.5/configure.ac 2018-02-22 12:42:35.749384821 +0000 +@@ -291,6 +291,7 @@ AC_PATH_PROG(__PHP, php, %{_bindir}/php, + AC_PATH_PROG(__PYTHON, python, %{_bindir}/python, $MYPATH) + AC_PATH_PROG(__RM, rm, /bin/rm, $MYPATH) + AC_PATH_PROG(__RSH, rsh, %{_bindir}/rsh, $MYPATH) ++AC_PATH_PROG(__RUBY, ruby, %{_bindir}/ruby, $MYPATH) + AC_PATH_PROG(__SED, sed, /bin/sed, $MYPATH) + AC_PATH_PROG(__SH, sh, /bin/sh, $MYPATH) + AC_PATH_PROG(__SSH, ssh, %{_bindir}/ssh, $MYPATH) +diff -urpa rpm-4.5.orig/macros.in rpm-4.5/macros.in +--- rpm-4.5.orig/macros.in 2008-06-10 22:00:43.000000000 +0000 ++++ rpm-4.5/macros.in 2018-02-22 13:53:01.843337239 +0000 +@@ -78,6 +78,7 @@ + %__python @__PYTHON@ + %__rm @__RM@ + %__rsh @__RSH@ ++%__ruby @__RUBY@ + %__sed @__SED@ + %__sh @__SH@ + %__ssh @__SSH@ +@@ -1421,6 +1422,44 @@ PreReq: python >= %{python_version}, pyt + #%__java_requires %{_rpmhome}/javadeps.sh --requires + + #------------------------------------------------------------------------ ++# ruby(...) configuration. ++# ++# Path to scripts to autogenerate ruby package dependencies, ++ ++# Note: Used if _use_internal_dependency_generator is non-zero. The ++# helpers are also used by %{_rpmhome}/rpmdeps {--provides|--requires}. ++%__ruby_provides %{_rpmhome}/rubygems.rb --provides ++%__ruby_requires %{_rpmhome}/rubygems.rb --requires ++ ++%ruby_version %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["ruby_version"]') ++ ++%ruby_archdir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["archdir"]') ++%ruby_libdir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["rubylibdir"]') ++%ruby_sitedir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["sitedir"]') ++%ruby_sitearchdir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["sitearchdir"]') ++%ruby_sitelibdir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["sitelibdir"]') ++%ruby_vendordir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["vendordir"]') ++%ruby_vendorarchdir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["vendorarchdir"]') ++%ruby_vendorlibdir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["vendorlibdir"]') ++%ruby_gemdir %(%{__ruby} -rrbconfig -e 'print RbConfig::CONFIG["rubylibdir"].sub(RbConfig::CONFIG["ruby_version"], "gems/#{RbConfig::CONFIG["ruby_version"]}")') ++%ruby_ridir %(%{__ruby} -rrbconfig -e 'print File.join(RbConfig::CONFIG["datadir"], "ri", RbConfig::CONFIG["ruby_version"])') ++ ++%__gem_helper %{_usrlibrpm}/gem_helper.rb ++ ++%gem_build(f:j:) \ ++ %__gem_helper build \\\ ++ %{-f:-f%{-f*}} \\\ ++ %{!-j:%{_smp_mflags}}%{-j:-j%{-j*}} ++ ++%gem_install(i:n:C) \ ++ DESTDIR=${DESTDIR:-%{buildroot}} \\\ ++ %__gem_helper install \\\ ++ --env-shebang --rdoc --ri --force --ignore-dependencies \\\ ++ %{!-i:--install-dir %{buildroot}%{ruby_gemdir}}%{-i:--install-dir %{-i*}} \\\ ++ %{!-n:--bindir %{buildroot}%{_bindir}}%{-n:--bindir%{-n*}} \\\ ++ %{!-C:--fix-permissions} ++ ++#------------------------------------------------------------------------ + # libtool(...) configuration. + # + # Path to scripts to autogenerate libtool package dependencies, +diff -urpa rpm-4.5.orig/scripts/Makefile.am rpm-4.5/scripts/Makefile.am +--- rpm-4.5.orig/scripts/Makefile.am 2008-05-21 20:48:02.000000000 +0000 ++++ rpm-4.5/scripts/Makefile.am 2018-02-22 13:55:18.773335698 +0000 +@@ -19,7 +19,8 @@ EXTRA_DIST = \ + sql.prov sql.req symclash.py symclash.sh tcl.req tgpg trpm u_pkg.sh \ + vpkg-provides.sh vpkg-provides2.sh \ + macros.perl* macros.python* \ +- macros.php* find-*.php find-php-* ++ macros.php* find-*.php find-php-* \ ++ gem_helper.rb rubygems.rb + + installprefix = $(DESTDIR) + +@@ -43,4 +44,5 @@ versionlib_SCRIPTS = \ + rpmdb_loadcvt \ + rpm.daily rpm.log rpm.xinetd \ + symclash.py symclash.sh tgpg u_pkg.sh \ +- vpkg-provides.sh vpkg-provides2.sh ++ vpkg-provides.sh vpkg-provides2.sh \ ++ gem_helper.rb rubygems.rb diff --git a/rpm.spec b/rpm.spec index 0ba234f..edfc4e6 100644 --- a/rpm.spec +++ b/rpm.spec @@ -42,7 +42,7 @@ Summary(ru.UTF-8): Менеджер пакетов от RPM Summary(uk.UTF-8): Менеджер пакетів від RPM Name: rpm Version: 4.5 -Release: 80.1 +Release: 81 License: LGPL Group: Base Source0: %{name}-%{version}.tar.gz @@ -67,6 +67,8 @@ Source18: banner.sh Source19: %{name}-macros.gstreamer Source20: macros.php Source21: %{name}-php-requires.php +Source22: rubygems.rb +Source23: gem_helper.rb Patch1000: %{name}-new-debuginfo.patch #Patch0: %{name}-pl.po.patch Patch1: %{name}-rpmrc.patch @@ -169,7 +171,8 @@ Patch108: %{name}-changelog_order_check_nonfatal.patch Patch109: %{name}-installplatform.patch Patch110: %{name}-xz.patch Patch111: %{name}-shrink.patch -Patch112: notrans.patch +Patch112: %{name}-rubyprov.patch +Patch113: notrans.patch URL: http://rpm5.org/ BuildRequires: autoconf >= 2.57 BuildRequires: automake >= 1.4 @@ -634,6 +637,23 @@ packages. Dodatkowe narzędzia do sprawdzenia zależności skryptów PHP PEAR w pakietach RPM. +%package rubyprov +Summary: Ruby tools, which simplify creation of RPM packages with Ruby software +Summary(pl.UTF-8): Makra ułatwiające tworzenie pakietów RPM z programami napisanymi w Ruby +Group: Applications/File +Requires: %{name} = %{version}-%{release} +Requires: ruby +Requires: ruby-modules +Requires: ruby-rubygems + +%description rubyprov +Ruby tools, which simplifies creation of RPM packages with Ruby +software. + +%description rubyprov -l pl.UTF-8 +Makra ułatwiające tworzenie pakietów RPM z programami napisanymi w +Ruby. + %package -n python-rpm Summary: Python interface to RPM library Summary(pl.UTF-8): Pythonowy interfejs do biblioteki RPM-a @@ -792,6 +812,7 @@ install %{SOURCE13} scripts/perl.prov %patch110 -p1 %patch111 -p1 %patch112 -p1 +%patch113 -p1 mv -f po/{sr,sr@Latn}.po rm -rf sqlite zlib popt @@ -807,6 +828,9 @@ sed -i -e 's,AM_PTHREADS_SHARED("POSIX/.*,:,' db/dist/aclocal/mutex.ac rm -rf db3 db rpmdb/db.h %endif +cp -p %{SOURCE22} scripts/rubygems.rb +cp -p %{SOURCE23} scripts/gem_helper.rb + # generate Group translations to *.po awk -f %{SOURCE6} %{SOURCE1} @@ -1427,6 +1451,11 @@ find %{_rpmlibdir} -name '*-linux' -type l | xargs rm -f %defattr(644,root,root,755) %attr(755,root,root) %{_rpmlibdir}/php* +%files rubyprov +%defattr(644,root,root,755) +%attr(755,root,root) %{_rpmlibdir}/gem_helper.rb +%attr(755,root,root) %{_rpmlibdir}/rubygems.rb + %if %{with python} %files -n python-rpm %defattr(644,root,root,755) diff --git a/rubygems.rb b/rubygems.rb new file mode 100755 index 0000000..a3f63aa --- /dev/null +++ b/rubygems.rb @@ -0,0 +1,128 @@ +#!/usr/bin/env ruby +#-- +# Copyright 2010 Per Øyvind Karlsen +# This program is free software. It may be redistributed and/or modified under +# the terms of the LGPL version 2.1 (or later). +# +# FIXME: Someone with actual ruby skills should really clean up and sanitize +# this! fugliness obvious... +#++ + +require 'optparse' +require 'rbconfig' + +provides = false +requires = false + +opts = OptionParser.new("#{$0} <--provides|--requires>") +opts.on("-P", "--provides", "Print provides") do |val| + provides = true +end +opts.on("-R", "--requires", "Print requires") do |val| + requires= true +end + +rest = opts.permute(ARGV) + +if rest.size != 0 or (!provides and !requires) or (provides and requires) + $stderr.puts "Use either --provides OR --requires" + $stderr.puts opts + exit(1) +end + +require 'rubygems' +gem_dir = Gem.respond_to?(:default_dirs) ? Gem.default_dirs[:system][:gem_dir] : Gem.path.first +specpatt = "#{gem_dir}/specifications/.*\.gemspec$" +gems = [] +ruby_versioned = false +abi_provide = false +# as ruby_version may be empty, take version from basename of archdir +ruby_version = RbConfig::CONFIG["ruby_version"].empty? ? File.basename(RbConfig::CONFIG["archdir"]) : RbConfig::CONFIG["ruby_version"] + +for path in $stdin.readlines + # way fugly, but we make the assumption that if the package has + # this file, the package is the current ruby version, and should + # therefore provide ruby(abi) = version + if provides and path.match(RbConfig::CONFIG["archdir"] + "/rbconfig.rb") + abi_provide = true + ruby_versioned = true + elsif path.match(specpatt) + gems.push(path.chomp) + # this is quite ugly and lame, but the assumption made is that if any files + # found in any of these directories specific to this ruby version, the + # package is dependent on this specific version. + # FIXME: only supports current ruby version + elsif not ruby_versioned + if path.match(RbConfig::CONFIG["rubylibdir"]) + ruby_versioned = true + elsif path.match(RbConfig::CONFIG["archdir"]) + ruby_versioned = true + elsif path.match(RbConfig::CONFIG["sitelibdir"]) + ruby_versioned = !RbConfig::CONFIG["ruby_version"].empty? + elsif path.match(RbConfig::CONFIG["sitearchdir"]) + ruby_versioned = true + elsif path.match(RbConfig::CONFIG["vendorlibdir"]) + ruby_versioned = !RbConfig::CONFIG["ruby_version"].empty? + elsif path.match(RbConfig::CONFIG["vendorarchdir"]) + ruby_versioned = true + end + end +end + +if requires or abi_provide + abidep = "ruby(abi)" + if ruby_versioned + abidep += " = %s" % ruby_version + end + print abidep + "\n" +end + +if gems.length > 0 + require 'rubygems' + + if requires + + module Gem + class Requirement + def rpm_dependency_transform(name, version) + pessimistic = "" + if version == "> 0.0.0" or version == ">= 0" + version = "" + else + if version[0..1] == "~>" + pessimistic = "rubygem(%s) < %s\n" % [name, Gem::Version.create(version[3..-1]).bump] + version = version.gsub(/\~>/, '=>') + end + if version[0..1] == "!=" + version = version.gsub(/\!=/, '>') + end + version = version.sub(/^/, ' ') + end + version = "rubygem(%s)%s\n%s" % [name, version, pessimistic] + end + + def to_rpm(name) + result = as_list + return result.map { |version| rpm_dependency_transform(name, version) } + end + + end + end + end + + for gem in gems + data = File.read(gem) + spec = eval(data) + if provides + print "rubygem(%s) = %s\n" % [spec.name, spec.version] + end + if requires + for d in spec.dependencies + print d.requirement.to_rpm(d.name)[0] unless d.type != :runtime + end + for d in spec.required_rubygems_version.to_rpm("rubygems") + print d.gsub(/(rubygem\()|(\))/, "") + end + end + end +end