Merge pull request #20192 from Homebrew/dug-refactor-exec

Refactor exec.rb type fixes
This commit is contained in:
Douglas Eichelberger 2025-06-29 11:59:27 -07:00 committed by GitHub
commit bcab2ae500
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 27 additions and 27 deletions

View File

@ -39,12 +39,12 @@ class PATH
self self
end 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) def select(&block)
self.class.new(@paths.select(&block)) self.class.new(@paths.select(&block))
end 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) def reject(&block)
self.class.new(@paths.reject(&block)) self.class.new(@paths.reject(&block))
end end

View File

@ -32,7 +32,6 @@ module Homebrew
# Store the old environment so we can check if things were already set # Store the old environment so we can check if things were already set
# before we start mutating it. # before we start mutating it.
old_env = ENV.to_h old_env = ENV.to_h
new_env = T.cast(ENV, Superenv)
# Setup Homebrew's ENV extensions # Setup Homebrew's ENV extensions
ENV.activate_extensions! ENV.activate_extensions!
@ -46,7 +45,7 @@ module Homebrew
require "formula" require "formula"
require "formulary" require "formulary"
new_env.deps = @dsl.entries.filter_map do |entry| ENV.deps = @dsl.entries.filter_map do |entry|
next if entry.type != :brew next if entry.type != :brew
Formulary.factory(entry.name) Formulary.factory(entry.name)
@ -54,20 +53,20 @@ module Homebrew
# Allow setting all dependencies to be keg-only # Allow setting all dependencies to be keg-only
# (i.e. should be explicitly in HOMEBREW_*PATHs ahead of HOMEBREW_PREFIX) # (i.e. should be explicitly in HOMEBREW_*PATHs ahead of HOMEBREW_PREFIX)
new_env.keg_only_deps = if ENV["HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS"].present? ENV.keg_only_deps = if ENV["HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS"].present?
ENV.delete("HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS") ENV.delete("HOMEBREW_BUNDLE_EXEC_ALL_KEG_ONLY_DEPS")
new_env.deps ENV.deps
else else
new_env.deps.select(&:keg_only?) ENV.deps.select(&:keg_only?)
end end
new_env.setup_build_environment ENV.setup_build_environment
# Enable compiler flag filtering # Enable compiler flag filtering
ENV.refurbish_args ENV.refurbish_args
# Set up `nodenv`, `pyenv` and `rbenv` if present. # Set up `nodenv`, `pyenv` and `rbenv` if present.
env_formulae = %w[nodenv pyenv rbenv] env_formulae = %w[nodenv pyenv rbenv]
new_env.deps.each do |dep| ENV.deps.each do |dep|
dep_name = dep.name dep_name = dep.name
next unless env_formulae.include?(dep_name) next unless env_formulae.include?(dep_name)
@ -85,7 +84,7 @@ module Homebrew
end end
# Replace the formula versions from the environment variables # Replace the formula versions from the environment variables
new_env.deps.each do |formula| ENV.deps.each do |formula|
formula_name = formula.name formula_name = formula.name
formula_version = Bundle.formula_versions_from_env(formula_name) formula_version = Bundle.formula_versions_from_env(formula_name)
next unless formula_version next unless formula_version
@ -101,12 +100,7 @@ module Homebrew
rejected_opts = [] rejected_opts = []
path = PATH.new(ENV.fetch("PATH")) path = PATH.new(ENV.fetch("PATH"))
.reject do |path_value| .reject do |path_value|
if path_value.match?(opt) rejected_opts << path_value if path_value.match?(opt)
rejected_opts << path_value
true
else
false
end
end end
rejected_opts.each do |path_value| rejected_opts.each do |path_value|
path.prepend(path_value.gsub(opt, cellar)) path.prepend(path_value.gsub(opt, cellar))
@ -217,7 +211,7 @@ module Homebrew
entry: Homebrew::Bundle::Dsl::Entry, entry: Homebrew::Bundle::Dsl::Entry,
info: T::Hash[String, T.untyped], info: T::Hash[String, T.untyped],
service_file: Pathname, service_file: Pathname,
conflicting_services: T::Array[T::Hash[String, T.untyped]], conflicting_services: T::Array[T::Hash[String, T.anything]],
).void, ).void,
).void ).void
} }

View File

@ -31,7 +31,7 @@ module Homebrew
sig { override.void } sig { override.void }
def run def run
ENV.activate_extensions! 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 ENV.setup_build_environment
shell = if args.plain? shell = if args.plain?

View File

@ -13,8 +13,8 @@ class Dependencies < SimpleDelegator
sig { returns(T::Enumerator[Dependency]) } sig { returns(T::Enumerator[Dependency]) }
def each(&blk); end def each(&blk); end
sig { params(blk: T.proc.params(arg0: Dependency).returns(T::Boolean)).returns(T::Array[Dependency]) } sig { override.params(blk: T.proc.params(arg0: Dependency).returns(T.anything)).returns(T::Array[Dependency]) }
sig { returns(T::Enumerator[Dependency]) } sig { override.returns(T::Enumerator[Dependency]) }
def select(&blk); end def select(&blk); end
end end
@ -26,7 +26,7 @@ class Requirements < SimpleDelegator
sig { returns(T::Enumerator[Requirement]) } sig { returns(T::Enumerator[Requirement]) }
def each(&blk); end def each(&blk); end
sig { params(blk: T.proc.params(arg0: Requirement).returns(T::Boolean)).returns(T::Array[Requirement]) } sig { override.params(blk: T.proc.params(arg0: Requirement).returns(T.anything)).returns(T::Array[Requirement]) }
sig { returns(T::Enumerator[Requirement]) } sig { override.returns(T::Enumerator[Requirement]) }
def select(&blk); end def select(&blk); end
end end

View File

@ -16,10 +16,10 @@ module Homebrew
in an Xcode-only configuration since it adds tools like `make` to your `$PATH` in an Xcode-only configuration since it adds tools like `make` to your `$PATH`
which build systems would not find otherwise. which build systems would not find otherwise.
EOS EOS
flag "--env=", flag "--env=",
description: "Use the standard `$PATH` instead of superenv's when `std` is passed." description: "Use the standard `$PATH` instead of superenv's when `std` is passed."
flag "-c=", "--cmd=", flag "-c=", "--cmd=",
description: "Execute commands in a non-interactive shell." description: "Execute commands in a non-interactive shell."
named_args :file, max: 1 named_args :file, max: 1
end end
@ -29,7 +29,9 @@ module Homebrew
ENV.activate_extensions!(env: args.env) ENV.activate_extensions!(env: args.env)
if superenv?(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 end
ENV.setup_build_environment ENV.setup_build_environment
if superenv?(args.env) if superenv?(args.env)

View File

@ -10,6 +10,10 @@ class Sorbet
module Static module Static
class ENVClass class ENVClass
include EnvActivation 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 end
end end