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