From 1f86ad4b0f2f7af0f2b39da8053b4aefa7796721 Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Fri, 29 Sep 2023 01:26:31 +0100 Subject: [PATCH 1/2] standalone/load_path: rename to init --- Library/Homebrew/standalone.rb | 2 +- Library/Homebrew/standalone/{load_path.rb => init.rb} | 0 Library/Homebrew/startup.rb | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) rename Library/Homebrew/standalone/{load_path.rb => init.rb} (100%) diff --git a/Library/Homebrew/standalone.rb b/Library/Homebrew/standalone.rb index 865191d96b..0212c00d8c 100644 --- a/Library/Homebrew/standalone.rb +++ b/Library/Homebrew/standalone.rb @@ -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" diff --git a/Library/Homebrew/standalone/load_path.rb b/Library/Homebrew/standalone/init.rb similarity index 100% rename from Library/Homebrew/standalone/load_path.rb rename to Library/Homebrew/standalone/init.rb diff --git a/Library/Homebrew/startup.rb b/Library/Homebrew/startup.rb index c47ca3749b..1eff1ae226 100644 --- a/Library/Homebrew/startup.rb +++ b/Library/Homebrew/startup.rb @@ -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" From daa49a1323ccbd832e76acac9f22619fe209e52b Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Fri, 29 Sep 2023 01:34:39 +0100 Subject: [PATCH 2/2] Install gems automatically on newer Ruby --- Library/.rubocop.yml | 1 + Library/Homebrew/brew.rb | 8 -------- Library/Homebrew/standalone/init.rb | 21 ++++++++++++++++++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 93e1bf5c9d..6d47f3fad6 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -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" diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 2d7854e35d..c5e5bf5b13 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -15,14 +15,6 @@ end 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 diff --git a/Library/Homebrew/standalone/init.rb b/Library/Homebrew/standalone/init.rb index f567fc734a..0190ad0b3c 100644 --- a/Library/Homebrew/standalone/init.rb +++ b/Library/Homebrew/standalone/init.rb @@ -1,6 +1,22 @@ -# typed: true +# 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" @@ -12,6 +28,9 @@ 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/" \