]> git.pld-linux.org Git - packages/ruby.git/blame - operating_system.rb
fix ssl_certs cleanup
[packages/ruby.git] / operating_system.rb
CommitLineData
a6d548c5
ER
1module Gem
2 class << self
3
4 ##
5 # Returns full path of previous but one directory of dir in path
6 # E.g. for '/usr/share/ruby', 'ruby', it returns '/usr'
7
8 def previous_but_one_dir_to(path, dir)
9 split_path = path.split(File::SEPARATOR)
10 File.join(split_path.take_while { |one_dir| one_dir !~ /^#{dir}$/ }[0..-2])
11 end
12 private :previous_but_one_dir_to
13
1a83bc11
ER
14 ##
15 # Tries to detect, if arguments and environment variables suggest that
16 # 'gem install' is executed from rpmbuild.
17
18 def rpmbuild?
19 (ARGV.include?('--install-dir') || ARGV.include?('-i')) && ENV['RPM_PACKAGE_NAME']
20 end
21 private :rpmbuild?
22
a6d548c5
ER
23 ##
24 # Default gems locations allowed on FHS system (/usr, /usr/share).
25 # The locations are derived from directories specified during build
26 # configuration.
27
28 def default_locations
29 @default_locations ||= {
30 :system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
31 :local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
32 }
33 end
34
35 ##
36 # For each location provides set of directories for binaries (:bin_dir)
37 # platform independent (:gem_dir) and dependent (:ext_dir) files.
38
39 def default_dirs
40 @libdir ||= case RUBY_PLATFORM
41 when 'java'
42 ConfigMap[:datadir]
43 else
44 ConfigMap[:libdir]
45 end
46
47 @default_dirs ||= Hash[default_locations.collect do |destination, path|
48 [destination, {
49 :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
50 :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
51 :ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
52 }]
53 end]
54 end
55
56 ##
57 # Remove methods we are going to override. This avoids "method redefined;"
58 # warnings otherwise issued by Ruby.
59
60 remove_method :default_dir if method_defined? :default_dir
61 remove_method :default_path if method_defined? :default_path
62 remove_method :default_bindir if method_defined? :default_bindir
63 remove_method :default_ext_dir_for if method_defined? :default_ext_dir_for
64
65 ##
66 # RubyGems default overrides.
67
68 def default_dir
69 if Process.uid == 0
70 Gem.default_dirs[:local][:gem_dir]
71 else
72 Gem.user_dir
73 end
74 end
75
76 def default_path
77 path = default_dirs.collect {|location, paths| paths[:gem_dir]}
78 path.unshift Gem.user_dir if File.exist? Gem.user_home
79 end
80
81 def default_bindir
82 if Process.uid == 0
83 Gem.default_dirs[:local][:bin_dir]
84 else
85 File.join [Dir.home, 'bin']
86 end
87 end
88
89 def default_ext_dir_for base_dir
1a83bc11
ER
90 dir = if rpmbuild?
91 build_dir = base_dir.chomp Gem.default_dirs[:system][:gem_dir]
92 if build_dir != base_dir
93 File.join build_dir, Gem.default_dirs[:system][:ext_dir]
94 end
95 else
96 dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
97 dirs && dirs.last[:ext_dir]
98 end
99 dir && File.join(dir, RbConfig::CONFIG['RUBY_INSTALL_NAME'])
100 end
101
102 # This method should be available since RubyGems 2.2 until RubyGems 3.0.
103 # https://github.com/rubygems/rubygems/issues/749
104 if method_defined? :install_extension_in_lib
105 remove_method :install_extension_in_lib
106
107 def install_extension_in_lib
108 false
109 end
a6d548c5
ER
110 end
111 end
112end
This page took 0.044383 seconds and 4 git commands to generate.