Skip to content

Commit

Permalink
dev-cmd/typecheck: Tell the user how to configure Sorbet for taps
Browse files Browse the repository at this point in the history
- The previous try of setting `--dir` to the tap path produced nonsense
  (as far as I could tell).
- So I added a `sorbet` directory to `homebrew/services` locally,
  with a copy of the main config file, and went back to the `tap_path.cd`
  approach.
- This is a bit better, as in more like I'd expect, but something in
  Sorbet's knowledge of the world still doesn't find the "core" classes
  like `Formula`, `Plist` in the case of
  `brew typecheck homebrew/services`.

```
lib/service/services_cli.rb:107: Unable to resolve constant Keg https://srb.help/5002
     107 |        elsif service.formula.opt_prefix.exist? && (keg = Keg.for service.formula.opt_prefix) && keg.plist_installed?
                                                                    ^^^

lib/service/services_cli.rb:216: Unable to resolve constant Plist https://srb.help/5002
     216 |          Plist.parse_xml(plist_data, marshal: false)
                    ^^^^^
```
  • Loading branch information
issyl0 committed Aug 13, 2024
1 parent 399abae commit e46980d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions Library/Homebrew/dev-cmd/typecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ class Typecheck < AbstractCommand

sig { override.void }
def run
raise UsageError, "Cannot use --dir when specifying a tap." if args.named.present? && args.dir.present?

update = args.update? || args.update_all?
tap_path = args.no_named? ? HOMEBREW_LIBRARY_PATH : args.named.to_paths(only: :tap).first
unless (tap_path/"sorbet").exist?
raise UsageError, "Sorbet typechecking is not supported for the #{args.named.first} tap. " \
"Add a `sorbet/` directory with a config file to the tap to enable it."
end

groups = update ? Homebrew.valid_gem_groups : ["typecheck"]
Homebrew.install_bundler_gems!(groups:)

# Sorbet doesn't use bash privileged mode so we align EUID and UID here.
Process::UID.change_privilege(Process.euid) if Process.euid != Process.uid

HOMEBREW_LIBRARY_PATH.cd do
tap_path.cd do

Check warning on line 60 in Library/Homebrew/dev-cmd/typecheck.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/dev-cmd/typecheck.rb#L60

Added line #L60 was not covered by tests
if update
workers = args.debug? ? ["--workers=1"] : []
safe_system "bundle", "exec", "tapioca", "dsl", *workers
Expand Down Expand Up @@ -97,11 +101,10 @@ def run
end

srb_exec += ["--ignore", args.ignore] if args.ignore.present?
if args.file.present? || args.dir.present? || (tap_dir = args.named.to_paths(only: :tap).first).present?
if args.file.present? || args.dir.present?
cd("sorbet") do
srb_exec += ["--file", "../#{args.file}"] if args.file
srb_exec += ["--dir", "../#{args.dir}"] if args.dir
srb_exec += ["--dir", tap_dir.to_s] if tap_dir
end
end
success = system(*srb_exec)
Expand Down

0 comments on commit e46980d

Please sign in to comment.