Accepting request 128957 from openSUSE:Tools:Unstable

- map the != operator to > - which might be wrong in 50% of all cases

- require a patched rpm in case rpm does not have magic hooks

- move the option parsing to a shell script that is able to do it
  rightly (rpm macros are just *BAD*)

- make the rubygemdeps a ruby script much more clever about gemspecs

- Another take on %gem_install, the version w/o passing parameters
  seemed to be wrong

- avoid *.gemspec, we get problems if we there are two

- remove too relaxing permissions from unpacked archive

- add a provides for ruby-macros

- Fix %gem_unpack:
  Fetch Gemspec from gem metadata for gems that don't package Gemspecs
  but generate them programatically

OBS-URL: https://build.opensuse.org/request/show/128957
OBS-URL: https://build.opensuse.org/package/show/devel:languages:ruby/ruby?expand=0&rev=42
This commit is contained in:
Stephan Kulow 2012-07-26 07:25:42 +00:00 committed by Git OBS Bridge
parent e7bd882f6d
commit 53dbe04f09
8 changed files with 192 additions and 73 deletions

45
gem_install.sh Normal file
View File

@ -0,0 +1,45 @@
#! /bin/bash
# options may be followed by one colon to indicate they have a required argument
if ! options=$(getopt -o dEf -l ignore-dependencies,force,no-rdoc,rdoc,no-ri,ri,env-shebang,no-env-shebang,default-gem:,build-root:,gem-binary: -- "$@")
then
# something went wrong, getopt will put out an error message for us
exit 1
fi
eval set -- "$options"
gem_binary=gem
defaultgem=
gemfile=
otheropts=
while [ $# -gt 0 ]
do
case $1 in
--default-gem) defaultgem=$2 ; shift;;
--gem-binary) gem_binary="$2" ; shift;;
--build-root) otheropts="$otheropts $1=$2"; shift;;
(--) ;;
(-*) otheropts="$otheropts $1";;
(*) gemfile=$1; otheropts="$otheropts $1"; break;;
esac
shift
done
if [ "x$gemfile" = "x" ] ; then
gemfile=$(find . -maxdepth 2 -type f -name "$defaultgem")
otheropts="$otheropts $gemfile"
fi
set -x
$gem_binary install --verbose --local $otheropts
if test -d $RPM_BUILD_ROOT/usr/bin; then
cd $RPM_BUILD_ROOT/usr/bin
bins=`ls -1 *1.9 2> /dev/null`
if test -n "$bins"; then
for bin in $bins; do
mv -v $bin $(echo "$bin" | sed -e 's,1.9$,,')
done
fi
fi

View File

@ -1,3 +1,52 @@
-------------------------------------------------------------------
Wed Jul 25 14:52:49 UTC 2012 - coolo@suse.com
- map the != operator to > - which might be wrong in 50% of all cases
-------------------------------------------------------------------
Wed Jul 25 14:39:43 UTC 2012 - coolo@suse.com
- require a patched rpm in case rpm does not have magic hooks
-------------------------------------------------------------------
Wed Jul 25 12:17:02 UTC 2012 - coolo@suse.com
- move the option parsing to a shell script that is able to do it
rightly (rpm macros are just *BAD*)
-------------------------------------------------------------------
Wed Jul 25 11:09:28 UTC 2012 - coolo@suse.com
- make the rubygemdeps a ruby script much more clever about gemspecs
-------------------------------------------------------------------
Wed Jul 25 08:27:38 UTC 2012 - saschpe@suse.de
- Another take on %gem_install, the version w/o passing parameters
seemed to be wrong
-------------------------------------------------------------------
Wed Jul 25 05:54:25 UTC 2012 - coolo@suse.com
- avoid *.gemspec, we get problems if we there are two
-------------------------------------------------------------------
Tue Jul 24 15:24:43 UTC 2012 - coolo@suse.com
- remove too relaxing permissions from unpacked archive
-------------------------------------------------------------------
Tue Jul 24 14:55:31 UTC 2012 - coolo@suse.com
- add a provides for ruby-macros
-------------------------------------------------------------------
Tue Jul 24 14:36:38 UTC 2012 - saschpe@suse.de
- Fix %gem_unpack:
Fetch Gemspec from gem metadata for gems that don't package Gemspecs
but generate them programatically
-------------------------------------------------------------------
Tue Jul 17 14:15:42 UTC 2012 - saschpe@suse.de

View File

@ -1,2 +1,4 @@
%gem_cleanup /usr/bin/gem_build_cleanup %{buildroot}%{_libdir}/ruby/gems/
%gem_cleanup() \
/usr/lib/rpm/gem_build_cleanup.sh %{buildroot}%{_libdir}/ruby/gems/%{rb_ver}/ \
%{nil}

View File

@ -32,20 +32,19 @@
# %gem_unpack %{SOURCE0}
# %patch1 -p1
#
%gem_unpack() \
if [ %# -eq 0 ]; then \
%{gem_binary} unpack --verbose %{SOURCE0} \
else \
%{gem_binary} unpack --verbose %1 \
fi \
cd %{mod_name}-%{version} \
%gem_unpack(s:) \
source=%{-s:%{-s*}}%{!-s:%{SOURCE0}} \
%{gem_binary} unpack --verbose $source \
cd %{mod_name}-%{version} \
chmod og-w -R . \
%{gem_binary} unpack --spec --verbose $source \
%{nil}
# %%gem_build macro ...
#
%gem_build() \
GEMSPEC_SOURCE_DIR=`find . -maxdepth 2 -type f -name "*.gemspec" | xargs dirname` \
cd $GEMSPEC_SOURCE_DIR && %{gem_binary} build --verbose *.gemspec \
GEMSPEC_SOURCE_DIR=`find . -maxdepth 2 -type f -name %{mod_name}-%{version}.gemspec | xargs dirname` \
cd $GEMSPEC_SOURCE_DIR && %{gem_binary} build --verbose %{mod_name}-%{version}.gemspec \
%{nil}
# %%gem_install macro ...
@ -53,26 +52,9 @@ cd $GEMSPEC_SOURCE_DIR && %{gem_binary} build --verbose *.gemspec \
# When invoked with a single parameter, the macro retains the old macro behavior, i.e.
# building the upstream gem directly in $RPM_BUILD_ROOT without unpacking to %{_builddir} first.
#
%gem_install() \
if [ %# -ge 1 ]; then \
%{gem_binary} install --verbose --local --build-root=%{buildroot} %* ;\
else \
GEM_FILE=`find . -maxdepth 2 -type f -name "%{mod_name}-%{version}.gem"` \
%{gem_binary} install --verbose --local --bindir %{buildroot}%{_bindir} --install-dir %{buildroot}%{_libdir}/ruby/gems/%{rb_ver} $GEM_FILE \
fi; \
if test -d $RPM_BUILD_ROOT/usr/bin; then \
cd $RPM_BUILD_ROOT/usr/bin; \
bins=`ls -1 *1.9 2> /dev/null`; \
if test -n "$bins"; then \
for bin in $bins; do \
mv -v $bin $(echo "$bin" | sed -e 's,1.9$,,'); \
done ;\
fi ;\
fi ;\
%{nil}
%gem_install /usr/lib/rpm/gem_install.sh --default-gem %{mod_name}-%{version}.gem --build-root %{buildroot} --gem-binary %{gem_binary}
%gem_cleanup() \
/usr/bin/gem_build_cleanup %{buildroot}%{_libdir}/ruby/gems/%{rb_ver}/ \
/usr/lib/rpm/gem_build_cleanup.sh %{buildroot}%{_libdir}/ruby/gems/%{rb_ver}/ \
%{nil}

View File

@ -19,15 +19,14 @@
Name: ruby
Version: 1.9.3
Release: 0
#
#
BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source0: ruby.macros
Source1: gem_build_cleanup
Source2: gemrc
Source3: ruby.common-macros
Source4: rubygems.attr
Source5: rubygemsdeps.sh
Source5: rubygemsdeps.rb
Source6: gem_install.sh
Provides: /usr/bin/ruby
Url: http://www.ruby-lang.org/
Summary: An Interpreted Object-Oriented Scripting Language
@ -36,6 +35,12 @@ Group: Development/Languages/Ruby
Requires: ruby19
Provides: rubygems = 1.8.15
Obsoletes: rubygems < 1.8.15
Provides: ruby-macros = 1
Requires: ruby-common = %{version}-%{release}
%if %suse_version < 1140
# we need a patched rpm
Requires: rpm-with-ruby-provide-hook
%endif
%description
Ruby is an interpreted scripting language for quick and easy
@ -79,6 +84,7 @@ Development files to link against Ruby.
%package common
Summary: Files needed by all ruby versions
Group: Development/Languages/Ruby
Requires: /usr/bin/getopt
%description common
Development files to link against Ruby.
@ -88,7 +94,7 @@ Development files to link against Ruby.
%build
%install
install -D -m 0755 %{S:1} $RPM_BUILD_ROOT%_bindir/gem_build_cleanup
mkdir -p $RPM_BUILD_ROOT%_bindir
for bin in erb gem irb rake rdoc ri ruby testrb; do
ln -s %_bindir/"$bin"1.9 $RPM_BUILD_ROOT%_bindir/$bin
done
@ -98,13 +104,14 @@ install -D -m 0644 %{S:0} $RPM_BUILD_ROOT/etc/rpm/macros.ruby
install -D -m 0644 %{S:3} $RPM_BUILD_ROOT/etc/rpm/macros.common-ruby
install -D -m 0644 %{S:2} $RPM_BUILD_ROOT/etc/gemrc
install -D -m 0644 %{S:4} $RPM_BUILD_ROOT/usr/lib/rpm/fileattrs/rubygems.attr
install -D -m 0755 %{S:5} $RPM_BUILD_ROOT/usr/lib/rpm/rubygemsdeps.sh
install -D -m 0755 %{S:5} $RPM_BUILD_ROOT/usr/lib/rpm/rubygemsdeps.rb
install -D -m 0755 %{S:6} $RPM_BUILD_ROOT/usr/lib/rpm/gem_install.sh
install -D -m 0755 %{S:1} $RPM_BUILD_ROOT/usr/lib/rpm/gem_build_cleanup.sh
export NO_BRP_STALE_LINK_ERROR=yes
%files
%defattr(-,root,root)
/etc/rpm/macros.ruby
%exclude %_bindir/gem_build_cleanup
%{_bindir}/*
%files devel
@ -117,7 +124,8 @@ export NO_BRP_STALE_LINK_ERROR=yes
/etc/rpm/macros.common-ruby
%dir /usr/lib/rpm/fileattrs
/usr/lib/rpm/fileattrs/rubygems.attr
/usr/lib/rpm/rubygemsdeps.sh
%_bindir/gem_build_cleanup
/usr/lib/rpm/rubygemsdeps.rb
/usr/lib/rpm/gem_install.sh
/usr/lib/rpm/gem_build_cleanup.sh
%changelog

View File

@ -1,4 +1,4 @@
%__rubygems_requires %{_rpmconfigdir}/rubygemsdeps.sh --requires
%__rubygems_provides %{_rpmconfigdir}/rubygemsdeps.sh --provides
%__rubygems_path ^%{_libdir}/ruby/gems/[^/]*/specifications
%__rubygems_requires %{_rpmconfigdir}/rubygemsdeps.rb --requires
%__rubygems_provides %{_rpmconfigdir}/rubygemsdeps.rb --provides
%__rubygems_path ^%{_libdir}/ruby/gems/[^/]*/specifications

66
rubygemsdeps.rb Normal file
View File

@ -0,0 +1,66 @@
#!/usr/bin/ruby
require 'optparse'
require 'rubygems/specification'
opts = OptionParser.new("Usage: #{$0}")
provides=false
opts.on("-P", "--provides", "Output the provides of the package") do |val|
provides=true
end
requires=false
opts.on("-R", "--requires", "Output the requires of the package") do |val|
requires=true
end
rest = opts.permute(ARGV)
unless provides || requires
exit(0)
end
gemspecs=Array.new
$stdin.each_line do |line|
line.match(%r{.*/specifications/.*\.gemspec$}) do |m|
gemspecs << [m[0], Gem::Specification.load(m[0])]
end
end
gemspecs.each do |file, spec|
rubyabi=nil
file.match(%r{.*/gems/([^/]*)/.*}) do |m|
rubyabi=m[1]
end
if provides
# old forms
puts "rubygem-#{spec.name} = #{spec.version}"
versions = spec.version.to_s.split('.')
puts "rubygem-#{spec.name}-#{versions[0]} = #{spec.version}" if versions.length > 0
puts "rubygem-#{spec.name}-#{versions[0]}_#{versions[1]} = #{spec.version}" if versions.length > 1
puts "rubygem-#{spec.name}-#{versions[0]}_#{versions[1]}_#{versions[2]} = #{spec.version}" if versions.length > 2
# version without ruby version - asking for trouble
puts "rubygem(#{spec.name}) = #{spec.version}"
puts "rubygem(#{rubyabi}:#{spec.name}) = #{spec.version}" if rubyabi
end
if requires
puts "ruby(abi) = #{rubyabi}" if rubyabi
spec.runtime_dependencies.each do |dep|
dep.requirement.requirements.each do |r|
if r.first == '~>'
next_version = Gem::Version.create(r.last).bump
puts "rubygem(#{rubyabi}:#{dep.name}) >= #{r.last}"
puts "rubygem(#{rubyabi}:#{dep.name}) < #{next_version}"
elsif r.first == '!='
# this is purely guessing, but we can't generate conflicts here ;(
puts "rubygem(#{rubyabi}:#{dep.name}) > #{r.last}"
#puts "rubygem(#{rubyabi}:#{dep.name}) < #{r.last}"
else
puts "rubygem(#{rubyabi}:#{dep.name}) #{r.first} #{r.last}"
end
end
end
end
end

View File

@ -1,33 +0,0 @@
#!/bin/bash
[ $# -ge 1 ] || {
cat > /dev/null
exit 0
}
case $1 in
-P|--provides)
shift
RPM_BUILD_ROOT="$1"
while read possible
do
case "$possible" in
*.gemspec)
possible=${possible##*/}
possible=${possible%.gemspec}
echo "$possible" | sed -e 's,^\(.*\)-,rubygem(\1) = ,'
;;
esac
done
;;
-R|--requires)
while read possible ; do
case "$possible" in
*.gemspec)
echo "$possible" | sed -ne 's,.*/gems/,ruby(abi) = ,; s,/.*,,p'
;;
esac
done
;;
esac
exit 0