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