2016-02-01 15:43:26 +03:00
|
|
|
# frozen_string_literal: true
|
2009-06-10 01:38:59 +04:00
|
|
|
require 'rubygems/command'
|
|
|
|
|
|
|
|
##
|
|
|
|
# Installs RubyGems itself. This command is ordinarily only available from a
|
|
|
|
# RubyGems checkout or tarball.
|
|
|
|
|
|
|
|
class Gem::Commands::SetupCommand < Gem::Command
|
2019-02-14 15:59:03 +03:00
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
HISTORY_HEADER = /^===\s*[\d.a-zA-Z]+\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/.freeze
|
|
|
|
VERSION_MATCHER = /^===\s*([\d.a-zA-Z]+)\s*\/\s*\d{4}-\d{2}-\d{2}\s*$/.freeze
|
2018-05-30 16:01:35 +03:00
|
|
|
|
2018-10-22 03:27:02 +03:00
|
|
|
ENV_PATHS = %w[/usr/bin/env /bin/env].freeze
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
def initialize
|
2011-01-19 03:08:49 +03:00
|
|
|
require 'tmpdir'
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
super 'setup', 'Install RubyGems',
|
2012-11-29 10:52:18 +04:00
|
|
|
:format_executable => true, :document => %w[ri],
|
2019-12-20 05:50:32 +03:00
|
|
|
:force => true,
|
2014-01-07 05:19:28 +04:00
|
|
|
:site_or_vendor => 'sitelibdir',
|
2017-10-08 04:32:18 +03:00
|
|
|
:destdir => '', :prefix => '', :previous_version => '',
|
2020-02-01 05:14:04 +03:00
|
|
|
:regenerate_binstubs => true,
|
|
|
|
:regenerate_plugins => true
|
2012-11-29 10:52:18 +04:00
|
|
|
|
|
|
|
add_option '--previous-version=VERSION',
|
2017-10-08 04:32:18 +03:00
|
|
|
'Previous version of RubyGems',
|
2012-11-29 10:52:18 +04:00
|
|
|
'Used for changelog processing' do |version, options|
|
|
|
|
options[:previous_version] = version
|
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
add_option '--prefix=PREFIX',
|
|
|
|
'Prefix path for installing RubyGems',
|
|
|
|
'Will not affect gem repository location' do |prefix, options|
|
|
|
|
options[:prefix] = File.expand_path prefix
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option '--destdir=DESTDIR',
|
|
|
|
'Root directory to install RubyGems into',
|
|
|
|
'Mainly used for packaging RubyGems' do |destdir, options|
|
|
|
|
options[:destdir] = File.expand_path destdir
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option '--[no-]vendor',
|
2011-03-01 12:41:32 +03:00
|
|
|
'Install into vendorlibdir not sitelibdir' do |vendor, options|
|
2014-01-07 05:19:28 +04:00
|
|
|
options[:site_or_vendor] = vendor ? 'vendorlibdir' : 'sitelibdir'
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
add_option '--[no-]format-executable',
|
|
|
|
'Makes `gem` match ruby',
|
2017-10-08 04:32:18 +03:00
|
|
|
'If Ruby is ruby18, gem will be gem18' do |value, options|
|
2009-06-10 01:38:59 +04:00
|
|
|
options[:format_executable] = value
|
|
|
|
end
|
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
add_option '--[no-]document [TYPES]', Array,
|
2017-01-24 05:38:57 +03:00
|
|
|
'Generate documentation for RubyGems',
|
2012-11-29 10:52:18 +04:00
|
|
|
'List the documentation types you wish to',
|
|
|
|
'generate. For example: rdoc,ri' do |value, options|
|
|
|
|
options[:document] = case value
|
|
|
|
when nil then %w[rdoc ri]
|
|
|
|
when false then []
|
|
|
|
else value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
add_option '--[no-]rdoc',
|
|
|
|
'Generate RDoc documentation for RubyGems' do |value, options|
|
2018-11-21 13:20:47 +03:00
|
|
|
if value
|
2012-11-29 10:52:18 +04:00
|
|
|
options[:document] << 'rdoc'
|
|
|
|
else
|
|
|
|
options[:document].delete 'rdoc'
|
|
|
|
end
|
|
|
|
|
|
|
|
options[:document].uniq!
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
add_option '--[no-]ri',
|
|
|
|
'Generate RI documentation for RubyGems' do |value, options|
|
2018-11-21 13:20:47 +03:00
|
|
|
if value
|
2012-11-29 10:52:18 +04:00
|
|
|
options[:document] << 'ri'
|
|
|
|
else
|
|
|
|
options[:document].delete 'ri'
|
|
|
|
end
|
|
|
|
|
|
|
|
options[:document].uniq!
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
2013-03-07 08:06:30 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
add_option '--[no-]regenerate-binstubs',
|
|
|
|
'Regenerate gem binstubs' do |value, options|
|
2018-10-22 03:27:02 +03:00
|
|
|
options[:regenerate_binstubs] = value
|
|
|
|
end
|
2017-10-08 04:32:18 +03:00
|
|
|
|
2020-02-01 05:14:04 +03:00
|
|
|
add_option '--[no-]regenerate-plugins',
|
|
|
|
'Regenerate gem plugins' do |value, options|
|
|
|
|
options[:regenerate_plugins] = value
|
|
|
|
end
|
|
|
|
|
2019-12-20 05:50:32 +03:00
|
|
|
add_option '-f', '--[no-]force',
|
|
|
|
'Forcefully overwrite binstubs' do |value, options|
|
|
|
|
options[:force] = value
|
|
|
|
end
|
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
add_option('-E', '--[no-]env-shebang',
|
|
|
|
'Rewrite executables with a shebang',
|
|
|
|
'of /usr/bin/env') do |value, options|
|
|
|
|
options[:env_shebang] = value
|
|
|
|
end
|
|
|
|
|
2013-03-07 08:06:30 +04:00
|
|
|
@verbose = nil
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_ruby_version
|
2019-12-13 14:19:08 +03:00
|
|
|
required_version = Gem::Requirement.new '>= 2.3.0'
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
unless required_version.satisfied_by? Gem.ruby_version
|
2009-06-10 01:38:59 +04:00
|
|
|
alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}"
|
|
|
|
terminate_interaction 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def defaults_str # :nodoc:
|
2017-10-08 04:32:18 +03:00
|
|
|
"--format-executable --document ri --regenerate-binstubs"
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def description # :nodoc:
|
|
|
|
<<-EOF
|
|
|
|
Installs RubyGems itself.
|
|
|
|
|
|
|
|
RubyGems installs RDoc for itself in GEM_HOME. By default this is:
|
|
|
|
#{Gem.dir}
|
|
|
|
|
|
|
|
If you prefer a different directory, set the GEM_HOME environment variable.
|
|
|
|
|
|
|
|
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'}
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
module MakeDirs
|
2019-04-08 02:44:49 +03:00
|
|
|
def mkdir_p(path, **opts)
|
2018-05-30 16:01:35 +03:00
|
|
|
super
|
|
|
|
(@mkdirs ||= []) << path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def execute
|
2009-12-08 10:19:09 +03:00
|
|
|
@verbose = Gem.configuration.really_verbose
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
install_destdir = options[:destdir]
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
unless install_destdir.empty?
|
2009-06-10 01:38:59 +04:00
|
|
|
ENV['GEM_HOME'] ||= File.join(install_destdir,
|
|
|
|
Gem.default_dir.gsub(/^[a-zA-Z]:/, ''))
|
|
|
|
end
|
|
|
|
|
|
|
|
check_ruby_version
|
|
|
|
|
2011-01-19 03:08:49 +03:00
|
|
|
require 'fileutils'
|
2018-11-21 13:20:47 +03:00
|
|
|
if Gem.configuration.really_verbose
|
2009-06-10 01:38:59 +04:00
|
|
|
extend FileUtils::Verbose
|
|
|
|
else
|
|
|
|
extend FileUtils
|
|
|
|
end
|
2018-05-30 16:01:35 +03:00
|
|
|
extend MakeDirs
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
lib_dir, bin_dir = make_destination_dirs install_destdir
|
|
|
|
|
|
|
|
install_lib lib_dir
|
|
|
|
|
|
|
|
install_executables bin_dir
|
|
|
|
|
|
|
|
remove_old_bin_files bin_dir
|
|
|
|
|
2012-11-30 08:30:12 +04:00
|
|
|
remove_old_lib_files lib_dir
|
|
|
|
|
2019-04-02 14:48:18 +03:00
|
|
|
install_default_bundler_gem bin_dir
|
2017-10-08 04:32:18 +03:00
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
if mode = options[:dir_mode]
|
|
|
|
@mkdirs.uniq!
|
|
|
|
File.chmod(mode, @mkdirs)
|
|
|
|
end
|
|
|
|
|
2009-12-08 10:19:09 +03:00
|
|
|
say "RubyGems #{Gem::VERSION} installed"
|
|
|
|
|
2017-11-29 01:30:28 +03:00
|
|
|
regenerate_binstubs if options[:regenerate_binstubs]
|
2020-02-01 05:14:04 +03:00
|
|
|
regenerate_plugins if options[:regenerate_plugins]
|
2017-10-08 04:32:18 +03:00
|
|
|
|
2010-02-22 05:52:35 +03:00
|
|
|
uninstall_old_gemcutter
|
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
documentation_success = install_rdoc
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
say
|
2018-11-21 13:20:47 +03:00
|
|
|
if @verbose
|
2009-12-08 10:19:09 +03:00
|
|
|
say "-" * 78
|
|
|
|
say
|
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
if options[:previous_version].empty?
|
|
|
|
options[:previous_version] = Gem::VERSION.sub(/[0-9]+$/, '0')
|
|
|
|
end
|
|
|
|
|
|
|
|
options[:previous_version] = Gem::Version.new(options[:previous_version])
|
|
|
|
|
2013-07-09 02:41:03 +04:00
|
|
|
show_release_notes
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
say
|
|
|
|
say "-" * 78
|
|
|
|
say
|
|
|
|
|
|
|
|
say "RubyGems installed the following executables:"
|
2019-12-20 05:50:32 +03:00
|
|
|
say bin_file_names.map { |name| "\t#{name}\n" }
|
2009-06-10 01:38:59 +04:00
|
|
|
say
|
|
|
|
|
2019-12-20 05:50:32 +03:00
|
|
|
unless bin_file_names.grep(/#{File::SEPARATOR}gem$/)
|
2009-06-10 01:38:59 +04:00
|
|
|
say "If `gem` was installed by a previous RubyGems installation, you may need"
|
|
|
|
say "to remove it by hand."
|
|
|
|
say
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
|
|
|
if documentation_success
|
2018-11-21 13:20:47 +03:00
|
|
|
if options[:document].include? 'rdoc'
|
2012-11-29 10:52:18 +04:00
|
|
|
say "Rdoc documentation was installed. You may now invoke:"
|
|
|
|
say " gem server"
|
|
|
|
say "and then peruse beautifully formatted documentation for your gems"
|
|
|
|
say "with your web browser."
|
|
|
|
say "If you do not wish to install this documentation in the future, use the"
|
|
|
|
say "--no-document flag, or set it as the default in your ~/.gemrc file. See"
|
|
|
|
say "'gem help env' for details."
|
|
|
|
say
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
if options[:document].include? 'ri'
|
2012-11-29 10:52:18 +04:00
|
|
|
say "Ruby Interactive (ri) documentation was installed. ri is kind of like man "
|
2017-10-08 04:32:18 +03:00
|
|
|
say "pages for Ruby libraries. You may access it like this:"
|
2012-11-29 10:52:18 +04:00
|
|
|
say " ri Classname"
|
|
|
|
say " ri Classname.class_method"
|
|
|
|
say " ri Classname#instance_method"
|
|
|
|
say "If you do not wish to install this documentation in the future, use the"
|
|
|
|
say "--no-document flag, or set it as the default in your ~/.gemrc file. See"
|
|
|
|
say "'gem help env' for details."
|
|
|
|
say
|
|
|
|
end
|
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
def install_executables(bin_dir)
|
2018-05-30 16:01:35 +03:00
|
|
|
prog_mode = options[:prog_mode] || 0755
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
executables = { 'gem' => 'bin' }
|
|
|
|
executables.each do |tool, path|
|
|
|
|
say "Installing #{tool} executable" if @verbose
|
2016-09-28 04:16:43 +03:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
Dir.chdir path do
|
|
|
|
bin_files = Dir['*']
|
2016-09-28 04:16:43 +03:00
|
|
|
|
2019-04-02 14:48:18 +03:00
|
|
|
bin_files -= %w[update_rubygems]
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
bin_files.each do |bin_file|
|
2019-12-20 05:50:32 +03:00
|
|
|
dest_file = target_bin_path(bin_dir, bin_file)
|
2017-10-08 04:32:18 +03:00
|
|
|
bin_tmp_file = File.join Dir.tmpdir, "#{bin_file}.#{$$}"
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
begin
|
|
|
|
bin = File.readlines bin_file
|
2018-05-30 16:01:35 +03:00
|
|
|
bin[0] = shebang
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
File.open bin_tmp_file, 'w' do |fp|
|
|
|
|
fp.puts bin.join
|
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
install bin_tmp_file, dest_file, :mode => prog_mode
|
2019-12-20 05:50:32 +03:00
|
|
|
bin_file_names << dest_file
|
2017-10-08 04:32:18 +03:00
|
|
|
ensure
|
|
|
|
rm bin_tmp_file
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
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).chomp('"')}" "#{dest_file}" %1 %2 %3 %4 %5 %6 %7 %8 %9
|
|
|
|
GOTO :EOF
|
|
|
|
:WinNT
|
|
|
|
@"#{File.basename(Gem.ruby).chomp('"')}" "%~dpn0" %*
|
|
|
|
TEXT
|
|
|
|
end
|
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
install bin_cmd_file, "#{dest_file}.bat", :mode => prog_mode
|
2017-10-08 04:32:18 +03:00
|
|
|
ensure
|
|
|
|
rm bin_cmd_file
|
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
def shebang
|
|
|
|
if options[:env_shebang]
|
|
|
|
ruby_name = RbConfig::CONFIG['ruby_install_name']
|
|
|
|
@env_path ||= ENV_PATHS.find {|env_path| File.executable? env_path }
|
|
|
|
"#!#{@env_path} #{ruby_name}\n"
|
|
|
|
else
|
|
|
|
"#!#{Gem.ruby}\n"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def install_file(file, dest_dir)
|
2013-03-07 08:06:30 +04:00
|
|
|
dest_file = File.join dest_dir, file
|
|
|
|
dest_dir = File.dirname dest_file
|
2018-05-30 16:01:35 +03:00
|
|
|
unless File.directory? dest_dir
|
2018-12-23 03:20:49 +03:00
|
|
|
mkdir_p dest_dir, :mode => 0755
|
2018-05-30 16:01:35 +03:00
|
|
|
end
|
2013-03-07 08:06:30 +04:00
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
install file, dest_file, :mode => options[:data_mode] || 0644
|
2013-03-07 08:06:30 +04:00
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def install_lib(lib_dir)
|
2017-10-08 04:32:18 +03:00
|
|
|
libs = { 'RubyGems' => 'lib' }
|
2019-04-26 14:26:21 +03:00
|
|
|
libs['Bundler'] = 'bundler/lib'
|
2017-10-08 04:32:18 +03:00
|
|
|
libs.each do |tool, path|
|
|
|
|
say "Installing #{tool}" if @verbose
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
lib_files = rb_files_in path
|
2017-11-09 03:42:19 +03:00
|
|
|
lib_files.concat(template_files) if tool == 'Bundler'
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
pem_files = pem_files_in path
|
2016-09-28 04:16:43 +03:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
Dir.chdir path do
|
|
|
|
lib_files.each do |lib_file|
|
|
|
|
install_file lib_file, lib_dir
|
|
|
|
end
|
2016-09-28 04:16:43 +03:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
pem_files.each do |pem_file|
|
|
|
|
install_file pem_file, lib_dir
|
|
|
|
end
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def install_rdoc
|
|
|
|
gem_doc_dir = File.join Gem.dir, 'doc'
|
2010-04-22 12:24:42 +04:00
|
|
|
rubygems_name = "rubygems-#{Gem::VERSION}"
|
2009-06-10 01:38:59 +04:00
|
|
|
rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
|
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
begin
|
|
|
|
Gem.ensure_gem_subdirectories Gem.dir
|
|
|
|
rescue SystemCallError
|
|
|
|
# ignore
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
if File.writable? gem_doc_dir and
|
|
|
|
(not File.exist? rubygems_doc_dir or
|
2018-11-21 13:20:47 +03:00
|
|
|
File.writable? rubygems_doc_dir)
|
2009-12-08 10:19:09 +03:00
|
|
|
say "Removing old RubyGems RDoc and ri" if @verbose
|
2009-06-10 01:38:59 +04:00
|
|
|
Dir[File.join(Gem.dir, 'doc', 'rubygems-[0-9]*')].each do |dir|
|
|
|
|
rm_rf dir
|
|
|
|
end
|
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
require 'rubygems/rdoc'
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2012-11-29 10:52:18 +04:00
|
|
|
fake_spec = Gem::Specification.new 'rubygems', Gem::VERSION
|
|
|
|
def fake_spec.full_gem_path
|
|
|
|
File.expand_path '../../../..', __FILE__
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
|
|
|
generate_ri = options[:document].include? 'ri'
|
|
|
|
generate_rdoc = options[:document].include? 'rdoc'
|
|
|
|
|
|
|
|
rdoc = Gem::RDoc.new fake_spec, generate_rdoc, generate_ri
|
|
|
|
rdoc.generate
|
|
|
|
|
|
|
|
return true
|
2018-11-21 13:20:47 +03:00
|
|
|
elsif @verbose
|
2009-06-10 01:38:59 +04:00
|
|
|
say "Skipping RDoc generation, #{gem_doc_dir} not writable"
|
|
|
|
say "Set the GEM_HOME environment variable if you want RDoc generated"
|
|
|
|
end
|
2012-11-29 10:52:18 +04:00
|
|
|
|
|
|
|
return false
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
2019-04-02 14:48:18 +03:00
|
|
|
def install_default_bundler_gem(bin_dir)
|
2019-07-22 15:31:10 +03:00
|
|
|
specs_dir = Gem.default_specifications_dir
|
2018-02-16 11:08:06 +03:00
|
|
|
specs_dir = File.join(options[:destdir], specs_dir) unless Gem.win_platform?
|
2018-12-23 03:20:49 +03:00
|
|
|
mkdir_p specs_dir, :mode => 0755
|
2017-11-06 05:02:04 +03:00
|
|
|
|
2017-11-09 03:42:19 +03:00
|
|
|
# Workaround for non-git environment.
|
2017-11-29 01:30:28 +03:00
|
|
|
gemspec = File.open('bundler/bundler.gemspec', 'rb'){|f| f.read.gsub(/`git ls-files -z`/, "''") }
|
2017-11-09 03:42:19 +03:00
|
|
|
File.open('bundler/bundler.gemspec', 'w'){|f| f.write gemspec }
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
bundler_spec = Gem::Specification.load("bundler/bundler.gemspec")
|
2017-11-06 05:02:04 +03:00
|
|
|
bundler_spec.files = Dir.chdir("bundler") { Dir["{*.md,{lib,exe,man}/**/*}"] }
|
2017-10-08 04:32:18 +03:00
|
|
|
bundler_spec.executables -= %w[bundler bundle_ruby]
|
2018-02-06 05:58:35 +03:00
|
|
|
|
|
|
|
# Remove bundler-*.gemspec in default specification directory.
|
|
|
|
Dir.entries(specs_dir).
|
2017-10-08 04:32:18 +03:00
|
|
|
select {|gs| gs.start_with?("bundler-") }.
|
2018-02-06 05:58:35 +03:00
|
|
|
each {|gs| File.delete(File.join(specs_dir, gs)) }
|
2017-10-08 04:32:18 +03:00
|
|
|
|
2018-02-06 05:58:35 +03:00
|
|
|
default_spec_path = File.join(specs_dir, "#{bundler_spec.full_name}.gemspec")
|
2017-10-08 04:32:18 +03:00
|
|
|
Gem.write_binary(default_spec_path, bundler_spec.to_ruby)
|
|
|
|
|
|
|
|
bundler_spec = Gem::Specification.load(default_spec_path)
|
|
|
|
|
2018-02-06 05:58:35 +03:00
|
|
|
# Remove gemspec that was same version of vendored bundler.
|
|
|
|
normal_gemspec = File.join(Gem.default_dir, "specifications", "bundler-#{bundler_spec.version}.gemspec")
|
|
|
|
if File.file? normal_gemspec
|
|
|
|
File.delete normal_gemspec
|
|
|
|
end
|
|
|
|
|
|
|
|
# Remove gem files that were same version of vendored bundler.
|
2017-11-29 01:30:28 +03:00
|
|
|
if File.directory? bundler_spec.gems_dir
|
|
|
|
Dir.entries(bundler_spec.gems_dir).
|
2018-02-06 05:58:35 +03:00
|
|
|
select {|default_gem| File.basename(default_gem) == "bundler-#{bundler_spec.version}" }.
|
2017-11-29 01:30:28 +03:00
|
|
|
each {|default_gem| rm_r File.join(bundler_spec.gems_dir, default_gem) }
|
|
|
|
end
|
2017-10-08 04:32:18 +03:00
|
|
|
|
2018-05-18 04:39:13 +03:00
|
|
|
bundler_bin_dir = bundler_spec.bin_dir
|
2018-02-16 11:08:06 +03:00
|
|
|
bundler_bin_dir = File.join(options[:destdir], bundler_bin_dir) unless Gem.win_platform?
|
2018-12-23 03:20:49 +03:00
|
|
|
mkdir_p bundler_bin_dir, :mode => 0755
|
2018-02-06 05:58:35 +03:00
|
|
|
bundler_spec.executables.each do |e|
|
|
|
|
cp File.join("bundler", bundler_spec.bindir, e), File.join(bundler_bin_dir, e)
|
|
|
|
end
|
2017-11-06 05:02:04 +03:00
|
|
|
|
2019-04-02 14:48:18 +03:00
|
|
|
require 'rubygems/installer'
|
2017-11-29 01:30:28 +03:00
|
|
|
|
2019-04-02 14:48:18 +03:00
|
|
|
Dir.chdir("bundler") do
|
|
|
|
built_gem = Gem::Package.build(bundler_spec)
|
2019-04-26 14:26:21 +03:00
|
|
|
begin
|
2019-12-20 05:50:32 +03:00
|
|
|
installer = Gem::Installer.at(built_gem, env_shebang: options[:env_shebang], format_executable: options[:format_executable], force: options[:force], install_as_default: true, bin_dir: bin_dir, wrappers: true)
|
2019-04-26 14:26:21 +03:00
|
|
|
installer.install
|
|
|
|
ensure
|
|
|
|
FileUtils.rm_f built_gem
|
|
|
|
end
|
2017-11-29 01:30:28 +03:00
|
|
|
end
|
|
|
|
|
2019-12-20 05:50:32 +03:00
|
|
|
bundler_spec.executables.each {|executable| bin_file_names << target_bin_path(bin_dir, executable) }
|
|
|
|
|
2017-11-06 05:02:04 +03:00
|
|
|
say "Bundler #{bundler_spec.version} installed"
|
2017-10-08 04:32:18 +03:00
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def make_destination_dirs(install_destdir)
|
2012-04-18 04:04:12 +04:00
|
|
|
lib_dir, bin_dir = Gem.default_rubygems_dirs
|
2009-06-10 01:38:59 +04:00
|
|
|
|
2012-04-18 04:04:12 +04:00
|
|
|
unless lib_dir
|
|
|
|
lib_dir, bin_dir = generate_default_dirs(install_destdir)
|
|
|
|
end
|
|
|
|
|
2018-12-23 03:20:49 +03:00
|
|
|
mkdir_p lib_dir, :mode => 0755
|
|
|
|
mkdir_p bin_dir, :mode => 0755
|
2012-04-18 04:04:12 +04:00
|
|
|
|
|
|
|
return lib_dir, bin_dir
|
|
|
|
end
|
|
|
|
|
|
|
|
def generate_default_dirs(install_destdir)
|
2009-06-10 01:38:59 +04:00
|
|
|
prefix = options[:prefix]
|
|
|
|
site_or_vendor = options[:site_or_vendor]
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
if prefix.empty?
|
2014-01-07 05:19:28 +04:00
|
|
|
lib_dir = RbConfig::CONFIG[site_or_vendor]
|
|
|
|
bin_dir = RbConfig::CONFIG['bindir']
|
2009-06-10 01:38:59 +04:00
|
|
|
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.
|
2014-01-07 05:19:28 +04:00
|
|
|
(prefix == RbConfig::CONFIG['libdir'] or
|
2009-06-10 01:38:59 +04:00
|
|
|
# this one is important
|
2018-11-21 13:20:47 +03:00
|
|
|
prefix == File.join(RbConfig::CONFIG['libdir'], 'ruby'))
|
2018-08-27 13:05:04 +03:00
|
|
|
lib_dir = RbConfig::CONFIG[site_or_vendor]
|
|
|
|
bin_dir = RbConfig::CONFIG['bindir']
|
2009-06-10 01:38:59 +04:00
|
|
|
else
|
|
|
|
lib_dir = File.join prefix, 'lib'
|
|
|
|
bin_dir = File.join prefix, 'bin'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
unless install_destdir.empty?
|
2009-06-10 01:38:59 +04:00
|
|
|
lib_dir = File.join install_destdir, lib_dir.gsub(/^[a-zA-Z]:/, '')
|
|
|
|
bin_dir = File.join install_destdir, bin_dir.gsub(/^[a-zA-Z]:/, '')
|
|
|
|
end
|
|
|
|
|
2012-04-18 04:04:12 +04:00
|
|
|
[lib_dir, bin_dir]
|
2009-06-10 01:38:59 +04:00
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def pem_files_in(dir)
|
2013-03-07 08:06:30 +04:00
|
|
|
Dir.chdir dir do
|
|
|
|
Dir[File.join('**', '*pem')]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def rb_files_in(dir)
|
2012-11-30 08:30:12 +04:00
|
|
|
Dir.chdir dir do
|
|
|
|
Dir[File.join('**', '*rb')]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-09 03:42:19 +03:00
|
|
|
# for installation of bundler as default gems
|
|
|
|
def template_files
|
|
|
|
Dir.chdir "bundler/lib" do
|
2017-11-29 01:30:28 +03:00
|
|
|
(Dir[File.join('bundler', 'templates', '**', '{*,.*}')]).
|
2017-11-09 03:42:19 +03:00
|
|
|
select{|f| !File.directory?(f)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# for cleanup old bundler files
|
2018-11-21 13:20:47 +03:00
|
|
|
def template_files_in(dir)
|
2017-11-09 03:42:19 +03:00
|
|
|
Dir.chdir dir do
|
2017-11-29 01:30:28 +03:00
|
|
|
(Dir[File.join('templates', '**', '{*,.*}')]).
|
2017-11-09 03:42:19 +03:00
|
|
|
select{|f| !File.directory?(f)}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-06-10 01:38:59 +04:00
|
|
|
def remove_old_bin_files(bin_dir)
|
|
|
|
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
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
deprecation_message = "`#{old_bin_file}` has been deprecated. Use `#{new_name}` instead."
|
2009-06-10 01:38:59 +04:00
|
|
|
|
|
|
|
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
|
|
|
|
end
|
|
|
|
|
2018-11-21 13:20:47 +03:00
|
|
|
def remove_old_lib_files(lib_dir)
|
2017-10-08 04:32:18 +03:00
|
|
|
lib_dirs = { File.join(lib_dir, 'rubygems') => 'lib/rubygems' }
|
2019-04-26 14:26:21 +03:00
|
|
|
lib_dirs[File.join(lib_dir, 'bundler')] = 'bundler/lib/bundler'
|
2017-10-08 04:32:18 +03:00
|
|
|
lib_dirs.each do |old_lib_dir, new_lib_dir|
|
|
|
|
lib_files = rb_files_in(new_lib_dir)
|
2017-11-09 03:42:19 +03:00
|
|
|
lib_files.concat(template_files_in(new_lib_dir)) if new_lib_dir =~ /bundler/
|
2012-11-30 08:30:12 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
old_lib_files = rb_files_in(old_lib_dir)
|
2017-11-09 03:42:19 +03:00
|
|
|
old_lib_files.concat(template_files_in(old_lib_dir)) if old_lib_dir =~ /bundler/
|
2012-11-30 08:30:12 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
to_remove = old_lib_files - lib_files
|
2012-11-30 08:30:12 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
to_remove.delete_if do |file|
|
|
|
|
file.start_with? 'defaults'
|
|
|
|
end
|
2013-03-12 01:29:32 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
Dir.chdir old_lib_dir do
|
|
|
|
to_remove.each do |file|
|
|
|
|
FileUtils.rm_f file
|
2012-11-30 08:30:12 +04:00
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
warn "unable to remove old file #{file} please remove it by hand" if
|
|
|
|
File.exist? file
|
|
|
|
end
|
2012-11-30 08:30:12 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-07-09 02:41:03 +04:00
|
|
|
def show_release_notes
|
|
|
|
release_notes = File.join Dir.pwd, 'History.txt'
|
|
|
|
|
|
|
|
release_notes =
|
2018-11-21 13:20:47 +03:00
|
|
|
if File.exist? release_notes
|
2013-07-09 02:41:03 +04:00
|
|
|
history = File.read release_notes
|
|
|
|
|
2018-05-30 16:01:35 +03:00
|
|
|
history.force_encoding Encoding::UTF_8
|
2013-07-09 02:41:03 +04:00
|
|
|
|
2014-09-14 07:30:02 +04:00
|
|
|
history = history.sub(/^# coding:.*?(?=^=)/m, '')
|
2013-07-09 02:41:03 +04:00
|
|
|
|
|
|
|
text = history.split(HISTORY_HEADER)
|
|
|
|
text.shift # correct an off-by-one generated by split
|
|
|
|
version_lines = history.scan(HISTORY_HEADER)
|
|
|
|
versions = history.scan(VERSION_MATCHER).flatten.map do |x|
|
|
|
|
Gem::Version.new(x)
|
|
|
|
end
|
|
|
|
|
|
|
|
history_string = ""
|
|
|
|
|
|
|
|
until versions.length == 0 or
|
2019-12-20 05:50:32 +03:00
|
|
|
versions.shift <= options[:previous_version] do
|
2013-07-09 02:41:03 +04:00
|
|
|
history_string += version_lines.shift + text.shift
|
|
|
|
end
|
|
|
|
|
|
|
|
history_string
|
|
|
|
else
|
|
|
|
"Oh-no! Unable to find release notes!"
|
|
|
|
end
|
|
|
|
|
|
|
|
say release_notes
|
|
|
|
end
|
|
|
|
|
2010-02-22 05:52:35 +03:00
|
|
|
def uninstall_old_gemcutter
|
|
|
|
require 'rubygems/uninstaller'
|
|
|
|
|
|
|
|
ui = Gem::Uninstaller.new('gemcutter', :all => true, :ignore => true,
|
|
|
|
:version => '< 0.4')
|
|
|
|
ui.uninstall
|
|
|
|
rescue Gem::InstallError
|
|
|
|
end
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
def regenerate_binstubs
|
|
|
|
require "rubygems/commands/pristine_command"
|
|
|
|
say "Regenerating binstubs"
|
2018-05-30 16:01:35 +03:00
|
|
|
|
|
|
|
args = %w[--all --only-executables --silent]
|
|
|
|
if options[:env_shebang]
|
|
|
|
args << "--env-shebang"
|
|
|
|
end
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
command = Gem::Commands::PristineCommand.new
|
2018-05-30 16:01:35 +03:00
|
|
|
command.invoke(*args)
|
2017-10-08 04:32:18 +03:00
|
|
|
end
|
2016-09-28 04:16:43 +03:00
|
|
|
|
2020-02-01 05:14:04 +03:00
|
|
|
def regenerate_plugins
|
|
|
|
require "rubygems/commands/pristine_command"
|
|
|
|
say "Regenerating plugins"
|
|
|
|
|
|
|
|
args = %w[--all --only-plugins --silent]
|
|
|
|
|
|
|
|
command = Gem::Commands::PristineCommand.new
|
|
|
|
command.invoke(*args)
|
|
|
|
end
|
|
|
|
|
2019-12-20 05:50:32 +03:00
|
|
|
private
|
|
|
|
|
|
|
|
def target_bin_path(bin_dir, bin_file)
|
|
|
|
bin_file_formatted = if options[:format_executable]
|
|
|
|
Gem.default_exec_format % bin_file
|
|
|
|
else
|
|
|
|
bin_file
|
|
|
|
end
|
|
|
|
File.join bin_dir, bin_file_formatted
|
|
|
|
end
|
|
|
|
|
|
|
|
def bin_file_names
|
|
|
|
@bin_file_names ||= []
|
|
|
|
end
|
|
|
|
|
2017-10-08 04:32:18 +03:00
|
|
|
end
|