Refactor exec.rb type fixes

This commit is contained in:
Douglas Eichelberger 2025-06-29 08:05:23 -07:00
parent 5fed8f4210
commit 004c0a2a6c
No known key found for this signature in database
GPG Key ID: F90193CBD547EB81
5 changed files with 23 additions and 23 deletions

View File

@ -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

View File

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

View File

@ -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?

View File

@ -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)

View File

@ -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