utils/gems: use Gem API rather than ENV to set paths

This commit is contained in:
Bo Anderson 2021-02-27 15:50:08 +00:00
parent 25d0987642
commit a5b12a33c2
No known key found for this signature in database
GPG Key ID: 3DB94E204E137D65
3 changed files with 16 additions and 11 deletions

View File

@ -90,12 +90,16 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
ruby_args = HOMEBREW_RUBY_EXEC_ARGS.dup
if ENV["HOMEBREW_TESTS_COVERAGE"]
simplecov_spec = Gem.loaded_specs["simplecov"]
specs = [simplecov_spec]
simplecov_spec.runtime_dependencies.each do |dep|
parallel_tests_spec = Gem.loaded_specs["parallel_tests"]
specs = []
[simplecov_spec, parallel_tests_spec].each do |spec|
specs << spec
spec.runtime_dependencies.each do |dep|
specs += dep.to_specs
rescue Gem::LoadError => e
onoe e
end
end
libs = specs.flat_map do |spec|
full_gem_path = spec.full_gem_path
# full_require_paths isn't available in RubyGems < 2.2.

View File

@ -53,17 +53,15 @@ module Homebrew
def setup_gem_environment!(gem_home: nil, gem_bindir: nil, setup_path: true)
# Match where our bundler gems are.
gem_home ||= "#{ENV["HOMEBREW_LIBRARY"]}/Homebrew/vendor/bundle/ruby/#{RbConfig::CONFIG["ruby_version"]}"
ENV["GEM_HOME"] = gem_home
ENV["GEM_PATH"] = gem_home
Gem.paths = {
"GEM_HOME" => gem_home,
"GEM_PATH" => gem_home,
}
# Set TMPDIR so Xcode's `make` doesn't fall back to `/var/tmp/`,
# which may be not user-writable.
ENV["TMPDIR"] = ENV["HOMEBREW_TEMP"]
# Make RubyGems notice environment changes.
Gem.clear_paths
Gem::Specification.reset
return unless setup_path
# Add necessary Ruby and Gem binary directories to `PATH`.

View File

@ -2,6 +2,9 @@
# typed: false
# frozen_string_literal: true
require_relative "gems"
Homebrew.setup_gem_environment!
require_relative "../warnings"
Warnings.ignore :parser_syntax do