Skip to content

Commit

Permalink
Merge pull request #15955 from Bo98/newer-ruby-bootstrap
Browse files Browse the repository at this point in the history
Install gems automatically on newer Ruby
  • Loading branch information
Bo98 authored Sep 29, 2023
2 parents e1071e1 + daa49a1 commit f2c8b2e
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 29 deletions.
1 change: 1 addition & 0 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ Sorbet/StrictSigil:
Sorbet/TrueSigil:
Enabled: true
Exclude:
- "Homebrew/standalone/init.rb" # loaded before sorbet-runtime
- "Taps/**/*"
- "/**/{Formula,Casks}/**/*.rb"
- "**/{Formula,Casks}/**/*.rb"
Expand Down
8 changes: 0 additions & 8 deletions Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@

std_trap = trap("INT") { exit! 130 } # no backtrace thanks

# check ruby version before requiring any modules.
REQUIRED_RUBY_X, REQUIRED_RUBY_Y, = ENV.fetch("HOMEBREW_REQUIRED_RUBY_VERSION").split(".").map(&:to_i)
RUBY_X, RUBY_Y, = RUBY_VERSION.split(".").map(&:to_i)
if RUBY_X < REQUIRED_RUBY_X || (RUBY_X == REQUIRED_RUBY_X && RUBY_Y < REQUIRED_RUBY_Y)
raise "Homebrew must be run under Ruby #{REQUIRED_RUBY_X}.#{REQUIRED_RUBY_Y}! " \
"You're running #{RUBY_VERSION}."
end

require_relative "global"

begin
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/standalone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

# This file should be the first `require` in all entrypoints outside the `brew` environment.

require_relative "standalone/load_path"
require_relative "standalone/init"
require_relative "standalone/sorbet"
38 changes: 38 additions & 0 deletions Library/Homebrew/standalone/init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# typed: false
# frozen_string_literal: true

# This file is included before any other files. It intentionally has typing disabled and has minimal use of `require`.

required_ruby_major, required_ruby_minor, = ENV.fetch("HOMEBREW_REQUIRED_RUBY_VERSION", "").split(".").map(&:to_i)
unsupported_ruby = if required_ruby_minor.nil?
# We're probably only running rubocop etc so just assume supported
false
else
ruby_major, ruby_minor, = RUBY_VERSION.split(".").map(&:to_i)
if ruby_major < required_ruby_major || (ruby_major == required_ruby_major && ruby_minor < required_ruby_minor)
raise "Homebrew must be run under Ruby #{required_ruby_major}.#{required_ruby_minor}! " \
"You're running #{RUBY_VERSION}."
end

ruby_major != required_ruby_major || ruby_minor != required_ruby_minor
end.freeze

# We trust base Ruby to provide what we need.
# Don't look into the user-installed sitedir, which may contain older versions of RubyGems.
require "rbconfig"
$LOAD_PATH.reject! { |path| path.start_with?(RbConfig::CONFIG["sitedir"]) }

require "pathname"
HOMEBREW_LIBRARY_PATH = Pathname(__dir__).parent.realpath.freeze

require_relative "../utils/gems"
Homebrew.setup_gem_environment!(setup_path: false)

# Install gems for Rubies we don't vendor for.
Homebrew.install_bundler_gems! if unsupported_ruby

$LOAD_PATH.push HOMEBREW_LIBRARY_PATH.to_s unless $LOAD_PATH.include?(HOMEBREW_LIBRARY_PATH.to_s)
require_relative "../vendor/bundle/bundler/setup"
$LOAD_PATH.unshift "#{HOMEBREW_LIBRARY_PATH}/vendor/bundle/#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/" \
"bundler-#{Homebrew::HOMEBREW_BUNDLER_VERSION}/lib"
$LOAD_PATH.uniq!
19 changes: 0 additions & 19 deletions Library/Homebrew/standalone/load_path.rb

This file was deleted.

2 changes: 1 addition & 1 deletion Library/Homebrew/startup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# This file should be the first `require` in all entrypoints of `brew`.

require_relative "standalone/load_path"
require_relative "standalone/init"
require_relative "startup/ruby_path"
require "startup/config"
require_relative "startup/bootsnap"
Expand Down

0 comments on commit f2c8b2e

Please sign in to comment.