Skip to content

Commit

Permalink
Merge pull request #15183 from Bo98/prof-group2
Browse files Browse the repository at this point in the history
Revert "Revert "Split prof gems into their own group""
  • Loading branch information
Bo98 committed Apr 11, 2023
2 parents df14a96 + 376440c commit 448bf1a
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
restore-keys: ${{ runner.os }}-rubygems-

- name: Install Bundler RubyGems
run: brew install-bundler-gems --groups=sorbet
run: brew install-bundler-gems --groups=all

- name: Install shellcheck and shfmt
run: brew install shellcheck shfmt
Expand Down Expand Up @@ -80,7 +80,7 @@ jobs:
restore-keys: ${{ runner.os }}-rubygems-

- name: Install Bundler RubyGems
run: brew install-bundler-gems --groups=sorbet
run: brew install-bundler-gems --groups=all

- name: Run brew style on homebrew-core
run: brew style homebrew/core
Expand Down Expand Up @@ -142,7 +142,7 @@ jobs:
restore-keys: ${{ runner.os }}-rubygems-

- name: Install Bundler RubyGems
run: brew install-bundler-gems --groups=sorbet
run: brew install-bundler-gems --groups=all

- name: Set up the homebrew/core tap
run: brew tap homebrew/core
Expand Down Expand Up @@ -173,7 +173,7 @@ jobs:
restore-keys: ${{ runner.os }}-rubygems-

- name: Install Bundler RubyGems
run: brew install-bundler-gems --groups=sorbet
run: brew install-bundler-gems --groups=all

- name: Set up Homebrew all cask taps
run: |
Expand Down Expand Up @@ -209,7 +209,7 @@ jobs:
# Can't cache this because we need to check that it doesn't fail the
# "uncommitted RubyGems" step with a cold cache.
- name: Install Bundler RubyGems
run: brew install-bundler-gems --groups=sorbet
run: brew install-bundler-gems --groups=all

- name: Check for uncommitted RubyGems
working-directory: ${{ steps.set-up-homebrew.outputs.repository-path }}
Expand Down Expand Up @@ -318,7 +318,7 @@ jobs:
restore-keys: ${{ runner.os }}-rubygems-

- name: Install Bundler RubyGems
run: brew install-bundler-gems --groups=sorbet
run: brew install-bundler-gems --groups=all

- name: Create parallel test log directory
run: mkdir tests
Expand Down
11 changes: 7 additions & 4 deletions Library/Homebrew/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,8 @@ gem "rspec-retry", require: false
gem "rspec-sorbet", require: false
gem "rubocop", require: false
gem "rubocop-ast", require: false
# NOTE: ruby-prof v1.4.3 is the last version that supports Ruby 2.6.x
# TODO: remove explicit version when HOMEBREW_REQUIRED_RUBY_VERSION >= 2.7
gem "ruby-prof", "1.4.3", require: false
gem "simplecov", require: false
gem "simplecov-cobertura", require: false
gem "stackprof", require: false
gem "warning", require: false

group :sorbet, optional: true do
Expand All @@ -42,6 +38,13 @@ group :sorbet, optional: true do
gem "tapioca", require: false
end

group :prof, optional: true do
# NOTE: ruby-prof v1.4.3 is the last version that supports Ruby 2.6.x
# TODO: remove explicit version when HOMEBREW_REQUIRED_RUBY_VERSION >= 2.7
gem "ruby-prof", "1.4.3", require: false
gem "stackprof", require: false
end

# vendored gems
gem "activesupport"
gem "addressable"
Expand Down
9 changes: 7 additions & 2 deletions Library/Homebrew/dev-cmd/install-bundler-gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ def install_bundler_gems_args
def install_bundler_gems
args = install_bundler_gems_args.parse

groups = args.groups

# Clear previous settings. We want to fully replace - not append.
Homebrew::Settings.delete(:gemgroups) if args.groups
Homebrew::Settings.delete(:gemgroups) if groups

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

Homebrew.install_bundler_gems!(groups: args.groups || [])
Homebrew.install_bundler_gems!(groups: groups)
end
end
6 changes: 2 additions & 4 deletions Library/Homebrew/dev-cmd/prof.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def prof_args
def prof
args = prof_args.parse

Homebrew.install_bundler_gems!(groups: ["prof"])

brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path
FileUtils.mkdir_p "prof"
cmd = args.named.first
Expand All @@ -41,16 +43,12 @@ def prof
end

if args.stackprof?
# Already installed from Gemfile but use this to setup PATH and LOADPATH
Homebrew.install_gem_setup_path! "stackprof"
with_env HOMEBREW_STACKPROF: "1" do
system(*HOMEBREW_RUBY_EXEC_ARGS, brew_rb, *args.named)
end
output_filename = "prof/d3-flamegraph.html"
safe_system "stackprof --d3-flamegraph prof/stackprof.dump > #{output_filename}"
else
# Already installed from Gemfile but use this to setup PATH and LOADPATH
Homebrew.install_gem_setup_path! "ruby-prof"
output_filename = "prof/call_stack.html"
safe_system "ruby-prof", "--printer=call_stack", "--file=#{output_filename}", brew_rb, "--", *args.named
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def changed_test_files
def tests
args = tests_args.parse

Homebrew.install_bundler_gems!
Homebrew.install_bundler_gems!(groups: ["prof"])

require "byebug" if args.byebug?

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/dev-cmd/typecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ def self.typecheck_args
def self.typecheck
args = typecheck_args.parse

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

HOMEBREW_LIBRARY_PATH.cd do
if args.update? || args.update_all?
if update
odisabled "brew typecheck --update --fail-if-not-changed" if args.fail_if_not_changed?

excluded_gems = [
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"] = "sorbet"
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
23 changes: 22 additions & 1 deletion Library/Homebrew/utils/gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,24 @@ module Homebrew

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 @@ -134,6 +152,9 @@ 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
raise ArgumentError, "Invalid gem groups: #{invalid_groups.join(", ")}" unless invalid_groups.empty?

install_bundler!

require "settings"
Expand All @@ -142,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 448bf1a

Please sign in to comment.