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
|
|
|
|
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
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
##
|
|
|
|
# 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_spec::
|
|
|
|
# the path to a built gem from @user_spec
|
|
|
|
#
|
|
|
|
# @installer::
|
|
|
|
# a Gem::Installer for the @spec that installs into @gemhome
|
|
|
|
# @user_installer::
|
|
|
|
# a Gem::Installer for the @user_spec that installs into Gem.user_dir
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def setup
|
|
|
|
super
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@spec = quick_gem 'a' do |spec|
|
|
|
|
util_make_exec spec
|
|
|
|
end
|
2011-01-28 18:46:47 -05:00
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@user_spec = quick_gem 'b' do |spec|
|
|
|
|
util_make_exec spec
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
util_build_gem @spec
|
|
|
|
util_build_gem @user_spec
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
@gem = @spec.cache_file
|
|
|
|
@user_gem = @user_spec.cache_file
|
2011-03-01 04:41:32 -05:00
|
|
|
|
2011-05-31 23:45:05 -04:00
|
|
|
@installer = util_installer @spec, @gemhome
|
|
|
|
@user_installer = util_installer @user_spec, Gem.user_dir, :user
|
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
|
|
|
def util_gem_bindir spec = @spec # :nodoc:
|
2011-05-31 23:45:05 -04:00
|
|
|
# TODO: deprecate
|
|
|
|
spec.bin_dir
|
2008-03-31 18:40:06 -04:00
|
|
|
end
|
|
|
|
|
2012-11-29 01:52:18 -05:00
|
|
|
def util_gem_dir spec = @spec # :nodoc:
|
2011-05-31 23:45:05 -04:00
|
|
|
# TODO: deprecate
|
|
|
|
spec.gem_dir
|
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+.
|
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
def util_make_exec(spec = @spec, shebang = "#!/usr/bin/ruby")
|
|
|
|
spec.executables = %w[executable]
|
|
|
|
spec.files << 'bin/executable'
|
|
|
|
|
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
|
|
|
|
|
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
|
|
|
|
|
2008-03-31 18:40:06 -04:00
|
|
|
def util_setup_gem(ui = @ui) # HACK fix use_ui to make this automatic
|
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')
|
2012-04-17 20:04:12 -04:00
|
|
|
File.open File.join('bin', 'executable'), 'w' do |f|
|
|
|
|
f.puts "raise 'ran executable'"
|
|
|
|
end
|
2008-03-31 18:40:06 -04:00
|
|
|
File.open File.join('lib', 'code.rb'), 'w' do |f| f.puts '1' end
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
@installer = 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
|
2012-11-29 01:52:18 -05:00
|
|
|
|