2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2011-01-28 18:46:47 -05:00
|
|
|
require 'rubygems/test_case'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/installer'
|
|
|
|
|
|
|
|
class Gem::Installer
|
2011-01-28 18:46:47 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
attr_writer :bin_dir
|
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
|
|
|
attr_writer :build_args
|
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
attr_writer :gem_dir
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
attr_writer :force
|
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_writer :format
|
2011-01-28 18:46:47 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_writer :gem_home
|
2011-01-28 18:46:47 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_writer :env_shebang
|
2011-01-28 18:46:47 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_writer :ignore_dependencies
|
2011-01-28 18:46:47 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_writer :format_executable
|
2011-01-28 18:46:47 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_writer :security_policy
|
2011-01-28 18:46:47 -05:00
|
|
|
|
|
|
|
##
|
|
|
|
# Available through requiring rubygems/installer_test_case
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
attr_writer :wrappers
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2011-01-28 18:46:47 -05:00
|
|
|
##
|
|
|
|
# A test case for Gem::Installer.
|
|
|
|
|
|
|
|
class Gem::InstallerTestCase < Gem::TestCase
|
2008-03-31 18:40:06 -04:00
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
Gem::Installer.path_warning = false
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# The path where installed executables live
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def util_inst_bindir
|
|
|
|
File.join @gemhome, "bin"
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# Adds an executable named "executable" to +spec+ with the given +shebang+.
|
|
|
|
#
|
|
|
|
# The executable is also written to the bin dir in @tmpdir and the installed
|
|
|
|
# gem directory for +spec+.
|
|
|
|
|
2019-03-04 22:32:58 -05:00
|
|
|
def util_make_exec(spec = @spec, shebang = "#!/usr/bin/ruby", bindir = "bin")
|
2011-03-01 04:41:32 -05:00
|
|
|
spec.executables = %w[executable]
|
2019-03-04 22:32:58 -05:00
|
|
|
spec.bindir = bindir
|
2011-03-01 04:41:32 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
exec_path = spec.bin_file "executable"
|
|
|
|
write_file exec_path do |io|
|
2011-03-01 04:41:32 -05:00
|
|
|
io.puts shebang
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
bin_path = File.join @tempdir, "bin", "executable"
|
|
|
|
write_file bin_path do |io|
|
2011-03-01 04:41:32 -05:00
|
|
|
io.puts shebang
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
##
|
|
|
|
# Creates the following instance variables:
|
|
|
|
#
|
|
|
|
# @spec::
|
|
|
|
# a spec named 'a', intended for regular installs
|
|
|
|
#
|
|
|
|
# @gem::
|
|
|
|
# the path to a built gem from @spec
|
|
|
|
#
|
|
|
|
# And returns a Gem::Installer for the @spec that installs into @gemhome
|
|
|
|
|
|
|
|
def setup_base_installer
|
|
|
|
@gem = setup_base_gem
|
|
|
|
util_installer @spec, @gemhome
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates the following instance variables:
|
|
|
|
#
|
|
|
|
# @spec::
|
|
|
|
# a spec named 'a', intended for regular installs
|
|
|
|
#
|
|
|
|
# And returns a gem built for the @spec
|
|
|
|
|
|
|
|
def setup_base_gem
|
|
|
|
@spec = setup_base_spec
|
|
|
|
util_build_gem @spec
|
|
|
|
@spec.cache_file
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Sets up a generic specification for testing the rubygems installer
|
|
|
|
#
|
|
|
|
# And returns it
|
|
|
|
|
|
|
|
def setup_base_spec
|
|
|
|
quick_gem 'a' do |spec|
|
|
|
|
util_make_exec spec
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Creates the following instance variables:
|
|
|
|
#
|
|
|
|
# @spec::
|
|
|
|
# a spec named 'a', intended for regular installs
|
|
|
|
# @user_spec::
|
|
|
|
# a spec named 'b', intended for user installs
|
|
|
|
#
|
|
|
|
# @gem::
|
|
|
|
# the path to a built gem from @spec
|
|
|
|
# @user_gem::
|
|
|
|
# the path to a built gem from @user_spec
|
|
|
|
#
|
|
|
|
# And returns a Gem::Installer for the @user_spec that installs into Gem.user_dir
|
|
|
|
|
|
|
|
def setup_base_user_installer
|
|
|
|
@user_spec = quick_gem 'b' do |spec|
|
|
|
|
util_make_exec spec
|
|
|
|
end
|
|
|
|
|
|
|
|
util_build_gem @user_spec
|
|
|
|
|
|
|
|
@user_gem = @user_spec.cache_file
|
|
|
|
|
|
|
|
util_installer @user_spec, Gem.user_dir, :user
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Sets up the base @gem, builds it and returns an installer for it.
|
|
|
|
#
|
|
|
|
def util_setup_installer
|
|
|
|
@gem = setup_base_gem
|
|
|
|
|
|
|
|
util_setup_gem
|
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# Builds the @spec gem and returns an installer for it. The built gem
|
|
|
|
# includes:
|
|
|
|
#
|
|
|
|
# bin/executable
|
|
|
|
# lib/code.rb
|
|
|
|
# ext/a/mkrf_conf.rb
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
def util_setup_gem(ui = @ui)
|
2011-03-01 04:41:32 -05:00
|
|
|
@spec.files << File.join('lib', 'code.rb')
|
2008-03-31 18:40:06 -04:00
|
|
|
@spec.extensions << File.join('ext', 'a', 'mkrf_conf.rb')
|
|
|
|
|
|
|
|
Dir.chdir @tempdir do
|
|
|
|
FileUtils.mkdir_p 'bin'
|
|
|
|
FileUtils.mkdir_p 'lib'
|
|
|
|
FileUtils.mkdir_p File.join('ext', 'a')
|
2019-02-14 07:59:03 -05:00
|
|
|
|
2012-04-17 20:04:12 -04:00
|
|
|
File.open File.join('bin', 'executable'), 'w' do |f|
|
|
|
|
f.puts "raise 'ran executable'"
|
|
|
|
end
|
2019-02-14 07:59:03 -05:00
|
|
|
|
|
|
|
File.open File.join('lib', 'code.rb'), 'w' do |f|
|
|
|
|
f.puts '1'
|
|
|
|
end
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
File.open File.join('ext', 'a', 'mkrf_conf.rb'), 'w' do |f|
|
|
|
|
f << <<-EOF
|
|
|
|
File.open 'Rakefile', 'w' do |rf| rf.puts "task :default" end
|
|
|
|
EOF
|
|
|
|
end
|
|
|
|
|
2016-03-27 22:26:39 -04:00
|
|
|
yield @spec if block_given?
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
use_ui ui do
|
2012-11-29 01:52:18 -05:00
|
|
|
FileUtils.rm_f @gem
|
2011-05-31 23:45:05 -04:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@gem = Gem::Package.build @spec
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-06-01 05:45:11 -04:00
|
|
|
Gem::Installer.at @gem
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# Creates an installer for +spec+ that will install into +gem_home+. If
|
|
|
|
# +user+ is true a user-install will be performed.
|
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
def util_installer(spec, gem_home, user=false)
|
2015-07-01 17:50:14 -04:00
|
|
|
Gem::Installer.at(spec.cache_file,
|
2012-11-29 01:52:18 -05:00
|
|
|
:install_dir => gem_home,
|
|
|
|
:user_install => user)
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2012-11-29 01:52:18 -05:00
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|