Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 228 lines (170 sloc) 5.173 kb
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
1 #--
2 # Copyright 2006, 2007 by Chad Fowler, Rich Kilmer, Jim Weirich, Eric Hodel
3 # and others.
4 # All rights reserved.
5 # See LICENSE.txt for permissions.
6 #++
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
7
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
8 $:.unshift 'lib'
9 require 'rubygems'
c7886fd @chad update to setup.rb 3.4.1
chad authored
10
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
11 require 'fileutils'
12 require 'rbconfig'
13 require 'rdoc/rdoc'
14 require 'tmpdir'
c7886fd @chad update to setup.rb 3.4.1
chad authored
15
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
16 include FileUtils::Verbose
c7886fd @chad update to setup.rb 3.4.1
chad authored
17
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
18 # check ruby version
c7886fd @chad update to setup.rb 3.4.1
chad authored
19
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
20 required_version = Gem::Version::Requirement.create(">= 1.8.2")
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
21
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
22 unless required_version.satisfied_by? Gem::Version.new(RUBY_VERSION) then
23 abort "Expected Ruby version #{required_version}, was #{RUBY_VERSION}"
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
24 end
25
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
26 # install stuff
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
27
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
28 lib_dir = nil
29 bin_dir = nil
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
30
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
31 if ARGV.grep(/^--prefix/).empty? then
32 lib_dir = Config::CONFIG['sitelibdir']
33 bin_dir = Config::CONFIG['bindir']
34 else
35 prefix = nil
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
36
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
37 ARGV.grep(/^--prefix=(.*)/)
38 if $1.nil? or $1.empty? then
39 path_index = ARGV.index '--prefix'
40 prefix = ARGV[path_index + 1]
41 else
42 prefix = $1
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
43 end
44
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
45 raise "invalid --prefix #{prefix.inspect}" if prefix.nil?
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
46
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
47 lib_dir = File.join prefix, 'lib'
48 bin_dir = File.join prefix, 'bin'
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
49
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
50 mkdir_p lib_dir
51 mkdir_p bin_dir
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
52 end
53
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
54 Dir.chdir 'lib' do
55 lib_files = Dir[File.join('**', '*rb')]
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
56
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
57 lib_files.each do |lib_file|
58 dest_file = File.join lib_dir, lib_file
59 dest_dir = File.dirname dest_file
60 mkdir_p dest_dir unless File.directory? dest_dir
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
61
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
62 install lib_file, dest_file, :mode => 0644
c7886fd @chad update to setup.rb 3.4.1
chad authored
63 end
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
64 end
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
65
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
66 Dir.chdir 'bin' do
67 bin_files = Dir['*']
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
68
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
69 bin_files.each do |bin_file|
70 dest_file = File.join bin_dir, bin_file
71 bin_tmp_file = File.join Dir.tmpdir, bin_file
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
72
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
73 begin
74 cp bin_file, bin_tmp_file
75 bin = File.readlines bin_tmp_file
76 bin[0] = "#!#{Gem.ruby}\n"
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
77
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
78 File.open bin_tmp_file, 'w' do |fp|
79 fp.puts bin.join
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
80 end
81
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
82 install bin_tmp_file, dest_file, :mode => 0755
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
83 ensure
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
84 rm bin_tmp_file
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
85 end
86
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
87 next unless Gem.win_platform?
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
88
89 begin
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
90 bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.cmd"
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
91
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
92 File.open bin_cmd_file, 'w' do |file|
93 file.puts %{@"#{Gem.ruby}" "#{bin_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9}
c7886fd @chad update to setup.rb 3.4.1
chad authored
94 end
95
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
96 install bin_cmd_file, "#{dest_file}.cmd", :mode => 0755
97 ensure
98 rm bin_cmd_file
99 end
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
100 end
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
101 end
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
102
48efd10 @drbrain Install bin files for old gem executables
drbrain authored
103 # Replace old bin files with ones that abort.
104
105 old_bin_files = {
106 'gem_mirror' => 'gem mirror',
107 'gem_server' => 'gem server',
108 'gemlock' => 'gem lock',
109 'gemri' => 'ri',
110 'gemwhich' => 'gem which',
111 'index_gem_repository.rb' => 'gem generate_index',
112 }
113
114 old_bin_files.each do |old_bin_file, new_name|
115 old_bin_path = File.join bin_dir, old_bin_file
116 next unless File.exist? old_bin_path
117
118 File.open old_bin_path, 'w' do |fp|
119 fp.write <<-EOF
120 #!#{Gem.ruby}
121
122 abort "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead."
123 EOF
124 end
125
126 next unless Gem.win_platform?
127
128 File.open "#{old_bin_path}.cmd", 'w' do |fp|
129 fp.puts %{@"#{ruby_cmd}" "#{old_bin_file}"}
130 end
131 end
132
2e8c2a5 @drbrain Remove source caches on install
drbrain authored
133 # Remove source caches
134
135 require 'rubygems/source_info_cache'
136
137 user_cache_file = Gem::SourceInfoCache.user_cache_file
138 system_cache_file = Gem::SourceInfoCache.system_cache_file
139
140 rm user_cache_file if File.writable? user_cache_file
141 rm system_cache_file if File.writable? system_cache_file
142
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
143 # install RDoc
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
144
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
145 gem_doc_dir = File.join Gem.dir, 'doc'
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
146
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
147 if File.writable? gem_doc_dir then
148 puts "Removing old RubyGems RDoc and ri..."
b882a3c @drbrain Only clear RDoc for rubygems
drbrain authored
149 Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
150 rm_rf dir
c7886fd @chad update to setup.rb 3.4.1
chad authored
151 end
152
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
153 def run_rdoc(*args)
154 args << '--quiet'
155 args << '--main' << 'README'
156 args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt'
c7886fd @chad update to setup.rb 3.4.1
chad authored
157
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
158 r = RDoc::RDoc.new
159 r.document args
c7886fd @chad update to setup.rb 3.4.1
chad authored
160 end
161
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
162 rubygems_name = "rubygems-#{Gem::RubyGemsVersion}"
c7886fd @chad update to setup.rb 3.4.1
chad authored
163
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
164 doc_dir = File.join Gem.dir, 'doc', rubygems_name
c7886fd @chad update to setup.rb 3.4.1
chad authored
165
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
166 unless ARGV.include? '--no-ri' then
167 ri_dir = File.join doc_dir, 'ri'
168 puts "Installing #{rubygems_name} ri into #{ri_dir}..."
169 run_rdoc '--ri', '--op', ri_dir
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
170 end
171
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
172 unless ARGV.include? '--no-rdoc' then
173 rdoc_dir = File.join(doc_dir, 'rdoc')
174 puts "Installing #{rubygems_name} rdoc into #{rdoc_dir}..."
175 run_rdoc '--op', rdoc_dir
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
176 end
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
177 else
178 puts "Skipping RDoc generation, #{gem_doc_dir} not writable"
179 puts "Set the GEM_HOME environment variable if you want RDoc generated"
180 end
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
181
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
182 # Remove stubs
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
183
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
184 def stub?(path)
7f2c778 @drbrain Make setup.rb work on 1.9
drbrain authored
185 return unless File.readable? path
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
186 File.read(path, 40) =~ /^# This file was generated by RubyGems/ and
187 File.readlines(path).size < 20
188 end
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
189
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
190 puts <<-EOF.gsub(/^ */, '')
191 As of RubyGems 0.8.0, library stubs are no longer needed.
192 Searching $LOAD_PATH for stubs to optionally delete (may take a while)...
193 EOF
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
194
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
195 gemfiles = Dir[File.join("{#{($LOAD_PATH).join(',')}}", '**', '*.rb')]
196 gemfiles = gemfiles.map { |file| File.expand_path file }.uniq
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
197
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
198 puts "...done."
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
199
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
200 seen_stub = false
c7886fd @chad update to setup.rb 3.4.1
chad authored
201
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
202 gemfiles.each do |file|
203 next if File.directory? file
204 next unless stub? file
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
205
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
206 unless seen_stub then
207 puts "\nRubyGems has detected stubs that can be removed. Confirm their removal:"
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
208 end
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
209 seen_stub = true
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
210
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
211 print " * remove #{file}? [y/n] "
212 answer = gets
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
213
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
214 if answer =~ /y/i then
215 unlink file
216 puts " (removed)"
217 else
218 puts " (skipping)"
c7886fd @chad update to setup.rb 3.4.1
chad authored
219 end
220 end
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
221
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
222 if seen_stub then
223 puts "Finished with library stubs."
224 else
225 puts "No library stubs found."
228a380 @chad Changing to setup.rb. Needs testing!
chad authored
226 end
f9b95a4 @drbrain Gem::ruby now returns the full path. Added Gem::prefix to make self upd...
drbrain authored
227
Something went wrong with that request. Please try again.