Skip to content

Commit

Permalink
Merge pull request #18057 from Homebrew/rdbg-followup
Browse files Browse the repository at this point in the history
  • Loading branch information
Rylan12 authored Aug 15, 2024
2 parents fbbdc1e + 842b4ac commit f3a6aef
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 6 deletions.
13 changes: 11 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,18 @@
"configurations": [
{
"type": "rdbg",
"name": "Attach with rdbg",
"name": "Debug Homebrew command",
"request": "launch",
"rdbgPath": "${workspaceFolder}/Library/Homebrew/shims/gems/rdbg",
"command": "brew debugger --",
"script": "${fileBasenameNoExtension}",
"askParameters": true
},
{
"type": "rdbg",
"name": "Attach to Homebrew debugger",
"request": "attach",
"rdbgPath": "${workspaceFolder}/Library/Homebrew/vendor/portable-ruby/current/lib/ruby/gems/3.3.0/gems/debug-1.9.1/exe/rdbg",
"rdbgPath": "${workspaceFolder}/Library/Homebrew/shims/gems/rdbg",
"env": {
"TMPDIR": "/private/tmp/",
}
Expand Down
9 changes: 5 additions & 4 deletions Library/Homebrew/dev-cmd/debugger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class Debugger < AbstractCommand
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."

Expand All @@ -28,14 +26,17 @@ def run
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
env = {}
env[:RUBY_DEBUG_FORK_MODE] = "parent"
env[:RUBY_DEBUG_NONSTOP] = "1" unless ENV["HOMEBREW_RDBG"]

with_env(**env) do
system(*HOMEBREW_RUBY_EXEC_ARGS,
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
"-rdebug/#{debugger_method}",
Expand Down
6 changes: 6 additions & 0 deletions Library/Homebrew/shims/gems/rdbg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

export HOMEBREW_RDBG="1"

HOMEBREW_PORTABLE_RUBY_BIN="$(cd "$(dirname "$0")"/../../ && pwd)/vendor/portable-ruby/current/bin/"
exec "${HOMEBREW_PORTABLE_RUBY_BIN}"rdbg "$@"
12 changes: 12 additions & 0 deletions bin/brew
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,18 @@ then
FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi

if [[ -n "${HOMEBREW_RDBG:-}" ]]
then
for VAR in "${!RUBY_DEBUG_@}"
do
# Skip if variable value is empty.
[[ -z "${!VAR:-}" ]] && continue

FILTERED_ENV+=("${VAR}=${!VAR}")
done
fi

unset VAR ENV_VAR_NAMES

exec /usr/bin/env -i "${FILTERED_ENV[@]}" /bin/bash -p "${HOMEBREW_LIBRARY}/Homebrew/brew.sh" "$@"

0 comments on commit f3a6aef

Please sign in to comment.