diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index 46fd38bb3f..099613ac95 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -39,12 +39,12 @@ class PATH self end - sig { params(block: T.proc.params(arg0: String).returns(T::Boolean)).returns(T.self_type) } + sig { params(block: T.proc.params(arg0: String).returns(BasicObject)).returns(T.self_type) } def select(&block) self.class.new(@paths.select(&block)) end - sig { params(block: T.proc.params(arg0: String).returns(T::Boolean)).returns(T.self_type) } + sig { params(block: T.proc.params(arg0: String).returns(BasicObject)).returns(T.self_type) } def reject(&block) self.class.new(@paths.reject(&block)) end diff --git a/Library/Homebrew/bundle/commands/exec.rb b/Library/Homebrew/bundle/commands/exec.rb index 588de100e2..b6c698ff28 100644 --- a/Library/Homebrew/bundle/commands/exec.rb +++ b/Library/Homebrew/bundle/commands/exec.rb @@ -1,4 +1,4 @@ -# typed: false # rubocop:todo Sorbet/TrueSigil +# typed: true # frozen_string_literal: true require "English" @@ -13,6 +13,16 @@ module Homebrew module Exec PATH_LIKE_ENV_REGEX = /.+#{File::PATH_SEPARATOR}/ + sig { + params( + args: String, + global: T::Boolean, + file: T.nilable(String), + subcommand: String, + services: T::Boolean, + check: T::Boolean, + ).void + } def self.run(*args, global: false, file: nil, subcommand: "", services: false, check: false) if check require "bundle/commands/check" @@ -25,9 +35,9 @@ module Homebrew # Setup Homebrew's ENV extensions ENV.activate_extensions! - raise UsageError, "No command to execute was specified!" if args.blank? command = args.first + raise UsageError, "No command to execute was specified!" if command.blank? require "bundle/brewfile" @dsl = Brewfile.read(global:, file:) @@ -181,7 +191,7 @@ module Homebrew if services require "bundle/brew_services" - exit_code = 0 + exit_code = T.let(0, Integer) run_services(@dsl.entries) do Kernel.system(*args) if (system_exit_code = $CHILD_STATUS&.exitstatus) @@ -199,7 +209,7 @@ module Homebrew entries: T::Array[Homebrew::Bundle::Dsl::Entry], _block: T.proc.params( entry: Homebrew::Bundle::Dsl::Entry, - info: T::Hash[String, T.anything], + info: T::Hash[String, T.untyped], service_file: Pathname, conflicting_services: T::Array[T::Hash[String, T.anything]], ).void, @@ -279,7 +289,7 @@ module Homebrew map_service_info(entries) do |entry, info, service_file, conflicting_services| # Don't restart if already running this version loaded_file = Pathname.new(info["loaded_file"].to_s) - next if info["running"] && loaded_file&.file? && loaded_file&.realpath == service_file.realpath + next if info["running"] && loaded_file.file? && loaded_file.realpath == service_file.realpath if info["running"] && !Bundle::BrewServices.stop(info["name"], keep: true) opoo "Failed to stop #{info["name"]} service" diff --git a/Library/Homebrew/cmd/--env.rb b/Library/Homebrew/cmd/--env.rb index e0a2a50307..90f505942d 100644 --- a/Library/Homebrew/cmd/--env.rb +++ b/Library/Homebrew/cmd/--env.rb @@ -31,7 +31,7 @@ module Homebrew sig { override.void } def run ENV.activate_extensions! - T.cast(ENV, Superenv).deps = args.named.to_formulae if superenv?(nil) + ENV.deps = args.named.to_formulae if superenv?(nil) ENV.setup_build_environment shell = if args.plain? diff --git a/Library/Homebrew/dependencies.rbi b/Library/Homebrew/dependencies.rbi index 29a8508c06..5cdc3fcad4 100644 --- a/Library/Homebrew/dependencies.rbi +++ b/Library/Homebrew/dependencies.rbi @@ -13,8 +13,8 @@ class Dependencies < SimpleDelegator sig { returns(T::Enumerator[Dependency]) } def each(&blk); end - sig { params(blk: T.proc.params(arg0: Dependency).returns(T::Boolean)).returns(T::Array[Dependency]) } - sig { returns(T::Enumerator[Dependency]) } + sig { override.params(blk: T.proc.params(arg0: Dependency).returns(T.anything)).returns(T::Array[Dependency]) } + sig { override.returns(T::Enumerator[Dependency]) } def select(&blk); end end @@ -26,7 +26,7 @@ class Requirements < SimpleDelegator sig { returns(T::Enumerator[Requirement]) } def each(&blk); end - sig { params(blk: T.proc.params(arg0: Requirement).returns(T::Boolean)).returns(T::Array[Requirement]) } - sig { returns(T::Enumerator[Requirement]) } + sig { override.params(blk: T.proc.params(arg0: Requirement).returns(T.anything)).returns(T::Array[Requirement]) } + sig { override.returns(T::Enumerator[Requirement]) } def select(&blk); end end diff --git a/Library/Homebrew/dev-cmd/sh.rb b/Library/Homebrew/dev-cmd/sh.rb index 2ba18a56e9..df034059fe 100644 --- a/Library/Homebrew/dev-cmd/sh.rb +++ b/Library/Homebrew/dev-cmd/sh.rb @@ -16,10 +16,10 @@ module Homebrew in an Xcode-only configuration since it adds tools like `make` to your `$PATH` which build systems would not find otherwise. EOS - flag "--env=", - description: "Use the standard `$PATH` instead of superenv's when `std` is passed." - flag "-c=", "--cmd=", - description: "Execute commands in a non-interactive shell." + flag "--env=", + description: "Use the standard `$PATH` instead of superenv's when `std` is passed." + flag "-c=", "--cmd=", + description: "Execute commands in a non-interactive shell." named_args :file, max: 1 end @@ -29,7 +29,9 @@ module Homebrew ENV.activate_extensions!(env: args.env) if superenv?(args.env) - T.cast(ENV, Superenv).deps = Formula.installed.select { |f| f.keg_only? && f.opt_prefix.directory? } + ENV.deps = Formula.installed.select do |f| + f.keg_only? && f.opt_prefix.directory? + end end ENV.setup_build_environment if superenv?(args.env) diff --git a/Library/Homebrew/extend/ENV.rbi b/Library/Homebrew/extend/ENV.rbi index 24711f725f..b7727c58c9 100644 --- a/Library/Homebrew/extend/ENV.rbi +++ b/Library/Homebrew/extend/ENV.rbi @@ -10,6 +10,10 @@ class Sorbet module Static class ENVClass include EnvActivation + # NOTE: This is a bit misleading, as at most only one of these can be true + # See: EnvActivation#activate_extensions! + include Stdenv + include Superenv end end end