File: setup.rb

package info (click to toggle)
libgems-ruby 1.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 1,572 kB
  • ctags: 1,788
  • sloc: ruby: 17,926; sh: 223; makefile: 61
file content (326 lines) | stat: -rw-r--r-- 8,486 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
#--
# Copyright 2006, 2007 by Chad Fowler, Rich Kilmer, Jim Weirich, Eric Hodel
# and others.
# All rights reserved.
# See LICENSE.txt for permissions.
#++

# Make sure rubygems isn't already loaded.
if ENV['RUBYOPT'] and defined? Gem then
  ENV.delete 'RUBYOPT'

  require 'rbconfig'
  config = defined?(RbConfig) ? RbConfig : Config

  ruby = File.join config::CONFIG['bindir'], config::CONFIG['ruby_install_name']
  ruby << config::CONFIG['EXEEXT']

  exec(ruby, 'setup.rb', *ARGV)
end

$:.unshift 'lib'
require 'rubygems'
require 'getoptlong'

opts = GetoptLong.new(
    [ '--help',                   '-h', GetoptLong::NO_ARGUMENT ],
    [ '--prefix',                       GetoptLong::REQUIRED_ARGUMENT ],
    [ '--no-format-executable',         GetoptLong::NO_ARGUMENT ],
    [ '--no-rdoc',                      GetoptLong::NO_ARGUMENT ],
    [ '--no-ri',                        GetoptLong::NO_ARGUMENT ],
    [ '--vendor',                       GetoptLong::NO_ARGUMENT ],
    [ '--destdir',                      GetoptLong::REQUIRED_ARGUMENT ]
)

prefix = ''
format_executable = true
rdoc = true
ri = true
site_or_vendor = :sitelibdir
install_destdir = ''

opts.each do | opt, arg |
  case opt
  when '--help'
    puts <<HELP
ruby setup.rb [options]:

RubyGems will install the gem command with a name matching ruby's
prefix and suffix.  If ruby was installed as `ruby18`, gem will be
installed as `gem18`.

By default, this RubyGems will install gem as:
  #{Gem.default_exec_format % 'gem'}

Options:
  --help                 Print this message
  --prefix=DIR           Prefix path for installing RubyGems
                         Will not affect gem repository location
  --no-format-executable Force installation as `gem`
  --no-rdoc              Don't build RDoc for RubyGems
  --no-ri                Don't build ri for RubyGems
  --vendor               Install into vendorlibdir not sitelibdir
                         (Requires Ruby 1.8.7)
  --destdir              Root directory to install rubygems into
                         Used mainly for packaging RubyGems
HELP
    exit 0

  when '--no-rdoc'
    rdoc = false

  when '--no-ri'
    ri = false

  when '--no-format-executable'
    format_executable = false

  when '--prefix'
    prefix = File.expand_path(arg)

  when '--vendor'
    vendor_dir_version = Gem::Version::Requirement.create('>= 1.8.7')
    unless vendor_dir_version.satisfied_by? Gem.ruby_version then
      abort "To use --vendor you need ruby #{vendor_dir_version}, current #{Gem.ruby_version}"
    end
    site_or_vendor = :vendorlibdir

  when '--destdir'
    install_destdir = File.expand_path(arg)
  end
end

unless install_destdir.empty? then
  ENV['GEM_HOME'] ||= File.join(install_destdir,
                                Gem.default_dir.sub(/\A[a-z]:/i, ''))
end

require 'fileutils'
require 'rbconfig'
require 'tmpdir'

include FileUtils::Verbose

# check ruby version

required_version = Gem::Version::Requirement.create("> 1.8.3")

unless required_version.satisfied_by? Gem.ruby_version then
  abort "Expected Ruby version #{required_version}, was #{Gem.ruby_version}"
end

# install stuff

lib_dir = nil
bin_dir = nil

if prefix.empty?
  lib_dir = Gem::ConfigMap[site_or_vendor]
  bin_dir = Gem::ConfigMap[:bindir]
else
  # Apple installed RubyGems into libdir, and RubyGems <= 1.1.0 gets confused
  # about installation location, so switch back to sitelibdir/vendorlibdir.
  if defined?(APPLE_GEM_HOME) and
      # just in case Apple and RubyGems don't get this patched up proper.
     (prefix == Gem::ConfigMap[:libdir] or
      # this one is important
      prefix == File.join(Gem::ConfigMap[:libdir], 'ruby')) then
    lib_dir = Gem::ConfigMap[site_or_vendor]
    bin_dir = Gem::ConfigMap[:bindir]
  else
    lib_dir = File.join prefix, 'lib'
    bin_dir = File.join prefix, 'bin'
  end
end

unless install_destdir.empty?
  lib_dir = File.join install_destdir, lib_dir
  bin_dir = File.join install_destdir, bin_dir
end

mkdir_p lib_dir
mkdir_p bin_dir

Dir.chdir 'lib' do
  lib_files = Dir[File.join('**', '*rb')]

  lib_files.each do |lib_file|
    dest_file = File.join lib_dir, lib_file
    dest_dir = File.dirname dest_file
    mkdir_p dest_dir unless File.directory? dest_dir

    install lib_file, dest_file, :mode => 0644
  end
end

bin_file_names = []

Dir.chdir 'bin' do
  bin_files = Dir['*']

  bin_files.delete 'update_rubygems'

  bin_files.each do |bin_file|
    bin_file_formatted = if format_executable then
                           Gem.default_exec_format % bin_file
                         else
                           bin_file
                         end

    dest_file = File.join bin_dir, bin_file_formatted
    bin_tmp_file = File.join Dir.tmpdir, bin_file

    begin
      cp bin_file, bin_tmp_file
      bin = File.readlines bin_tmp_file
      bin[0] = "#!#{Gem.ruby}\n"

      File.open bin_tmp_file, 'w' do |fp|
        fp.puts bin.join
      end

      install bin_tmp_file, dest_file, :mode => 0755
      bin_file_names << dest_file
    ensure
      rm bin_tmp_file
    end

    next unless Gem.win_platform?

    begin
      bin_cmd_file = File.join Dir.tmpdir, "#{bin_file}.bat"

      File.open bin_cmd_file, 'w' do |file|
        file.puts <<-TEXT
@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"#{File.basename(Gem.ruby)}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"#{File.basename(Gem.ruby)}" "%~dpn0" %*
TEXT
      end

      install bin_cmd_file, "#{dest_file}.bat", :mode => 0755
    ensure
      rm bin_cmd_file
    end
  end
end

# Replace old bin files with ones that abort.

old_bin_files = {
  'gem_mirror' => 'gem mirror',
  'gem_server' => 'gem server',
  'gemlock' => 'gem lock',
  'gemri' => 'ri',
  'gemwhich' => 'gem which',
  'index_gem_repository.rb' => 'gem generate_index',
}

old_bin_files.each do |old_bin_file, new_name|
  old_bin_path = File.join bin_dir, old_bin_file
  next unless File.exist? old_bin_path

  deprecation_message = "`#{old_bin_file}` has been deprecated.  Use `#{new_name}` instead."

  File.open old_bin_path, 'w' do |fp|
    fp.write <<-EOF
#!#{Gem.ruby}

abort "#{deprecation_message}"
    EOF
  end

  next unless Gem.win_platform?

  File.open "#{old_bin_path}.bat", 'w' do |fp|
    fp.puts %{@ECHO.#{deprecation_message}}
  end
end

# Remove source caches
if install_destdir.empty?
  require 'rubygems/source_info_cache'

  user_cache_file = File.join(install_destdir,
                              Gem::SourceInfoCache.user_cache_file)
  system_cache_file = File.join(install_destdir,
                                Gem::SourceInfoCache.system_cache_file)

  rm_f user_cache_file if File.writable? File.dirname(user_cache_file)
  rm_f system_cache_file if File.writable? File.dirname(system_cache_file)
end

# install RDoc

gem_doc_dir = File.join Gem.dir, 'doc'
rubygems_name = "rubygems-#{Gem::RubyGemsVersion}"
rubygems_doc_dir = File.join gem_doc_dir, rubygems_name

if File.writable? gem_doc_dir and
   (not File.exist? rubygems_doc_dir or
    File.writable? rubygems_doc_dir) then
  puts "Removing old RubyGems RDoc and ri"
  Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
    rm_rf dir
  end

  def run_rdoc(*args)
    begin
      gem 'rdoc'
    rescue Gem::LoadError
    end

    require 'rdoc/rdoc'

    args << '--quiet'
    args << '--main' << 'README'
    args << '.' << 'README' << 'LICENSE.txt' << 'GPL.txt'

    r = RDoc::RDoc.new
    r.document args
  end

  if ri then
    ri_dir = File.join rubygems_doc_dir, 'ri'
    puts "Installing #{rubygems_name} ri into #{ri_dir}"
    run_rdoc '--ri', '--op', ri_dir
  end

  if rdoc then
    rdoc_dir = File.join rubygems_doc_dir, 'rdoc'
    puts "Installing #{rubygems_name} rdoc into #{rdoc_dir}"
    run_rdoc '--op', rdoc_dir
  end
else
  puts "Skipping RDoc generation, #{gem_doc_dir} not writable"
  puts "Set the GEM_HOME environment variable if you want RDoc generated"
end

puts
puts "-" * 78
puts

release_notes = File.join File.dirname(__FILE__), 'doc', 'release_notes',
                          "rel_#{Gem::RubyGemsVersion.gsub '.', '_'}.rdoc"

if File.exist? release_notes then
  puts File.read(release_notes)
else
  puts "Oh-no! Unable to find release notes in:\n\t#{release_notes}"
end

puts
puts "-" * 78
puts

puts "RubyGems installed the following executables:"
puts bin_file_names.map { |name| "\t#{name}\n" }
puts

puts "If `gem` was installed by a previous RubyGems installation, you may need"
puts "to remove it by hand."
puts