]> git.pld-linux.org Git - packages/ruby.git/blob - operating_system.rb
- rel 3 for non-bootstrap build
[packages/ruby.git] / operating_system.rb
1 module 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
14     ##
15     # Default gems locations allowed on FHS system (/usr, /usr/share).
16     # The locations are derived from directories specified during build
17     # configuration.
18
19     def default_locations
20       @default_locations ||= {
21         :system => previous_but_one_dir_to(ConfigMap[:vendordir], ConfigMap[:RUBY_INSTALL_NAME]),
22         :local => previous_but_one_dir_to(ConfigMap[:sitedir], ConfigMap[:RUBY_INSTALL_NAME])
23       }
24     end
25
26     ##
27     # For each location provides set of directories for binaries (:bin_dir)
28     # platform independent (:gem_dir) and dependent (:ext_dir) files.
29
30     def default_dirs
31       @libdir ||= case RUBY_PLATFORM
32       when 'java'
33         ConfigMap[:datadir]
34       else
35         ConfigMap[:libdir]
36       end
37
38       @default_dirs ||= Hash[default_locations.collect do |destination, path|
39         [destination, {
40           :bin_dir => File.join(path, ConfigMap[:bindir].split(File::SEPARATOR).last),
41           :gem_dir => File.join(path, ConfigMap[:datadir].split(File::SEPARATOR).last, 'gems'),
42           :ext_dir => File.join(path, @libdir.split(File::SEPARATOR).last, 'gems')
43         }]
44       end]
45     end
46
47     ##
48     # Remove methods we are going to override. This avoids "method redefined;"
49     # warnings otherwise issued by Ruby.
50
51     remove_method :default_dir if method_defined? :default_dir
52     remove_method :default_path if method_defined? :default_path
53     remove_method :default_bindir if method_defined? :default_bindir
54     remove_method :default_ext_dir_for if method_defined? :default_ext_dir_for
55
56     ##
57     # RubyGems default overrides.
58
59     def default_dir
60       if Process.uid == 0
61         Gem.default_dirs[:local][:gem_dir]
62       else
63         Gem.user_dir
64       end
65     end
66
67     def default_path
68       path = default_dirs.collect {|location, paths| paths[:gem_dir]}
69       path.unshift Gem.user_dir if File.exist? Gem.user_home
70     end
71
72     def default_bindir
73       if Process.uid == 0
74         Gem.default_dirs[:local][:bin_dir]
75       else
76         File.join [Dir.home, 'bin']
77       end
78     end
79
80     def default_ext_dir_for base_dir
81       dirs = Gem.default_dirs.detect {|location, paths| paths[:gem_dir] == base_dir}
82       dirs && File.join(dirs.last[:ext_dir], RbConfig::CONFIG['RUBY_INSTALL_NAME'])
83     end
84   end
85 end
This page took 0.059036 seconds and 3 git commands to generate.