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