Skip to content

Commit

Permalink
Dynamically find gem groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Bo98 committed Apr 10, 2023
1 parent b94aede commit 376440c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/install-bundler-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def install_bundler_gems
Homebrew::Settings.delete(:gemgroups) if groups

groups ||= []
groups |= VALID_GEM_GROUPS if groups.delete("all")
groups |= Homebrew.valid_gem_groups if groups.delete("all")

Homebrew.install_bundler_gems!(groups: groups)
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/typecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def self.typecheck
args = typecheck_args.parse

update = args.update? || args.update_all?
groups = update ? VALID_GEM_GROUPS : ["sorbet"]
groups = update ? Homebrew.valid_gem_groups : ["sorbet"]
Homebrew.install_bundler_gems!(groups: groups)

HOMEBREW_LIBRARY_PATH.cd do
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/vendor-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def vendor_gems

Homebrew.install_bundler!

ENV["BUNDLE_WITH"] = VALID_GEM_GROUPS.join(":")
ENV["BUNDLE_WITH"] = Homebrew.valid_gem_groups.join(":")

# System Ruby does not pick up the correct SDK by default.
ENV["SDKROOT"] = MacOS.sdk_path if ENV["HOMEBREW_MACOS_SYSTEM_RUBY_NEW_ENOUGH"]
Expand Down
24 changes: 20 additions & 4 deletions Library/Homebrew/utils/gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ module Homebrew
# After updating this, run `brew vendor-gems --update=--bundler`.
HOMEBREW_BUNDLER_VERSION = "2.3.26"

VALID_GEM_GROUPS = ["sorbet", "prof"].freeze

module_function

# @api private
def gemfile
File.join(ENV.fetch("HOMEBREW_LIBRARY"), "Homebrew", "Gemfile")
end

# @api private
def valid_gem_groups
install_bundler!
require "bundler"

Bundler.with_unbundled_env do
ENV["BUNDLE_GEMFILE"] = gemfile
groups = Bundler::Definition.build(Bundler.default_gemfile, Bundler.default_lockfile, false).groups
groups.delete(:default)
groups.map(&:to_s)
end
end

def ruby_bindir
"#{RbConfig::CONFIG["prefix"]}/bin"
end
Expand Down Expand Up @@ -136,7 +152,7 @@ def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups:
old_bundle_frozen = ENV.fetch("BUNDLE_FROZEN", nil)
old_sdkroot = ENV.fetch("SDKROOT", nil)

invalid_groups = groups - VALID_GEM_GROUPS
invalid_groups = groups - valid_gem_groups
raise ArgumentError, "Invalid gem groups: #{invalid_groups.join(", ")}" unless invalid_groups.empty?

install_bundler!
Expand All @@ -147,7 +163,7 @@ def install_bundler_gems!(only_warn_on_failure: false, setup_path: true, groups:
groups |= (Homebrew::Settings.read(:gemgroups)&.split(";") || [])
groups.sort!

ENV["BUNDLE_GEMFILE"] = File.join(ENV.fetch("HOMEBREW_LIBRARY"), "Homebrew", "Gemfile")
ENV["BUNDLE_GEMFILE"] = gemfile
ENV["BUNDLE_WITH"] = groups.join(" ")
ENV["BUNDLE_FROZEN"] = "true"

Expand Down

0 comments on commit 376440c

Please sign in to comment.