aboutsummaryrefslogtreecommitdiffstats
path: root/spec/bundler/support/helpers.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-15 21:31:12 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-05-22 20:32:30 +0900
commitc7ebeb7eda9f7f6bbb48effe1efc026eeb64d09c (patch)
treeb516b3b5119331d4d8431b4d17f552e2c8e798fe /spec/bundler/support/helpers.rb
parentf4f157fc81b940c0f76a01ee266a08e6bba69b6b (diff)
downloadruby-c7ebeb7eda9f7f6bbb48effe1efc026eeb64d09c.tar.gz
Sync Bundler PR #3624
Diffstat (limited to 'spec/bundler/support/helpers.rb')
-rw-r--r--spec/bundler/support/helpers.rb146
1 files changed, 73 insertions, 73 deletions
diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb
index 50cf4438d9..731a2d9664 100644
--- a/spec/bundler/support/helpers.rb
+++ b/spec/bundler/support/helpers.rb
@@ -2,17 +2,25 @@
require_relative "command_execution"
require_relative "the_bundle"
+require_relative "path"
module Spec
module Helpers
+ include Spec::Path
+
def reset!
Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir|
- next if %w[base remote1 gems rubygems . ..].include?(File.basename(dir))
+ next if %w[base base_system remote1 gems rubygems . ..].include?(File.basename(dir))
FileUtils.rm_rf(dir)
end
FileUtils.mkdir_p(home)
FileUtils.mkdir_p(tmpdir)
+ reset_paths!
+ end
+
+ def reset_paths!
Bundler.reset!
+ Gem.clear_paths
end
def self.bang(method)
@@ -80,14 +88,10 @@ module Spec
with_sudo = options.delete(:sudo)
sudo = with_sudo == :preserve_env ? "sudo -E --preserve-env=RUBYOPT" : "sudo" if with_sudo
- bundle_bin = options.delete("bundle_bin") || bindir.join("bundle")
-
- if system_bundler = options.delete(:system_bundler)
- bundle_bin = system_gem_path.join("bin/bundler")
- end
+ bundle_bin = options.delete(:bundle_bin)
+ bundle_bin ||= installed_bindir.join("bundle")
env = options.delete(:env) || {}
- env["PATH"].gsub!("#{Path.root}/exe", "") if env["PATH"] && system_bundler
requires = options.delete(:requires) || []
@@ -103,7 +107,6 @@ module Spec
end
load_path = []
- load_path << lib_dir unless system_bundler
load_path << spec_dir
dir = options.delete(:dir) || bundled_app
@@ -145,12 +148,12 @@ module Spec
end
def bundler(cmd, options = {})
- options["bundle_bin"] = bindir.join("bundler")
+ options[:bundle_bin] = system_gem_path.join("bin/bundler")
bundle(cmd, options)
end
def ruby(ruby, options = {})
- ruby_cmd = build_ruby_cmd({ :load_path => options[:no_lib] ? [] : [lib_dir] })
+ ruby_cmd = build_ruby_cmd
escaped_ruby = RUBY_PLATFORM == "java" ? ruby.shellescape.dump : ruby.shellescape
sys_exec(%(#{ruby_cmd} -w -e #{escaped_ruby}), options)
end
@@ -169,8 +172,8 @@ module Spec
def build_ruby_cmd(options = {})
sudo = options.delete(:sudo)
- libs = options.delete(:load_path) || []
- lib_option = "-I#{libs.join(File::PATH_SEPARATOR)}"
+ libs = options.delete(:load_path)
+ lib_option = libs ? "-I#{libs.join(File::PATH_SEPARATOR)}" : []
requires = options.delete(:requires) || []
requires << "#{Path.spec_dir}/support/hax.rb"
@@ -180,12 +183,8 @@ module Spec
end
def gembin(cmd, options = {})
- old = ENV["RUBYOPT"]
- ENV["RUBYOPT"] = "#{ENV["RUBYOPT"]} -I#{lib_dir}"
cmd = bundled_app("bin/#{cmd}") unless cmd.to_s.include?("/")
sys_exec(cmd.to_s, options)
- ensure
- ENV["RUBYOPT"] = old
end
def gem_command(command, options = {})
@@ -328,14 +327,16 @@ module Spec
FileUtils.cp shipped_file, target_shipped_file, :preserve => true
end
- # for Ruby core repository
- if File.exist? File.join(build_path, "lib/bundler/bundler.gemspec")
- FileUtils.mv File.join(build_path, "lib/bundler/bundler.gemspec"), build_path
- end
-
replace_version_file(version, dir: build_path) # rubocop:disable Style/HashSyntax
- gem_command! "build bundler.gemspec", :dir => build_path
+ build_metadata = {
+ :built_at => loaded_gemspec.date.utc.strftime("%Y-%m-%d"),
+ :git_commit_sha => sys_exec("git rev-parse --short HEAD", :dir => source_root).strip,
+ }
+
+ replace_build_metadata(build_metadata, dir: build_path) # rubocop:disable Style/HashSyntax
+
+ gem_command! "build #{relative_gemspec}", :dir => build_path
yield(bundler_path)
ensure
@@ -344,19 +345,24 @@ module Spec
end
def with_gem_path_as(path)
- backup = ENV.to_hash
- ENV["GEM_HOME"] = path.to_s
- ENV["GEM_PATH"] = path.to_s
- ENV["BUNDLER_ORIG_GEM_PATH"] = nil
- yield
- ensure
- ENV.replace(backup)
+ without_env_side_effects do
+ ENV["GEM_HOME"] = path.to_s
+ ENV["GEM_PATH"] = path.to_s
+ ENV["BUNDLER_ORIG_GEM_PATH"] = nil
+ yield
+ end
end
def with_path_as(path)
+ without_env_side_effects do
+ ENV["PATH"] = path.to_s
+ ENV["BUNDLER_ORIG_PATH"] = nil
+ yield
+ end
+ end
+
+ def without_env_side_effects
backup = ENV.to_hash
- ENV["PATH"] = path.to_s
- ENV["BUNDLER_ORIG_PATH"] = nil
yield
ensure
ENV.replace(backup)
@@ -397,56 +403,29 @@ module Spec
with_path_added(tmp("fake_man")) { yield }
end
+ def pristine_system_gems(*gems)
+ FileUtils.rm_rf(system_gem_path)
+
+ system_gems(*gems)
+ end
+
def system_gems(*gems)
opts = gems.last.is_a?(Hash) ? gems.last : {}
path = opts.fetch(:path, system_gem_path)
gems = gems.flatten
- unless opts[:keep_path]
- FileUtils.rm_rf(path)
- FileUtils.mkdir_p(path)
- end
-
- Gem.clear_paths
-
- env_backup = ENV.to_hash
- ENV["GEM_HOME"] = path.to_s
- ENV["GEM_PATH"] = path.to_s
- ENV["BUNDLER_ORIG_GEM_PATH"] = nil
-
- install_gems(*gems)
- return unless block_given?
- begin
- yield
- ensure
- ENV.replace(env_backup)
+ with_gem_path_as(path) do
+ install_gems(*gems)
end
end
def realworld_system_gems(*gems)
gems = gems.flatten
- FileUtils.rm_rf(system_gem_path)
- FileUtils.mkdir_p(system_gem_path)
-
- Gem.clear_paths
-
- gem_home = ENV["GEM_HOME"]
- gem_path = ENV["GEM_PATH"]
- path = ENV["PATH"]
- ENV["GEM_HOME"] = system_gem_path.to_s
- ENV["GEM_PATH"] = system_gem_path.to_s
-
- gems.each do |gem|
- gem_command! "install --no-document #{gem}"
- end
- return unless block_given?
- begin
- yield
- ensure
- ENV["GEM_HOME"] = gem_home
- ENV["GEM_PATH"] = gem_path
- ENV["PATH"] = path
+ with_gem_path_as(system_gem_path) do
+ gems.each do |gem|
+ gem_command! "install --no-document #{gem}"
+ end
end
end
@@ -464,9 +443,8 @@ module Spec
end
def simulate_new_machine
- system_gems []
- FileUtils.rm_rf system_gem_path
FileUtils.rm_rf bundled_app(".bundle")
+ pristine_system_gems :bundler
end
def simulate_platform(platform)
@@ -490,12 +468,34 @@ module Spec
old = ENV["BUNDLER_SPEC_WINDOWS"]
ENV["BUNDLER_SPEC_WINDOWS"] = "true"
simulate_platform platform do
- yield
+ simulate_bundler_version_when_missing_prerelease_default_gem_activation do
+ yield
+ end
end
ensure
ENV["BUNDLER_SPEC_WINDOWS"] = old
end
+ # workaround for missing https://github.com/rubygems/rubygems/commit/929e92d752baad3a08f3ac92eaec162cb96aedd1
+ def simulate_bundler_version_when_missing_prerelease_default_gem_activation
+ return yield unless Gem.rubygems_version < Gem::Version.new("3.1.0.pre.1")
+
+ old = ENV["BUNDLER_VERSION"]
+ ENV["BUNDLER_VERSION"] = Bundler::VERSION
+ yield
+ ensure
+ ENV["BUNDLER_VERSION"] = old
+ end
+
+ # workaround for missing https://github.com/rubygems/rubygems/commit/929e92d752baad3a08f3ac92eaec162cb96aedd1
+ def env_for_missing_prerelease_default_gem_activation
+ if Gem.rubygems_version < Gem::Version.new("3.1.0.pre.1")
+ { "BUNDLER_VERSION" => Bundler::VERSION }
+ else
+ {}
+ end
+ end
+
def revision_for(path)
sys_exec("git rev-parse HEAD", :dir => path).strip
end