029ae1
From 94da59aafacc6a9efe829529eb51385588d6f149 Mon Sep 17 00:00:00 2001
029ae1
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
029ae1
Date: Fri, 11 Nov 2011 13:14:45 +0100
029ae1
Subject: [PATCH] Allow to install RubyGems into custom location, outside of
029ae1
 Ruby tree.
029ae1
029ae1
---
029ae1
 configure.ac            |  5 +++++
029ae1
 loadpath.c              |  4 ++++
029ae1
 template/verconf.h.tmpl |  3 +++
029ae1
 tool/rbinstall.rb       | 10 ++++++++++
029ae1
 4 files changed, 22 insertions(+)
029ae1
029ae1
diff --git a/configure.ac b/configure.ac
029ae1
index 93af30321d..bc13397e0e 100644
029ae1
--- a/configure.ac
029ae1
+++ b/configure.ac
ff7df6
@@ -3795,6 +3795,10 @@ AC_ARG_WITH(vendorarchdir,
029ae1
             [vendorarchdir=$withval],
029ae1
             [vendorarchdir=${multiarch+'${rubysitearchprefix}/vendor_ruby'${ruby_version_dir}}${multiarch-'${vendorlibdir}/${sitearch}'}])
029ae1
 
029ae1
+AC_ARG_WITH(rubygemsdir,
029ae1
+           AS_HELP_STRING([--with-rubygemsdir=DIR], [custom rubygems directory]),
029ae1
+            [rubygemsdir=$withval])
029ae1
+
029ae1
 AS_IF([test "${LOAD_RELATIVE+set}"], [
029ae1
     AC_DEFINE_UNQUOTED(LOAD_RELATIVE, $LOAD_RELATIVE)
029ae1
     RUBY_EXEC_PREFIX=''
ff7df6
@@ -3819,6 +3823,7 @@ AC_SUBST(sitearchdir)dnl
029ae1
 AC_SUBST(vendordir)dnl
029ae1
 AC_SUBST(vendorlibdir)dnl
029ae1
 AC_SUBST(vendorarchdir)dnl
029ae1
+AC_SUBST(rubygemsdir)dnl
029ae1
 
029ae1
 AC_SUBST(CONFIGURE, "`echo $0 | sed 's|.*/||'`")dnl
029ae1
 AC_SUBST(configure_args, "`echo "${ac_configure_args}" | sed 's/\\$/$$/g'`")dnl
029ae1
diff --git a/loadpath.c b/loadpath.c
029ae1
index 623dc9d..74c5d9e 100644
029ae1
--- a/loadpath.c
029ae1
+++ b/loadpath.c
029ae1
@@ -94,6 +94,10 @@ const char ruby_initial_load_paths[] =
029ae1
 #endif
029ae1
 #endif
029ae1
 
029ae1
+#ifdef RUBYGEMS_DIR
029ae1
+    RUBYGEMS_DIR "\0"
029ae1
+#endif
029ae1
+
029ae1
     RUBY_LIB "\0"
029ae1
 #ifdef RUBY_THINARCH
029ae1
     RUBY_ARCH_LIB_FOR(RUBY_THINARCH) "\0"
029ae1
diff --git a/template/verconf.h.tmpl b/template/verconf.h.tmpl
029ae1
index 79c003e..34f2382 100644
029ae1
--- a/template/verconf.h.tmpl
029ae1
+++ b/template/verconf.h.tmpl
029ae1
@@ -36,6 +36,9 @@
029ae1
 % if C["RUBY_SEARCH_PATH"]
029ae1
 #define RUBY_SEARCH_PATH		"${RUBY_SEARCH_PATH}"
029ae1
 % end
029ae1
+% if C["rubygemsdir"]
029ae1
+#define RUBYGEMS_DIR			"${rubygemsdir}"
029ae1
+% end
029ae1
 %
029ae1
 % R = {}
029ae1
 % R["ruby_version"] = '"RUBY_LIB_VERSION"'
029ae1
diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
029ae1
index b47b6e1..0b99408 100755
029ae1
--- a/tool/rbinstall.rb
029ae1
+++ b/tool/rbinstall.rb
029ae1
@@ -343,6 +343,7 @@ def CONFIG.[](name, mandatory = false)
029ae1
   vendorlibdir = CONFIG["vendorlibdir"]
029ae1
   vendorarchlibdir = CONFIG["vendorarchdir"]
029ae1
 end
029ae1
+rubygemsdir = CONFIG["rubygemsdir"]
029ae1
 mandir = CONFIG["mandir", true]
029ae1
 docdir = CONFIG["docdir", true]
029ae1
 enable_shared = CONFIG["ENABLE_SHARED"] == 'yes'
029ae1
@@ -570,7 +571,16 @@ def stub
029ae1
 install?(:local, :comm, :lib) do
029ae1
   prepare "library scripts", rubylibdir
029ae1
   noinst = %w[*.txt *.rdoc *.gemspec]
029ae1
+  # Bundler carries "rubygems.rb" file, so it must be specialcased :/
029ae1
+  noinst += %w[rubygems.rb rubygems/ bundler.rb bundler/] if rubygemsdir
029ae1
   install_recursive(File.join(srcdir, "lib"), rubylibdir, :no_install => noinst, :mode => $data_mode)
029ae1
+  if rubygemsdir
029ae1
+    noinst = %w[*.txt *.rdoc *.gemspec]
029ae1
+    install_recursive(File.join(srcdir, "lib", "rubygems"), File.join(rubygemsdir, "rubygems"), :no_install => noinst, :mode => $data_mode)
029ae1
+    install(File.join(srcdir, "lib", "rubygems.rb"), File.join(rubygemsdir, "rubygems.rb"), :mode => $data_mode)
029ae1
+    install_recursive(File.join(srcdir, "lib", "bundler"), File.join(rubylibdir, "bundler"), :no_install => noinst, :mode => $data_mode)
029ae1
+    install(File.join(srcdir, "lib", "bundler.rb"), rubylibdir, :mode => $data_mode)
029ae1
+  end
029ae1
 end
029ae1
 
029ae1
 install?(:local, :comm, :hdr, :'comm-hdr') do
029ae1
-- 
029ae1
1.8.3.1
029ae1