aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPer Øyvind Karlsen <peroyvind@mandriva.org>2010-10-16 10:15:23 +0000
committerPer Øyvind Karlsen <peroyvind@mandriva.org>2010-10-16 10:15:23 +0000
commitb56089de7c35ff42f0184ee22f2de0553392fd46 (patch)
tree0a650aa4980cadc3e446a4d9290e09570ba31d3f
parenta7be79dfae7c40425612f5441fb97c6ae6cd7901 (diff)
downloadrpm-setup-b56089de7c35ff42f0184ee22f2de0553392fd46.tar
rpm-setup-b56089de7c35ff42f0184ee22f2de0553392fd46.tar.gz
rpm-setup-b56089de7c35ff42f0184ee22f2de0553392fd46.tar.bz2
rpm-setup-b56089de7c35ff42f0184ee22f2de0553392fd46.tar.xz
rpm-setup-b56089de7c35ff42f0184ee22f2de0553392fd46.zip
add gem_helper.rb and it's corresponding macros %gem_unpack, %gem_build &1.108
gem_install for simplifying & streamlining ruby gem packaging.
-rw-r--r--Makefile.am1
-rw-r--r--NEWS6
-rw-r--r--build.macros.in24
-rw-r--r--configure.ac2
-rwxr-xr-xgem_helper.rb173
5 files changed, 204 insertions, 2 deletions
diff --git a/Makefile.am b/Makefile.am
index f89860d..f3d2278 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -28,6 +28,7 @@ pkg_scripts = \
filter.sh \
find-lang.pl \
find-debuginfo.sh \
+ gem_helper.rb \
git-repository--after-tarball \
git-repository--apply-patch \
http.req \
diff --git a/NEWS b/NEWS
index 71130ad..489084f 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,8 @@
-Version 1.107 - 9 Seotember 2010, by Per Øyvind Karlsen
+Version 1.108 - 16 October 2010, by Per Øyvind Karlsen
+- add gem_helper.rb and it's corresponding macros %gem_unpack, %gem_build &
+ gem_install for simplifying & streamlining ruby gem packaging.
+
+Version 1.107 - 9 September 2010, by Per Øyvind Karlsen
- enable automatic dependency extraction for ruby gems
Version 1.106 - 16 July 2010, by Jerome Quelin
diff --git a/build.macros.in b/build.macros.in
index f14e8e2..1082579 100644
--- a/build.macros.in
+++ b/build.macros.in
@@ -306,6 +306,30 @@ Requires: python >= %minver, python < %maxver
%ocaml_sitelib %(if [ -x /usr/bin/ocamlc ]; then ocamlc -where;fi)/site-lib
#------------------------------------------------------------------------------
+# Ruby gem macros
+#
+
+%gem_unpack(n:a:) \
+ %{expand: %%global __tar tar -m} \
+%setup -q -c -T -a0 %{-n:-n %{-n*}} %{-a:-a %{-a*}} \
+%{__tar}zxf data.tar.gz
+
+%__gem_helper @RPMVENDORDIR@/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 \\\
+ %{!-i:--install-dir %{buildroot}%{ruby_gemdir}}%{-i:--install-dir %{-i*}} \\\
+ %{!-n:--bindir %{buildroot}%{_bindir}}%{-n:--bindir%{-n*}} \\\
+ %{!-C:--fix-permissions}
+
+#------------------------------------------------------------------------------
# Redefine RPM sections to allow jumping over them using "--without <section>".
# This an interesting alternative to --short-circuit.
# The following are mostly equivalent:
diff --git a/configure.ac b/configure.ac
index 1917d8d..7fa268a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,7 +4,7 @@
# $Id$
AC_PREREQ(2.59)
-AC_INIT(rpm-mandriva-setup, 1.107, nanardon@mandriva.org)
+AC_INIT(rpm-mandriva-setup, 1.108, nanardon@mandriva.org)
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE(1.9 -Wno-portability)
AC_CONFIG_SRCDIR
diff --git a/gem_helper.rb b/gem_helper.rb
new file mode 100755
index 0000000..6661575
--- /dev/null
+++ b/gem_helper.rb
@@ -0,0 +1,173 @@
+#!/usr/bin/env ruby
+#--
+# Copyright 2010 Per Øyvind Karlsen <peroyvind@mandriva.org>
+# 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'
+
+if ARGV[0] == "build" or ARGV[0] == "install"
+ 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.. </lameworkaround>
+ 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")
+ header = YAML::load(file_data)
+ file_data.close()
+ body = header.instance_variable_get :@ivars
+
+ require 'rubygems'
+ spec = Gem::Specification.from_yaml(YAML.dump(header))
+
+ 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