mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Merge pull request #20192 from Homebrew/dug-refactor-exec
Refactor exec.rb type fixes
This commit is contained in:
commit
bcab2ae500
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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?
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user