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