| Class | Gem::Commands::SetupCommand |
| In: |
lib/rubygems/commands/setup_command.rb
|
| Parent: | Gem::Command |
Installs RubyGems itself. This command is ordinarily only available from a RubyGems checkout or tarball.
# File lib/rubygems/commands/setup_command.rb, line 9
9: def initialize
10: require 'tmpdir'
11:
12: super 'setup', 'Install RubyGems',
13: :format_executable => true, :rdoc => true, :ri => true,
14: :site_or_vendor => :sitelibdir,
15: :destdir => '', :prefix => ''
16:
17: add_option '--prefix=PREFIX',
18: 'Prefix path for installing RubyGems',
19: 'Will not affect gem repository location' do |prefix, options|
20: options[:prefix] = File.expand_path prefix
21: end
22:
23: add_option '--destdir=DESTDIR',
24: 'Root directory to install RubyGems into',
25: 'Mainly used for packaging RubyGems' do |destdir, options|
26: options[:destdir] = File.expand_path destdir
27: end
28:
29: add_option '--[no-]vendor',
30: 'Install into vendorlibdir not sitelibdir' do |vendor, options|
31: options[:site_or_vendor] = vendor ? :vendorlibdir : :sitelibdir
32: end
33:
34: add_option '--[no-]format-executable',
35: 'Makes `gem` match ruby',
36: 'If ruby is ruby18, gem will be gem18' do |value, options|
37: options[:format_executable] = value
38: end
39:
40: add_option '--[no-]rdoc',
41: 'Generate RDoc documentation for RubyGems' do |value, options|
42: options[:rdoc] = value
43: end
44:
45: add_option '--[no-]ri',
46: 'Generate RI documentation for RubyGems' do |value, options|
47: options[:ri] = value
48: end
49: end
# File lib/rubygems/commands/setup_command.rb, line 51
51: def check_ruby_version
52: required_version = Gem::Requirement.new '>= 1.8.7'
53:
54: unless required_version.satisfied_by? Gem.ruby_version then
55: alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}"
56: terminate_interaction 1
57: end
58: end
# File lib/rubygems/commands/setup_command.rb, line 83
83: def execute
84: @verbose = Gem.configuration.really_verbose
85:
86: install_destdir = options[:destdir]
87:
88: unless install_destdir.empty? then
89: ENV['GEM_HOME'] ||= File.join(install_destdir,
90: Gem.default_dir.gsub(/^[a-zA-Z]:/, ''))
91: end
92:
93: check_ruby_version
94:
95: require 'fileutils'
96: if Gem.configuration.really_verbose then
97: extend FileUtils::Verbose
98: else
99: extend FileUtils
100: end
101:
102: lib_dir, bin_dir = make_destination_dirs install_destdir
103:
104: install_lib lib_dir
105:
106: install_executables bin_dir
107:
108: remove_old_bin_files bin_dir
109:
110: say "RubyGems #{Gem::VERSION} installed"
111:
112: uninstall_old_gemcutter
113:
114: install_rdoc
115:
116: say
117: if @verbose then
118: say "-" * 78
119: say
120: end
121:
122: release_notes = File.join Dir.pwd, 'History.txt'
123:
124: release_notes = if File.exist? release_notes then
125: open release_notes do |io|
126: text = io.gets '==='
127: text << io.gets('===')
128: text[0...-3].sub(/^# coding:.*?^=/m, '')
129: end
130: else
131: "Oh-no! Unable to find release notes!"
132: end
133:
134: say release_notes
135:
136: say
137: say "-" * 78
138: say
139:
140: say "RubyGems installed the following executables:"
141: say @bin_file_names.map { |name| "\t#{name}\n" }
142: say
143:
144: unless @bin_file_names.grep(/#{File::SEPARATOR}gem$/) then
145: say "If `gem` was installed by a previous RubyGems installation, you may need"
146: say "to remove it by hand."
147: say
148: end
149: end
# File lib/rubygems/commands/setup_command.rb, line 272
272: def generate_default_dirs(install_destdir)
273: prefix = options[:prefix]
274: site_or_vendor = options[:site_or_vendor]
275:
276: if prefix.empty? then
277: lib_dir = Gem::ConfigMap[site_or_vendor]
278: bin_dir = Gem::ConfigMap[:bindir]
279: else
280: # Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets
281: # confused about installation location, so switch back to
282: # sitelibdir/vendorlibdir.
283: if defined?(APPLE_GEM_HOME) and
284: # just in case Apple and RubyGems don't get this patched up proper.
285: (prefix == Gem::ConfigMap[:libdir] or
286: # this one is important
287: prefix == File.join(Gem::ConfigMap[:libdir], 'ruby')) then
288: lib_dir = Gem::ConfigMap[site_or_vendor]
289: bin_dir = Gem::ConfigMap[:bindir]
290: else
291: lib_dir = File.join prefix, 'lib'
292: bin_dir = File.join prefix, 'bin'
293: end
294: end
295:
296: unless install_destdir.empty? then
297: lib_dir = File.join install_destdir, lib_dir.gsub(/^[a-zA-Z]:/, '')
298: bin_dir = File.join install_destdir, bin_dir.gsub(/^[a-zA-Z]:/, '')
299: end
300:
301: [lib_dir, bin_dir]
302: end
# File lib/rubygems/commands/setup_command.rb, line 151
151: def install_executables(bin_dir)
152: say "Installing gem executable" if @verbose
153:
154: @bin_file_names = []
155:
156: Dir.chdir 'bin' do
157: bin_files = Dir['*']
158:
159: bin_files.delete 'update_rubygems'
160:
161: bin_files.each do |bin_file|
162: bin_file_formatted = if options[:format_executable] then
163: Gem.default_exec_format % bin_file
164: else
165: bin_file
166: end
167:
168: dest_file = File.join bin_dir, bin_file_formatted
169: bin_tmp_file = File.join Dir.tmpdir, bin_file
170:
171: begin
172: bin = File.readlines bin_file
173: bin[0] = "#!#{Gem.ruby}\n"
174:
175: File.open bin_tmp_file, 'w' do |fp|
176: fp.puts bin.join
177: end
178:
179: install bin_tmp_file, dest_file, :mode => 0755
180: @bin_file_names << dest_file
181: ensure
182: rm bin_tmp_file
183: end
184:
185: next unless Gem.win_platform?
186:
187: begin
188: bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat"
189:
190: File.open bin_cmd_file, 'w' do |file|
191: file.puts "@ECHO OFF\nIF NOT \"%~f0\" == \"~f0\" GOTO :WinNT\n@\"\#{File.basename(Gem.ruby).chomp('\"')}\" \"\#{dest_file}\" %1 %2 %3 %4 %5 %6 %7 %8 %9\nGOTO :EOF\n:WinNT\n@\"\#{File.basename(Gem.ruby).chomp('\"')}\" \"%~dpn0\" %*\n"
192: end
193:
194: install bin_cmd_file, "#{dest_file}.bat", :mode => 0755
195: ensure
196: rm bin_cmd_file
197: end
198: end
199: end
200: end
# File lib/rubygems/commands/setup_command.rb, line 210
210: def install_lib(lib_dir)
211: say "Installing RubyGems" if @verbose
212:
213: Dir.chdir 'lib' do
214: lib_files = Dir[File.join('**', '*rb')]
215:
216: # Be sure to include our SSL ca bundles
217: lib_files += Dir[File.join('**', '*pem')]
218:
219: lib_files.each do |lib_file|
220: dest_file = File.join lib_dir, lib_file
221: dest_dir = File.dirname dest_file
222: mkdir_p dest_dir unless File.directory? dest_dir
223:
224: install lib_file, dest_file, :mode => 0644
225: end
226: end
227: end
# File lib/rubygems/commands/setup_command.rb, line 229
229: def install_rdoc
230: gem_doc_dir = File.join Gem.dir, 'doc'
231: rubygems_name = "rubygems-#{Gem::VERSION}"
232: rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
233:
234: if File.writable? gem_doc_dir and
235: (not File.exist? rubygems_doc_dir or
236: File.writable? rubygems_doc_dir) then
237: say "Removing old RubyGems RDoc and ri" if @verbose
238: Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
239: rm_rf dir
240: end
241:
242: if options[:ri] then
243: ri_dir = File.join rubygems_doc_dir, 'ri'
244: say "Installing #{rubygems_name} ri into #{ri_dir}" if @verbose
245: run_rdoc '--ri', '--op', ri_dir
246: end
247:
248: if options[:rdoc] then
249: rdoc_dir = File.join rubygems_doc_dir, 'rdoc'
250: say "Installing #{rubygems_name} rdoc into #{rdoc_dir}" if @verbose
251: run_rdoc '--op', rdoc_dir
252: end
253: elsif @verbose then
254: say "Skipping RDoc generation, #{gem_doc_dir} not writable"
255: say "Set the GEM_HOME environment variable if you want RDoc generated"
256: end
257: end
# File lib/rubygems/commands/setup_command.rb, line 259
259: def make_destination_dirs(install_destdir)
260: lib_dir, bin_dir = Gem.default_rubygems_dirs
261:
262: unless lib_dir
263: lib_dir, bin_dir = generate_default_dirs(install_destdir)
264: end
265:
266: mkdir_p lib_dir
267: mkdir_p bin_dir
268:
269: return lib_dir, bin_dir
270: end
# File lib/rubygems/commands/setup_command.rb, line 304
304: def remove_old_bin_files(bin_dir)
305: old_bin_files = {
306: 'gem_mirror' => 'gem mirror',
307: 'gem_server' => 'gem server',
308: 'gemlock' => 'gem lock',
309: 'gemri' => 'ri',
310: 'gemwhich' => 'gem which',
311: 'index_gem_repository.rb' => 'gem generate_index',
312: }
313:
314: old_bin_files.each do |old_bin_file, new_name|
315: old_bin_path = File.join bin_dir, old_bin_file
316: next unless File.exist? old_bin_path
317:
318: deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead."
319:
320: File.open old_bin_path, 'w' do |fp|
321: fp.write "#!\#{Gem.ruby}\n\nabort \"\#{deprecation_message}\"\n"
322: end
323:
324: next unless Gem.win_platform?
325:
326: File.open "#{old_bin_path}.bat", 'w' do |fp|
327: fp.puts %{@ECHO.#{deprecation_message}}
328: end
329: end
330: end
# File lib/rubygems/commands/setup_command.rb, line 337
337: def run_rdoc(*args)
338: begin
339: gem 'rdoc'
340: rescue Gem::LoadError
341: end
342:
343: require 'rdoc/rdoc'
344:
345: args << '--main' << 'README.rdoc' << '--quiet'
346: args << '.'
347: args << 'README.rdoc' << 'UPGRADING.rdoc'
348: args << 'LICENSE.txt' << 'MIT.txt' << 'History.txt'
349:
350: r = RDoc::RDoc.new
351: r.document args
352: end