Make operating_system.rb more robust.

This avoids issues with incomplete rbconfig.rb such as:

https://bugs.ruby-lang.org/issues/10822
This commit is contained in:
Vít Ondruch 2015-02-03 13:33:29 +01:00
parent 76bbf0976d
commit 329ba54c7e
2 changed files with 21 additions and 8 deletions

View File

@ -6,6 +6,8 @@ module Gem
# E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'
def previous_but_one_dir_to(path, dir)
return unless path
split_path = path.split(File::SEPARATOR)
File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
end
@ -44,13 +46,21 @@ module Gem
RbConfig::CONFIG['libdir']
end
@default_dirs ||= Hash[default_locations.collect do |destination, path|
[destination, {
:bin_dir => File.join(path, RbConfig::CONFIG['bindir'].split(File::SEPARATOR).last),
:gem_dir => File.join(path, RbConfig::CONFIG['datadir'].split(File::SEPARATOR).last, 'gems'),
:ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
}]
end]
@default_dirs ||= Hash.new do |hash, key|
hash[key] = if path = default_locations[key]
{
:bin_dir => File.join(path, RbConfig::CONFIG['bindir'].split(File::SEPARATOR).last),
:gem_dir => File.join(path, RbConfig::CONFIG['datadir'].split(File::SEPARATOR).last, 'gems'),
:ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
}
else
{
:bin_dir => '',
:gem_dir => '',
:ext_dir => ''
}
end
end
end
##

View File

@ -21,7 +21,7 @@
%endif
%global release 4
%global release 5
%{!?release_string:%global release_string %{?development_release:0.}%{release}%{?development_release:.%{development_release}}%{?dist}}
%global rubygems_version 2.4.5
@ -881,6 +881,9 @@ make check TESTS="-v $DISABLE_TESTS"
%{ruby_libdir}/tkextlib
%changelog
* Tue Feb 03 2015 Vít Ondruch <vondruch@redhat.com> - 2.2.0-5
- Make operating_system.rb more robust.
* Thu Jan 29 2015 Vít Ondruch <vondruch@redhat.com> - 2.2.0-4
- Add missing rubygem-test-unit dependency on rubygem-power_assert.