Merge pull request #18050 from Homebrew/rdbg

This commit is contained in:
Rylan Polster 2024-08-15 10:28:54 -04:00 committed by GitHub
commit dd8334bf83
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 95 additions and 0 deletions

14
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,14 @@
{
"version": "0.2.0",
"configurations": [
{
"type": "rdbg",
"name": "Attach with rdbg",
"request": "attach",
"rdbgPath": "${workspaceFolder}/Library/Homebrew/vendor/portable-ruby/current/lib/ruby/gems/3.3.0/gems/debug-1.9.1/exe/rdbg",
"env": {
"TMPDIR": "/private/tmp/",
}
}
]
}

View File

@ -2,6 +2,7 @@
# frozen_string_literal: true # frozen_string_literal: true
require "cli/parser" require "cli/parser"
require "shell_command"
module Homebrew module Homebrew
# Subclass this to implement a `brew` command. This is preferred to declaring a named function in the `Homebrew` # Subclass this to implement a `brew` command. This is preferred to declaring a named function in the `Homebrew`
@ -41,6 +42,9 @@ module Homebrew
sig { returns(T::Boolean) } sig { returns(T::Boolean) }
def dev_cmd? = T.must(name).start_with?("Homebrew::DevCmd") def dev_cmd? = T.must(name).start_with?("Homebrew::DevCmd")
sig { returns(T::Boolean) }
def ruby_cmd? = !include?(Homebrew::ShellCommand)
sig { returns(CLI::Parser) } sig { returns(CLI::Parser) }
def parser = CLI::Parser.new(self, &@parser_block) def parser = CLI::Parser.new(self, &@parser_block)

View File

@ -41,6 +41,11 @@ module Commands
require?(HOMEBREW_DEV_CMD_PATH/cmd) require?(HOMEBREW_DEV_CMD_PATH/cmd)
end end
def self.valid_ruby_cmd?(cmd)
(valid_internal_cmd?(cmd) || valid_internal_dev_cmd?(cmd) || external_ruby_v2_cmd_path(cmd)) &&
Homebrew::AbstractCommand.command(cmd)&.ruby_cmd?
end
def self.method_name(cmd) def self.method_name(cmd)
cmd.to_s cmd.to_s
.tr("-", "_") .tr("-", "_")

View File

@ -0,0 +1,47 @@
# typed: strict
# frozen_string_literal: true
module Homebrew
module DevCmd
class Debugger < AbstractCommand
cmd_args do
description <<~EOS
Run the specified Homebrew command in debug mode.
To pass flags to the command, use `--` to separate them from the `brew` flags.
For example: `brew debugger -- list --formula`.
EOS
switch "-s", "--stop",
description: "Stop at the beginning of the script."
switch "-O", "--open",
description: "Start remote debugging over a Unix socket."
named_args :command, min: 1
end
sig { override.void }
def run
raise UsageError, "Debugger is only supported with portable Ruby!" unless HOMEBREW_USING_PORTABLE_RUBY
unless Commands.valid_ruby_cmd?(args.named.first)
raise UsageError, "`#{args.named.first}` is not a valid Ruby command!"
end
brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path
nonstop = "1" unless args.stop?
debugger_method = if args.open?
"open"
else
"start"
end
with_env RUBY_DEBUG_NONSTOP: nonstop, RUBY_DEBUG_FORK_MODE: "parent" do
system(*HOMEBREW_RUBY_EXEC_ARGS,
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
"-rdebug/#{debugger_method}",
brew_rb, *args.named)
end
end
end
end
end

View File

@ -0,0 +1,25 @@
# typed: true
# DO NOT EDIT MANUALLY
# This is an autogenerated file for dynamic methods in `Homebrew::DevCmd::Debugger`.
# Please instead update this file by running `bin/tapioca dsl Homebrew::DevCmd::Debugger`.
class Homebrew::DevCmd::Debugger
sig { returns(Homebrew::DevCmd::Debugger::Args) }
def args; end
end
class Homebrew::DevCmd::Debugger::Args < Homebrew::CLI::Args
sig { returns(T::Boolean) }
def O?; end
sig { returns(T::Boolean) }
def open?; end
sig { returns(T::Boolean) }
def s?; end
sig { returns(T::Boolean) }
def stop?; end
end