2018-11-02 19:07:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-08 09:32:18 -04:00
|
|
|
require_relative "path"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-15 08:31:12 -04:00
|
|
|
$LOAD_PATH.unshift(Spec::Path.source_lib_dir.to_s)
|
2020-05-08 01:19:04 -04:00
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
module Spec
|
|
|
|
module Rubygems
|
2019-11-11 03:57:45 -05:00
|
|
|
extend self
|
|
|
|
|
|
|
|
def dev_setup
|
2021-04-14 23:47:04 -04:00
|
|
|
install_gems(dev_gemfile)
|
2019-07-08 09:32:18 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
def gem_load(gem_name, bin_container)
|
2020-05-08 01:19:04 -04:00
|
|
|
require_relative "switch_rubygems"
|
2019-12-14 05:49:16 -05:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
gem_load_and_activate(gem_name, bin_container)
|
2019-07-08 09:32:18 -04:00
|
|
|
end
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
def gem_require(gem_name)
|
2019-07-08 09:32:18 -04:00
|
|
|
gem_activate(gem_name)
|
|
|
|
require gem_name
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
def test_setup
|
|
|
|
setup_test_paths
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
require "fileutils"
|
2018-11-02 19:07:56 -04:00
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
FileUtils.mkdir_p(Path.home)
|
|
|
|
FileUtils.mkdir_p(Path.tmpdir)
|
|
|
|
|
2018-11-02 19:07:56 -04:00
|
|
|
ENV["HOME"] = Path.home.to_s
|
|
|
|
ENV["TMPDIR"] = Path.tmpdir.to_s
|
|
|
|
|
2019-11-11 03:57:45 -05:00
|
|
|
require "rubygems/user_interaction"
|
2018-11-02 19:07:56 -04:00
|
|
|
Gem::DefaultUserInteraction.ui = Gem::SilentUI.new
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
def install_parallel_test_deps
|
2021-04-14 23:47:04 -04:00
|
|
|
Gem.clear_paths
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
require "parallel"
|
2021-04-14 23:47:04 -04:00
|
|
|
require "fileutils"
|
2020-05-08 01:19:04 -04:00
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
install_test_deps
|
2020-05-08 01:19:04 -04:00
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
(2..Parallel.processor_count).each do |n|
|
|
|
|
source = Path.source_root.join("tmp", "1")
|
|
|
|
destination = Path.source_root.join("tmp", n.to_s)
|
2020-05-08 01:19:04 -04:00
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
FileUtils.rm_rf destination
|
|
|
|
FileUtils.cp_r source, destination
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_test_paths
|
|
|
|
Gem.clear_paths
|
|
|
|
|
|
|
|
ENV["BUNDLE_PATH"] = nil
|
|
|
|
ENV["GEM_HOME"] = ENV["GEM_PATH"] = Path.base_system_gems.to_s
|
2020-05-15 08:31:12 -04:00
|
|
|
ENV["PATH"] = [Path.system_gem_path.join("bin"), ENV["PATH"]].join(File::PATH_SEPARATOR)
|
|
|
|
ENV["PATH"] = [Path.bindir, ENV["PATH"]].join(File::PATH_SEPARATOR) if Path.ruby_core?
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def install_test_deps
|
|
|
|
setup_test_paths
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
install_gems(test_gemfile)
|
|
|
|
install_gems(rubocop_gemfile, Path.rubocop_gems.to_s)
|
|
|
|
install_gems(standard_gemfile, Path.standard_gems.to_s)
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
2021-01-03 20:11:34 -05:00
|
|
|
def check_source_control_changes(success_message:, error_message:)
|
|
|
|
require "open3"
|
|
|
|
|
|
|
|
output, status = Open3.capture2e("git status --porcelain")
|
|
|
|
|
|
|
|
if status.success? && output.empty?
|
|
|
|
puts
|
|
|
|
puts success_message
|
|
|
|
puts
|
|
|
|
else
|
|
|
|
system("git status --porcelain")
|
|
|
|
|
|
|
|
puts
|
|
|
|
puts error_message
|
|
|
|
puts
|
|
|
|
|
|
|
|
exit(1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-15 00:20:25 -04:00
|
|
|
private
|
2019-11-11 03:57:45 -05:00
|
|
|
|
|
|
|
def gem_load_and_activate(gem_name, bin_container)
|
|
|
|
gem_activate(gem_name)
|
|
|
|
load Gem.bin_path(gem_name, bin_container)
|
|
|
|
rescue Gem::LoadError => e
|
2021-04-21 07:54:29 -04:00
|
|
|
abort "We couldn't activate #{gem_name} (#{e.requirement}). Run `gem install #{gem_name}:'#{e.requirement}'`"
|
2019-11-11 03:57:45 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def gem_activate(gem_name)
|
2020-05-08 01:19:04 -04:00
|
|
|
require "bundler"
|
|
|
|
gem_requirement = Bundler::LockfileParser.new(File.read(dev_lockfile)).dependencies[gem_name]&.requirement
|
2019-11-11 03:57:45 -05:00
|
|
|
gem gem_name, gem_requirement
|
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
def install_gems(gemfile, path = nil)
|
2020-05-08 01:19:04 -04:00
|
|
|
old_gemfile = ENV["BUNDLE_GEMFILE"]
|
|
|
|
ENV["BUNDLE_GEMFILE"] = gemfile.to_s
|
2021-04-14 23:47:04 -04:00
|
|
|
|
|
|
|
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?
|
2020-05-08 01:19:04 -04:00
|
|
|
ensure
|
2021-04-14 23:47:04 -04:00
|
|
|
if path
|
|
|
|
ENV["BUNDLE_PATH"] = old_path
|
|
|
|
else
|
|
|
|
ENV["BUNDLE_PATH__SYSTEM"] = old_path__system
|
|
|
|
end
|
|
|
|
|
2020-05-08 01:19:04 -04:00
|
|
|
ENV["BUNDLE_GEMFILE"] = old_gemfile
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_gemfile
|
2020-05-15 08:31:12 -04:00
|
|
|
Path.test_gemfile
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
2021-04-14 23:47:04 -04:00
|
|
|
def rubocop_gemfile
|
|
|
|
Path.rubocop_gemfile
|
|
|
|
end
|
|
|
|
|
|
|
|
def standard_gemfile
|
|
|
|
Path.standard_gemfile
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def dev_gemfile
|
2020-05-15 08:31:12 -04:00
|
|
|
Path.dev_gemfile
|
2020-05-08 01:19:04 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def dev_lockfile
|
|
|
|
lockfile_for(dev_gemfile)
|
|
|
|
end
|
|
|
|
|
|
|
|
def lockfile_for(gemfile)
|
|
|
|
Pathname.new("#{gemfile.expand_path}.lock")
|
2018-11-02 19:07:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|