Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Revert "Split prof gems into their own group"" #15183

Merged
merged 3 commits into from Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/tests.yml
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 --display-cop-names 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
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
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
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
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
Expand Up @@ -45,10 +45,12 @@ def self.typecheck_args
def self.typecheck
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved
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
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
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