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,11 +90,15 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
ruby_args = HOMEBREW_RUBY_EXEC_ARGS.dup ruby_args = HOMEBREW_RUBY_EXEC_ARGS.dup
if ENV["HOMEBREW_TESTS_COVERAGE"] if ENV["HOMEBREW_TESTS_COVERAGE"]
simplecov_spec = Gem.loaded_specs["simplecov"] simplecov_spec = Gem.loaded_specs["simplecov"]
specs = [simplecov_spec] parallel_tests_spec = Gem.loaded_specs["parallel_tests"]
simplecov_spec.runtime_dependencies.each do |dep| specs = []
specs += dep.to_specs [simplecov_spec, parallel_tests_spec].each do |spec|
rescue Gem::LoadError => e specs << spec
onoe e spec.runtime_dependencies.each do |dep|
specs += dep.to_specs
rescue Gem::LoadError => e
onoe e
end
end end
libs = specs.flat_map do |spec| libs = specs.flat_map do |spec|
full_gem_path = spec.full_gem_path full_gem_path = spec.full_gem_path

View File

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

View File

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