diff options
author | Hiroshi SHIBATA <[email protected]> | 2021-04-15 12:47:04 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <[email protected]> | 2021-04-15 15:36:15 +0900 |
commit | ed149dbf46d1a8b16e6de9c3dbbcc10f72c9c019 (patch) | |
tree | 1c8c755fa592e280dc7718dc8a9317d1ac368394 /spec/bundler/support | |
parent | 0d9496f924d36534bd524791554d49dc0026b0e0 (diff) |
Merge the master branch of Bundler
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4383
Diffstat (limited to 'spec/bundler/support')
-rw-r--r-- | spec/bundler/support/builders.rb | 44 | ||||
-rw-r--r-- | spec/bundler/support/bundle.rb | 8 | ||||
-rw-r--r-- | spec/bundler/support/hax.rb | 2 | ||||
-rw-r--r-- | spec/bundler/support/helpers.rb | 4 | ||||
-rw-r--r-- | spec/bundler/support/matchers.rb | 51 | ||||
-rw-r--r-- | spec/bundler/support/path.rb | 40 | ||||
-rw-r--r-- | spec/bundler/support/rubygems_ext.rb | 69 |
7 files changed, 127 insertions, 91 deletions
diff --git a/spec/bundler/support/builders.rb b/spec/bundler/support/builders.rb index c76c3f505e..d593ced27e 100644 --- a/spec/bundler/support/builders.rb +++ b/spec/bundler/support/builders.rb @@ -30,7 +30,11 @@ module Spec end def build_repo1 + rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first + build_repo gem_repo1 do + FileUtils.cp rake_path, "#{gem_repo1}/gems/" + build_gem "rack", %w[0.9.1 1.0.0] do |s| s.executables = "rackup" s.post_install_message = "Rack's post install message" @@ -150,32 +154,6 @@ module Spec build_gem "duradura", "7.0" - build_gem "with_implicit_rake_dep" do |s| - s.extensions << "Rakefile" - s.write "Rakefile", <<-RUBY - task :default do - path = File.expand_path("../lib", __FILE__) - FileUtils.mkdir_p(path) - File.open("\#{path}/implicit_rake_dep.rb", "w") do |f| - f.puts "IMPLICIT_RAKE_DEP = 'YES'" - end - end - RUBY - end - - build_gem "another_implicit_rake_dep" do |s| - s.extensions << "Rakefile" - s.write "Rakefile", <<-RUBY - task :default do - path = File.expand_path("../lib", __FILE__) - FileUtils.mkdir_p(path) - File.open("\#{path}/another_implicit_rake_dep.rb", "w") do |f| - f.puts "ANOTHER_IMPLICIT_RAKE_DEP = 'YES'" - end - end - RUBY - end - build_gem "very_simple_binary", &:add_c_extension build_gem "simple_binary", &:add_c_extension @@ -255,6 +233,13 @@ module Spec def build_repo(path, &blk) return if File.directory?(path) + + FileUtils.mkdir_p("#{path}/gems") + + update_repo(path, &blk) + end + + def check_test_gems! rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first if rake_path.nil? @@ -263,14 +248,9 @@ module Spec rake_path = Dir["#{Path.base_system_gems}/**/rake*.gem"].first end - if rake_path - FileUtils.mkdir_p("#{path}/gems") - FileUtils.cp rake_path, "#{path}/gems/" - else + if rake_path.nil? abort "Your test gems are missing! Run `rm -rf #{tmp}` and try again." end - - update_repo(path, &blk) end def update_repo(path) diff --git a/spec/bundler/support/bundle.rb b/spec/bundler/support/bundle.rb new file mode 100644 index 0000000000..bb21526d35 --- /dev/null +++ b/spec/bundler/support/bundle.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +require "rubygems" +require_relative "path" +bundler_gemspec = Spec::Path.loaded_gemspec +bundler_gemspec.instance_variable_set(:@full_gem_path, Spec::Path.source_root) +bundler_gemspec.activate if bundler_gemspec.respond_to?(:activate) +load File.expand_path("bundle", Spec::Path.bindir) diff --git a/spec/bundler/support/hax.rb b/spec/bundler/support/hax.rb index fc8e0ad55d..8fd35890ae 100644 --- a/spec/bundler/support/hax.rb +++ b/spec/bundler/support/hax.rb @@ -29,7 +29,7 @@ module Gem end # We only need this hack for rubygems versions without the BundlerVersionFinder - if Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0") + if Gem.rubygems_version < Gem::Version.new("2.7.0") @path_to_default_spec_map.delete_if do |_path, spec| spec.name == "bundler" end diff --git a/spec/bundler/support/helpers.rb b/spec/bundler/support/helpers.rb index a7cc1ce810..d896b5276e 100644 --- a/spec/bundler/support/helpers.rb +++ b/spec/bundler/support/helpers.rb @@ -10,7 +10,7 @@ module Spec def reset! Dir.glob("#{tmp}/{gems/*,*}", File::FNM_DOTMATCH).each do |dir| - next if %w[base base_system remote1 gems rubygems . ..].include?(File.basename(dir)) + next if %w[base base_system remote1 rubocop standard gems rubygems . ..].include?(File.basename(dir)) FileUtils.rm_rf(dir) end FileUtils.mkdir_p(home) @@ -130,7 +130,7 @@ module Spec def ruby(ruby, options = {}) ruby_cmd = build_ruby_cmd - escaped_ruby = RUBY_PLATFORM == "java" ? ruby.shellescape.dump : ruby.shellescape + escaped_ruby = ruby.shellescape sys_exec(%(#{ruby_cmd} -w -e #{escaped_ruby}), options) end diff --git a/spec/bundler/support/matchers.rb b/spec/bundler/support/matchers.rb index 5d129ed849..1613662981 100644 --- a/spec/bundler/support/matchers.rb +++ b/spec/bundler/support/matchers.rb @@ -114,30 +114,49 @@ module Spec match do opts = names.last.is_a?(Hash) ? names.pop : {} source = opts.delete(:source) - groups = Array(opts[:groups]) + groups = Array(opts.delete(:groups)).map(&:inspect).join(", ") opts[:raise_on_error] = false - groups << opts - @errors = names.map do |name| - name, version, platform = name.split(/\s+/) + @errors = names.map do |full_name| + name, version, platform = full_name.split(/\s+/) require_path = name == "bundler" ? "#{lib_dir}/bundler" : name.tr("-", "/") version_const = name == "bundler" ? "Bundler::VERSION" : Spec::Builders.constantize(name) - code = [] - code << "require '#{require_path}.rb'" - code << "puts #{version_const}" - run code.join("; "), *groups - actual_version, actual_platform = out.strip.split(/\s+/, 2) - unless Gem::Version.new(actual_version) == Gem::Version.new(version) + source_const = "#{Spec::Builders.constantize(name)}_SOURCE" + ruby <<~R, opts + require '#{lib_dir}/bundler' + Bundler.setup(#{groups}) + + require '#{require_path}.rb' + actual_version, actual_platform = #{version_const}.split(/\s+/, 2) + unless Gem::Version.new(actual_version) == Gem::Version.new('#{version}') + puts actual_version + exit 64 + end + unless actual_platform.to_s == '#{platform}' + puts actual_platform + exit 65 + end + require '#{require_path}/source' + exit 0 if #{source.nil?} + actual_source = #{source_const} + unless actual_source == '#{source}' + puts actual_source + exit 66 + end + R + next if exitstatus == 0 + if exitstatus == 64 + actual_version = out.split("\n").last next "#{name} was expected to be at version #{version} but was #{actual_version}" end - unless actual_platform == platform + if exitstatus == 65 + actual_platform = out.split("\n").last next "#{name} was expected to be of platform #{platform} but was #{actual_platform}" end - next unless source - source_const = "#{Spec::Builders.constantize(name)}_SOURCE" - run "require '#{require_path}/source'; puts #{source_const}", *groups - unless out.strip == source - next "Expected #{name} (#{version}) to be installed from `#{source}`, was actually from `#{out}`" + if exitstatus == 66 + actual_source = out.split("\n").last + next "Expected #{name} (#{version}) to be installed from `#{source}`, was actually from `#{actual_source}`" end + next "Command to check forgem inclusion of gem #{full_name} failed" end.compact @errors.empty? diff --git a/spec/bundler/support/path.rb b/spec/bundler/support/path.rb index 62f136aa0b..a9e9704cf9 100644 --- a/spec/bundler/support/path.rb +++ b/spec/bundler/support/path.rb @@ -6,7 +6,7 @@ require "rbconfig" module Spec module Path def source_root - @source_root ||= Pathname.new(ruby_core? ? "../../../.." : "../../..").expand_path(__FILE__) + @source_root ||= Pathname.new(ruby_core? ? "../../.." : "../..").expand_path(__dir__) end def root @@ -30,7 +30,15 @@ module Spec end def test_gemfile - @test_gemfile ||= source_root.join(ruby_core? ? "tool/bundler/test_gems.rb" : "test_gems.rb") + @test_gemfile ||= source_root.join("tool/bundler/test_gems.rb") + end + + def rubocop_gemfile + @rubocop_gemfile ||= source_root.join(rubocop_gemfile_basename) + end + + def standard_gemfile + @standard_gemfile ||= source_root.join(standard_gemfile_basename) end def dev_gemfile @@ -119,7 +127,7 @@ module Spec end def vendored_gems(path = nil) - bundled_app(*["vendor/bundle", Gem.ruby_engine, RbConfig::CONFIG["ruby_version"], path].compact) + scoped_gem_path(bundled_app("vendor/bundle")).join(*[path].compact) end def cached_gem(path) @@ -138,6 +146,14 @@ module Spec tmp.join("gems/base") end + def rubocop_gems + tmp.join("gems/rubocop") + end + + def standard_gems + tmp.join("gems/standard") + end + def file_uri_for(path) protocol = "file://" root = Gem.win_platform? ? "/" : "" @@ -178,7 +194,11 @@ module Spec end def local_gem_path(*path, base: bundled_app) - base.join(*[".bundle", Gem.ruby_engine, RbConfig::CONFIG["ruby_version"], *path].compact) + scoped_gem_path(base.join(".bundle")).join(*path) + end + + def scoped_gem_path(base) + base.join(Gem.ruby_engine, RbConfig::CONFIG["ruby_version"]) end def lib_path(*args) @@ -193,10 +213,6 @@ module Spec root.join("lib") end - def xdg_config_home - home(".config") - end - def global_plugin_gem(*args) home ".bundle", "plugin", "gems", *args end @@ -255,6 +271,14 @@ module Spec !git_root.join(".git").directory? end + def rubocop_gemfile_basename + source_root.join("tool/bundler/#{RUBY_VERSION.start_with?("2.3") ? "rubocop23_gems.rb" : "rubocop_gems.rb"}") + end + + def standard_gemfile_basename + source_root.join("tool/bundler/#{RUBY_VERSION.start_with?("2.3") ? "standard23_gems.rb" : "standard_gems.rb"}") + end + extend self end end diff --git a/spec/bundler/support/rubygems_ext.rb b/spec/bundler/support/rubygems_ext.rb index 59429884d6..ea774429c9 100644 --- a/spec/bundler/support/rubygems_ext.rb +++ b/spec/bundler/support/rubygems_ext.rb @@ -9,7 +9,7 @@ module Spec extend self def dev_setup - install_gems(dev_gemfile, dev_lockfile) + install_gems(dev_gemfile) end def gem_load(gem_name, bin_container) @@ -33,25 +33,25 @@ module Spec ENV["HOME"] = Path.home.to_s ENV["TMPDIR"] = Path.tmpdir.to_s - ENV["XDG_CONFIG_HOME"] = Path.xdg_config_home.to_s require "rubygems/user_interaction" Gem::DefaultUserInteraction.ui = Gem::SilentUI.new end def install_parallel_test_deps + Gem.clear_paths + require "parallel" + require "fileutils" - prev_env_test_number = ENV["TEST_ENV_NUMBER"] + install_test_deps - begin - Parallel.processor_count.times do |n| - ENV["TEST_ENV_NUMBER"] = (n + 1).to_s + (2..Parallel.processor_count).each do |n| + source = Path.source_root.join("tmp", "1") + destination = Path.source_root.join("tmp", n.to_s) - install_test_deps - end - ensure - ENV["TEST_ENV_NUMBER"] = prev_env_test_number + FileUtils.rm_rf destination + FileUtils.cp_r source, destination end end @@ -67,9 +67,9 @@ module Spec def install_test_deps setup_test_paths - workaround_loaded_specs_issue - - install_gems(test_gemfile, test_lockfile) + install_gems(test_gemfile) + install_gems(rubocop_gemfile, Path.rubocop_gems.to_s) + install_gems(standard_gemfile, Path.standard_gems.to_s) end def check_source_control_changes(success_message:, error_message:) @@ -94,18 +94,6 @@ module Spec private - # Some rubygems versions include loaded specs when loading gemspec stubs - # from the file system. In this situation, that makes bundler incorrectly - # assume that `rake` is already installed at `tmp/` because it's installed - # globally, and makes it skip installing it to the proper location for our - # tests. To workaround, we remove `rake` from the loaded specs when running - # under those versions, so that `bundler` does the right thing. - def workaround_loaded_specs_issue - current_rubygems_version = Gem::Version.new(Gem::VERSION) - - Gem.loaded_specs.delete("rake") if current_rubygems_version >= Gem::Version.new("3.0.0.beta2") && current_rubygems_version < Gem::Version.new("3.2.0") - end - def gem_load_and_activate(gem_name, bin_container) gem_activate(gem_name) load Gem.bin_path(gem_name, bin_container) @@ -119,14 +107,27 @@ module Spec gem gem_name, gem_requirement end - def install_gems(gemfile, lockfile) + def install_gems(gemfile, path = nil) old_gemfile = ENV["BUNDLE_GEMFILE"] ENV["BUNDLE_GEMFILE"] = gemfile.to_s - require "bundler" - definition = Bundler::Definition.build(gemfile, lockfile, nil) - definition.validate_runtime! - Bundler::Installer.install(Path.source_root, definition, :path => ENV["GEM_HOME"]) + + if path + old_path = ENV["BUNDLE_PATH"] + ENV["BUNDLE_PATH"] = path + else + old_path__system = ENV["BUNDLE_PATH__SYSTEM"] + ENV["BUNDLE_PATH__SYSTEM"] = "true" + end + + output = `#{Gem.ruby} #{File.expand_path("support/bundle.rb", Path.spec_dir)} install` + raise "Error when installing gems in #{gemfile}: #{output}" unless $?.success? ensure + if path + ENV["BUNDLE_PATH"] = old_path + else + ENV["BUNDLE_PATH__SYSTEM"] = old_path__system + end + ENV["BUNDLE_GEMFILE"] = old_gemfile end @@ -134,8 +135,12 @@ module Spec Path.test_gemfile end - def test_lockfile - lockfile_for(test_gemfile) + def rubocop_gemfile + Path.rubocop_gemfile + end + + def standard_gemfile + Path.standard_gemfile end def dev_gemfile |