Homebrew / homebrew-bundle

📦 Bundler for non-Ruby dependencies from Homebrew, Homebrew Cask and the Mac App Store.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Maintaining Ruby 2.6 compatibility

anujmore-grabtaxi opened this issue · comments

Hi, I am trying to install from a brew bundle and it gives me the following error:

==> Tapping homebrew/bundle
Cloning into '/opt/homebrew/Library/Taps/homebrew/homebrew-bundle'...
remote: Enumerating objects: 7673, done.
remote: Counting objects: 100% (7673/7673), done.
remote: Compressing objects: 100% (3050/3050), done.
remote: Total 7673 (delta 4533), reused 7503 (delta 4458), pack-reused 0
Receiving objects: 100% (7673/7673), 1.79 MiB | 2.31 MiB/s, done.
Resolving deltas: 100% (4533/4533), done.
Tapped 1 command (108 files, 2.2MB).
Tapping <REDACTED>
Error: undefined method `filter_map' for []:Array
Did you mean?  filter
Please report this bug:
  https://github.com/Homebrew/homebrew-bundle/issues
/opt/homebrew/Library/Taps/homebrew/homebrew-bundle/lib/bundle/brew_installer.rb:175:in `outdated_formulae'
:

This happens because the function has been added in 2.7 but Apple says that it won't update the Ruby version any more

I made the following change (check patchset) and it works for me, but I was wondering if there's a change I can do for picking up the Ruby version on my shell:

❯ ruby --version
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [arm64-darwin22]
❯ which -a ruby
/opt/homebrew/bin/ruby
/usr/bin/ruby

custom.patch

Patch in text (just replacing each filter_map {...} with map {...}.compact:

diff --git a/lib/bundle/brew_dumper.rb b/lib/bundle/brew_dumper.rb
index 45b95c7..4803f92 100644
--- a/lib/bundle/brew_dumper.rb
+++ b/lib/bundle/brew_dumper.rb
@@ -143,8 +143,7 @@ module Bundle
         installed_as_dependency = tab.installed_as_dependency
         installed_on_request = tab.installed_on_request
         runtime_dependencies = if (runtime_deps = tab.runtime_dependencies)
-          runtime_deps.filter_map { |d| d["full_name"] }
-
+          runtime_deps.map { |d| d["full_name"] }.compact
         end
         poured_from_bottle = tab.poured_from_bottle
       end
@@ -205,13 +204,13 @@ module Bundle
       # Step 2: Sort by formula dependency topology.
       topo = Topo.new
       formulae.each do |f|
-        topo[f[:name]] = topo[f[:full_name]] = f[:dependencies].filter_map do |dep|
+        topo[f[:name]] = topo[f[:full_name]] = f[:dependencies].map do |dep|
           ff = formulae_by_name(dep)
           next if ff.blank?
           next unless ff[:any_version_installed?]

           ff[:full_name]
-        end
+        end.compact
       end
       @formulae = topo.tsort
                       .map { |name| @formulae_by_full_name[name] || @formulae_by_name[name] }
diff --git a/lib/bundle/brew_installer.rb b/lib/bundle/brew_installer.rb
index 2b4d12d..b8b72f0 100644
--- a/lib/bundle/brew_installer.rb
+++ b/lib/bundle/brew_installer.rb
@@ -1,4 +1,4 @@
-# frozen_string_literal: true
+# frozen_string_literal: true.compact

 module Bundle
   class BrewInstaller
@@ -172,19 +172,19 @@ module Bundle
     end

     def self.outdated_formulae
-      @outdated_formulae ||= formulae.filter_map { |f| f[:name] if f[:outdated?] }
+      @outdated_formulae ||= formulae.map { |f| f[:name] if f[:outdated?] }.compact
     end

     def self.pinned_formulae
-      @pinned_formulae ||= formulae.filter_map { |f| f[:name] if f[:pinned?] }
+      @pinned_formulae ||= formulae.map { |f| f[:name] if f[:pinned?] }.compact
     end

     def self.linked_and_keg_only_formulae
-      @linked_and_keg_only_formulae ||= formulae.filter_map { |f| f[:name] if f[:link?] == true }
+      @linked_and_keg_only_formulae ||= formulae.map { |f| f[:name] if f[:link?] == true }.compact
     end

     def self.unlinked_and_not_keg_only_formulae
-      @unlinked_and_not_keg_only_formulae ||= formulae.filter_map { |f| f[:name] if f[:link?] == false }
+      @unlinked_and_not_keg_only_formulae ||= formulae.map { |f| f[:name] if f[:link?] == false }.compact
     end

     def self.formulae
diff --git a/lib/bundle/brew_services.rb b/lib/bundle/brew_services.rb
index c5fad23..47cd14b 100644
--- a/lib/bundle/brew_services.rb
+++ b/lib/bundle/brew_services.rb
@@ -38,12 +38,12 @@ module Bundle
     def started_services
       @started_services ||= if Bundle.services_installed?
         states_to_skip = %w[stopped none]
-        Utils.safe_popen_read(HOMEBREW_BREW_FILE, "services", "list").lines.filter_map do |line|
+        Utils.safe_popen_read(HOMEBREW_BREW_FILE, "services", "list").lines.map do |line|
           name, state, _plist = line.split(/\s+/)
           next if states_to_skip.include? state

           name
-        end
+        end.compact
       else
         []
       end
diff --git a/lib/bundle/cask_installer.rb b/lib/bundle/cask_installer.rb
index 345ea3e..2e194a1 100644
--- a/lib/bundle/cask_installer.rb
+++ b/lib/bundle/cask_installer.rb
@@ -37,7 +37,7 @@ module Bundle
         return Bundle.system HOMEBREW_BREW_FILE, "upgrade", "--cask", full_name, verbose: verbose
       end

-      args = options.fetch(:args, []).filter_map do |k, v|
+      args = options.fetch(:args, []).map do |k, v|
         case v
         when TrueClass
           "--#{k}"
@@ -46,7 +46,7 @@ module Bundle
         else
           "--#{k}=#{v}"
         end
-      end
+      end.compact

       args << "--force" if force
       args.uniq!

given that this is for Catalina which only makes up 0.68% of total usage over the last 30d, i'm hesitant to leave this old Ruby laying around for the sake of old Mac installs. the newer Ruby approach is much cleaner and concise as to the purpose of it and i feel this patch takes away some of that.

is there a reason you cannot upgrade? as it stands, you may need to fork homebrew-bundle to continue running your patch.

No, the freeze started with Catalina, but even the latest macOS comes with the same version:

I get this on 13.6.4 (Ventura) and Sonoma too:

❯ /usr/bin/ruby --version
ruby 2.6.10p210 (2022-04-12 revision 67958) [universal.arm64e-darwin23]

Another thing that confuses me is that I already have 3.3 installed and in my $PATH. It just doesn't seem to get picked up.

You shouldn't need old Ruby even on Catalina. We supply Homebrew's portable Ruby for this. You need to brew update and, if homebrew-bundle is still broken, supply your brew config and brew doctor output here.