[ruby/private-ruby-2.1] Detect if rubygems are running under rpmbuild.
Vít Ondruch
vondruch at fedoraproject.org
Fri Jan 10 13:55:23 UTC 2014
commit 19ff4992f3753a8a614abf5088635b6fbd2464e0
Author: Vít Ondruch <vondruch at redhat.com>
Date: Fri Jan 10 14:53:57 2014 +0100
Detect if rubygems are running under rpmbuild.
This allows to install binaryi extensions on suitable place and clears
the .spec files a bit.
operating_system.rb | 21 +++++++++++++++++++--
1 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/operating_system.rb b/operating_system.rb
index fba8117..079564f 100644
--- a/operating_system.rb
+++ b/operating_system.rb
@@ -12,6 +12,15 @@ module Gem
private :previous_but_one_dir_to
##
+ # Tries to detect, if arguments and environment variables suggest that
+ # 'gem install' is executed from rpmbuild.
+
+ def rpmbuild?
+ (ARGV.include?('--install-dir') || ARGV.include?('-i')) && ENV['RPM_PACKAGE_NAME']
+ end
+ private :rpmbuild?
+
+ ##
# Default gems locations allowed on FHS system (/usr, /usr/share).
# The locations are derived from directories specified during build
# configuration.
@@ -78,8 +87,16 @@ module Gem
end
def default_ext_dir_for base_dir
- dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
- dirs && File.join(dirs.last[:ext_dir], RbConfig::CONFIG['RUBY_INSTALL_NAME'])
+ dir = if rpmbuild?
+ build_dir = base_dir.chomp Gem.default_dirs[:system][:gem_dir]
+ if build_dir != base_dir
+ File.join build_dir, Gem.default_dirs[:system][:ext_dir]
+ end
+ else
+ dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
+ dirs && dirs.last[:ext_dir]
+ end
+ dir && File.join(dir, RbConfig::CONFIG['RUBY_INSTALL_NAME'])
end
# This method should be available since RubyGems 2.2 until RubyGems 3.0.
More information about the scm-commits
mailing list