Merge pull request #15183 from Bo98/prof-group2

Revert "Revert "Split prof gems into their own group""
This commit is contained in:
Bo Anderson 2023-04-11 15:11:57 +01:00 committed by GitHub
commit 448bf1a49c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 51 additions and 22 deletions

View File

@ -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
@ -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
@ -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
@ -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: |
@ -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 }}
@ -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

View File

@ -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
@ -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"

View File

@ -24,9 +24,14 @@ module Homebrew
def install_bundler_gems
args = install_bundler_gems_args.parse
# Clear previous settings. We want to fully replace - not append.
Homebrew::Settings.delete(:gemgroups) if args.groups
groups = args.groups
Homebrew.install_bundler_gems!(groups: args.groups || [])
# Clear previous settings. We want to fully replace - not append.
Homebrew::Settings.delete(:gemgroups) if groups
groups ||= []
groups |= Homebrew.valid_gem_groups if groups.delete("all")
Homebrew.install_bundler_gems!(groups: groups)
end
end

View File

@ -24,6 +24,8 @@ module Homebrew
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
@ -41,16 +43,12 @@ module Homebrew
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

View File

@ -88,7 +88,7 @@ module Homebrew
def tests
args = tests_args.parse
Homebrew.install_bundler_gems!
Homebrew.install_bundler_gems!(groups: ["prof"])
require "byebug" if args.byebug?

View File

@ -45,10 +45,12 @@ module Homebrew
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 = [

View File

@ -30,7 +30,7 @@ module Homebrew
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"]

View File

@ -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
@ -134,6 +152,9 @@ module Homebrew
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"
@ -142,7 +163,7 @@ module Homebrew
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"