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